public static void main(Args _args)
{
//Library class for getting access token
AADAuthClient.Program program = new AADAuthClient.Program();
try
{
// Create the authentication client
str accessToken = program.getAccessTokenAsync(tokenEndPoint, clientId, clientSecret);
if (!accessToken)
{
throw error("Access token retrieval failed.");
return;
}
System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
// Add the access token to the request headers
headers.Add("Authorization", "Bearer " + accessToken);
headers.Add("Content-Type", "application/json");
// Set the request URL
str apiUrl = "URI"; // Replace with your API endpoint URL
// Create the HTTP request
System.Net.HttpWebRequest request = System.Net.WebRequest::Create(apiUrl) as System.Net.HttpWebRequest;
//request.set_Headers(headers);
request.Method = 'POST';
//This part is for sending json body
JSONContract contract = new JSONContract();
contract.parmBOMId("string");
contract.parmCustRef("string");
//This is a class for handling JSON
JsonParser jsonParser = new JsonParser();
str jsonBody = jsonParser.objtoJson(contract);
using (var streamWriter = new System.IO.StreamWriter(request.GetRequestStream()))
{
streamWriter.Write(jsonBody);
streamWriter.Flush();
}
// Send the request
System.Net.HttpWebResponse response = request.GetResponse();
// Read and process the response
str responseBody = response.GetResponseStream().ToString();
//System.IO.StreamReader streamRead;
//streamRead = new System.IO.StreamReader(response.GetResponseStream());
info(strFmt("API Response: %1", responseBody));
info(strFmt("jsonBody: %1", jsonBody));
}
catch (Exception::Error)
{
error(/An error occurred during authentication or the HTTP request: /); //+ errorTextGet());
}
}
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,902 Super User 2024 Season 2
Martin Dráb 229,302 Most Valuable Professional
nmaenpaa 101,156