Rest API GET call in JSON format in Dynamics 365 Finance and Operations | CloudFronts

Rest API GET call in JSON format in Dynamics 365 Finance and Operations

In this blog, we will see how to get response from Rest Api through GET call

Consisting of basic authentication, we will pass username and password in byteStr and for the endpoint we will put it in url in below code.
class CFSJSTestRestAPI
    public static void main(Args _args)
        int                                find;
        str                                url,aosUri,activeDirectoryTenant;
        str                                activeDirectoryClientAppId;
        str                                activeDirectoryClientAppSecret;
        str                                postData,activeDirectoryResource;
        str                                aadClientAppSecret,oAuthHeader;
        str                                returnValue,jsonString,jsondszstr;
        System.Net.HttpWebRequest          request;
        System.Net.HttpWebResponse         response;
        System.Byte[]                      byteArray;
        System.IO.Stream                   dataStream;
        System.IO.StreamReader             streamRead;
        System.IO.StreamWriter             streamWrite;
        System.Net.ServicePoint            servicePoint;
        System.Net.ServicePointManager     servicePointmgr;
        System.Net.HttpVersion             version;
        CLRObject                          clrObj;
        Newtonsoft.Json.JsonReader         reader;
        System.Text.Encoding               utf8;
        Counter                            countCounter;
        Object                             obj;
        Map                                data;
        System.Byte[]                      byteArraynew;
        System.Net.WebHeaderCollection     headers = new System.Net.WebHeaderCollection();
        new InteropPermission(InteropKind::ClrInterop).assert();
        str  byteStr = strfmt('%1:%2', "USERNAME", "PASSWORD");
        headers  = new System.Net.WebHeaderCollection();
        url      = "";
        clrObj   = System.Net.WebRequest::Create(url);
        request  = clrObj;
        utf8            = System.Text.Encoding::get_UTF8();
        byteArraynew    = utf8.GetBytes(byteStr);
        byteStr         = System.Convert::ToBase64String(byteArraynew);

        headers.Add("Authorization", 'Basic ' + byteStr);

        servicePoint = request.get_ServicePoint();


        response    = request.GetResponse();
        dataStream  = response.GetResponseStream();
        streamRead  = new System.IO.StreamReader(dataStream);
        jsonString  = streamRead.ReadToEnd();

        info(strFmt("RESPONSE: %1",jsonString));


Thanks for reading !!!

Share Story :

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.