Monday, 4 December 2023

Call external API in D365 FO X++

 using System.IO;

using System.Net;

using System.Text;

using Microsoft.WindowsAzure.Storage;

using Microsoft.WindowsAzure.Storage.File;

using Microsoft.IdentityModel.Clients.ActiveDirectory;

using System.Threading.Tasks;

class DXAPIServiceClass extends SysOperationServiceBase

{

    public void processOperation()

    {

        WebException                exception;

        HttpWebRequest              webRequest;

        WebResponse                 webResponse;

        CLRObject                   clrObj;

        System.Exception            ex;

        System.Byte[]               bytes;

        System.Text.Encoding        encoding;

        #OCCRetryCount

       

        webRequest                  = System.Net.WebRequest::Create('3rd party(external) URL');

        webRequest.Method           = 'Get';

        webRequest.KeepAlive        = true;

        webRequest.ContentType      = 'application/x-www-form-urlencoded';

        webRequest.Timeout          = maxInt();


        System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();

        //str auth = this.geLokcal();

        Headers = webRequest.Headers;

        headers.Add('Authorization', 'Bearer ' + "GubjUjpC5tgmZ8Q85sXYIj");


        if (webRequest != null)

        {

            webResponse = webRequest.GetResponse();


            using (StreamReader streamReader = new StreamReader(webResponse.GetResponseStream()))

            {

                str response = streamReader.readToEnd();

            }


            webResponse.Close();


        }

        else

        {

            throw new System.Exception("Please provide valid URL");

        }

    }

}

No comments:

Post a Comment

workflow business event configuration with power automate flow in d365 FO

  https://www.linkedin.com/pulse/purchase-order-approvals-d365fo-power-automate-ahmed-ali-el-bardisy-jyssf/