Get the json response consume the CRM api
internal final class TECGetAccountGUID
{
/// <summary>
/// Class entry point. The system will call this method when a designated menu
/// is selected or when execution starts and this class is set as the startup class.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
System.Net.HttpWebResponse response;
CLRObject clrObj;
System.Exception ex;
System.IO.Stream requestStream;
System.IO.StreamWriter streamWriter;
System.IO.StreamReader streamRead;
System.Net.WebHeaderCollection httpHeader, httpHeaderRes;
System.Net.HttpWebRequest request;
Notes reqBodyStr, resBodyStr;
str getAccountid;
str rawResponse;
Map responseData;
str eqValue = 'Tata Communications Limited';
str token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IlhSdmtvOFA3QTNVYVdTblU3Yk05blQwTWpoQSIsImtpZCI6IlhSdmtvOFA3QTNVYVdTblU3Yk05blQwTWpoQSJ9.eyJhdWQiOiJodHRwczovL3N5bmRyb21lY3JtdWF0LmNybTguZHluYW1pY3MuY29tIiwiaXNzIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvNWEyMjQzYmEtOTg2ZC00MTYwLTk5NTQtNzI0ZjRjNWMyNTg0LyIsImlhdCI6MTcwODk0MjUyMCwibmJmIjoxNzA4OTQyNTIwLCJleHAiOjE3MDg5NDY0MjAsImFpbyI6IkUyTmdZTGdlKzZFNmJZR3Y2V1psOHd2ZmwydFVBQUE9IiwiYXBwaWQiOiIyYjcwMzVhZi1lNDIzLTRmMGMtYTI5OS1lMjJiYjBlOWNlYTkiLCJhcHBpZGFjciI6IjEiLCJpZHAiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC81YTIyNDNiYS05ODZkLTQxNjAtOTk1NC03MjRmNGM1YzI1ODQvIiwib2lkIjoiNGVlYTFiYmQtNjc2Ni00ZDk0LWE0NjgtOTg0ZmE3ZDJmNjVlIiwicmgiOiIwLkFYSUF1a01pV20yWVlFR1pWSEpQVEZ3bGhBY0FBQUFBQUFBQXdBQUFBQUFBQUFEREFBQS4iLCJzdWIiOiI0ZWVhMWJiZC02NzY2LTRkOTQtYTQ2OC05ODRmYTdkMmY2NWUiLCJ0ZW5hbnRfcmVnaW9uX3Njb3BlIjoiQVMiLCJ0aWQiOiI1YTIyNDNiYS05ODZkLTQxNjAtOTk1NC03MjRmNGM1YzI1ODQiLCJ1dGkiOiJLVHdVNnNxb08wU3J4WTdmaXJkd0FBIiwidmVyIjoiMS4wIiwieG1zX2NhZSI6IjEifQ.ZU0z35TQeyY7e5tV3C3hAZHOyolib94Y7_kJUiV_K2bXyrEVKmMb7eJhzAp5ZyVq5jQHF4zU8KGB5xEBevhuH8fPAqSf7gbpujLK6-jA2UHTm_urOOSPjwnyITSJdWINVxKdPn1HGmfeV5uPWsXfLuiB4Tpl7A2lb2V_Mpo1cmeEs-sZO8-zZTPTvmj6zB5kbw7jVf5s-0VZm6KcaZ6UbXJhFBsOsc57AEJt14BvelZKhlGunpTgQSbNFRAlrmwpjGr7Eop0uAr7J_IyKl1zmcG4S00gQ1DCQ8eSwe5J-RnR182tNYZ_9Wr8355Gf2SrNF1dXKnG51saiGZuOJgBMw';
// setting all header here
httpHeader = new System.Net.WebHeaderCollection();
httpHeader.Add("authorization", "Bearer " + token);
httpHeader.Add("prefer","return=representation");
try
{
new InteropPermission(InteropKind::ClrInterop).assert();
clrObj = System.Net.WebRequest::Create('https://syndromecrmuat.api.crm8.dynamics.com/api/data/v9.2/accounts?$select=name&$filter=name%20eq%20%20%27Tata%20Communications%20Limited%27'); //eq//System.Net.WebRequest::Create(parameters.EinvPDF+"?format=PDF&irns="+ewayNumber);
request = clrObj;
request.set_Headers(httpHeader);
request.set_Method('GET');
request.set_ContentType('application/json; charset=utf-8');
//Response
new InteropPermission(InteropKind::DllInterop).assert();
response = request.GetResponse();
streamRead = new System.IO.StreamReader(response.GetResponseStream());
resBodyStr = streamRead.ReadToEnd();
// rawResponse = response;//response.parmData();
responseData = RetailCommonWebAPI::getMapFromJsonString(resBodyStr);
// Get the value from the Map
mapEnumerator mapEnumerator;
Map map1;
List accountList;
ListEnumerator listEnumerator;
container accountID;
mapEnumerator = responseData.getEnumerator();
while ( mapEnumerator.moveNext())
{
switch (mapEnumerator.currentKey())
{
case "value" :
accountID = mapEnumerator.currentValue();
accountList =List::create(accountID);
listEnumerator = accountList.getEnumerator();
while (listEnumerator.moveNext())
{
accountID = listEnumerator.current();
map1 = Map::create(accountID);
//info(map1.lookup('accountid'));
getAccountid = map1.lookup("accountid");
}
break;
}
}
// accountid = responseData.lookup("Value");
Info(getAccountid);
//info(strFmt('Report download : %1',filepaths));
}
catch
{
ex = CLRInterop::getLastException().GetBaseException();
error(ex.get_Message());
}
}
}
Comments
Post a Comment