web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Need to call API. First to get response in form of token and then send some data to API to get response in True/False.

(1) ShareShare
ReportReport
Posted on by 518

Hi everyone,

I need to get response from an API call which will send me a token. And onse token received, I need to call API to get response.

I have already tested the API CALL from power automate and it is working fine.

Now I need help in getting this process to be done from a class call. Could you please help me with the code which I can use to get this done?

Regards

Siddhant Singh

I have the same question (0)
  • Verified answer
    Urvashi Kumari Profile Picture
    23 on at

    using System.Net;
    using System.Net.Http;
    
     
    
    class SST_APICall
    {
        public static void main(Args _args)
        {
            System.Net.HttpWebRequest       request;
            System.Net.HttpWebResponse      response;
            CLRObject                       clrObj;
            System.Exception                ex;
            System.Net.WebHeaderCollection  httpHeader;
            System.IO.Stream                requestStream, responseStream;
            SST_APITable                    table1;
            System.IO.StreamWriter          streamWriter;
            System.Net.Cache.HttpRequestCachePolicy policy;
            //System.Net.Cache.HttpRequestCacheLevel cacheLevel;
            //policy = new System.Net.Cache.HttpRequestCachePolicy(cacheLevel);
    
     
    
            str url = "http://yourhost.net/service";
            str clientId = "";
            str secretId = "";
    
     
    
    
            select firstonly1 crosscompany table1;
            httpHeader = new System.Net.WebHeaderCollection();
            new InteropPermission(InteropKind::ClrInterop).assert();
            clrObj = System.Net.WebRequest::Create("https:XXXXX");
    
     
    
            System.Text.Encoding encoding = System.Text.Encoding::UTF8;
            System.Byte[] bytes = encoding.GetBytes(clientId   ":"   secretId);
            System.String base64 = System.Convert::ToBase64String(bytes);
    
     
    
            System.String headerKey = "Authorization";
            System.String headerValue = "Basic "   base64;
            //System.Net.WebRequest request = System.Net.WebRequest::Create(url);
            System.Net.WebHeaderCollection headers = request.Headers;
            headers.Add(headerKey,headerValue);
    
     
    
            request = clrObj;
            // adding headers
            /*headers.Add("Grant", "XXXXX");
            headers.Add("owner_id", "XXXXX");
            headers.Add("gstin", "XXXXX");*/
    
     
    
            request.set_Headers(headers);
            request.Method = "POST";
            request.Accept = "application/json";
            request.ContentType = "application/x-www-form-urlencoded";
    
            requestStream = request.GetRequestStream();
    
     
    
            streamWriter = new System.IO.StreamWriter(request.GetRequestStream());
            streamWriter.Write(table1.FieldString1); // writing JSON
            streamWriter.Flush();
            streamWriter.Close();
    
     
    
            response = request.GetResponse();
            System.IO.StreamReader streamRead = new System.IO.StreamReader(response.GetResponseStream());
            info(streamRead.ReadToEnd());
        }
    
     
    
    }
    
    has context menu

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans