Tuesday, February 21, 2023

How to Call External API Service from CRM Plugins/Custom Workflows.

 public string CallRESTAPIService(string restAPIURL, string serviceCredentials)

       {
           string jsonResponse = string.Empty;
           var uri = new Uri(restAPIURL);
           var request = WebRequest.Create(uri);
           request.Method = WebRequestMethods.Http.Get;
           request.ContentType = "application/json";
           request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(serviceCredentials));
           try
           {
               using (var response = request.GetResponse())
               {
                   using (var reader = new StreamReader(response.GetResponseStream()))
                   {
                       jsonResponse = reader.ReadToEnd();
                   }
               }
           }
           catch (System.Exception ex)
           {
               throw ex;
           }
           return jsonResponse;
       }

No comments:

Post a Comment

How to Deploy your API as a web app or API app

  Before you can call your custom API from a logic app workflow, deploy your API as a web app or API app to Azure App Service. To make your ...