Test the Json service with the Bearer token
internal final class TECTestService
{
/// <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.Exception ex,webException;
str errorMsg,bodyData,byteTokenStr,payload,output;
SysInfologEnumerator infoEnumerator;
SysInfologMessageStruct infoMsgStruct;
Exception readException;
try
{
// System.String headerKey = "Authorization";
// System.String headerValue = "Bearer" + "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IjVCM25SeHRRN2ppOGVORGMzRnkwNUtmOTdaRSIsImtpZCI6IjVCM25SeHRRN2ppOGVORGMzRnkwNUtmOTdaRSJ9.eyJhdWQiOiJodHRwczovL3VzbmNvbmVib3hheDFhb3MuY2xvdWQub25lYm94LmR5bmFtaWNzLmNvbS8iLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC81YTIyNDNiYS05ODZkLTQxNjAtOTk1NC03MjRmNGM1YzI1ODQvIiwiaWF0IjoxNzA2MzUxMTU0LCJuYmYiOjE3MDYzNTExNTQsImV4cCI6MTcwNjM1NTA1NCwiYWlvIjoiRTJWZ1lNam40Mkt6YzBqYXJyRmZ2NFhOWEhBQ0FBPT0iLCJhcHBpZCI6ImJhM2U2OTFmLTg2MzUtNDM0OS05Y2Y4LWRmOTYyYzczZmNhYiIsImFwcGlkYWNyIjoiMSIsImlkcCI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0LzVhMjI0M2JhLTk4NmQtNDE2MC05OTU0LTcyNGY0YzVjMjU4NC8iLCJvaWQiOiI1Yzc2MDBjYy1mY2VmLTQ0YmEtOTFkNy00ZDhjNGNjYWMwZGIiLCJyaCI6IjAuQVhJQXVrTWlXbTJZWUVHWlZISlBURndsaEJVQUFBQUFBQUFBd0FBQUFBQUFBQUREQUFBLiIsInN1YiI6IjVjNzYwMGNjLWZjZWYtNDRiYS05MWQ3LTRkOGM0Y2NhYzBkYiIsInRpZCI6IjVhMjI0M2JhLTk4NmQtNDE2MC05OTU0LTcyNGY0YzVjMjU4NCIsInV0aSI6ImI3WkszUXltekV5eDllUll2QUFPQUEiLCJ2ZXIiOiIxLjAifQ.IO9pyfBCI42wg2RGb59Ijdy5zN2_9CMPYfO_CrEWoola0OLOlvAL_K-hgkSagWlXknHaTJHLywjT2L5jSZEZlLcxYZNuHmwUlPEQeYTtgs6JrvyvnrHhaQNF88G6FeBZcxkUmtEQ3p-Gk32IkCgztCj3CI2ZIIgMJDxxh_5YDu2bZdWoCp-aWf3dYFGr5HE947-eZNdaRUTJQ65EYEwGOYAi1Q3ZBAtlhQEsrva7tIXspXEDYrYStQKDh_zNHkDWRebrYG8HD9LsiALU-OvWH6xNTMnR3DHMxrrNeyhbpzncHaq82zT9VZCEYJ2fHrx-71PyLm_UvxKY-ICYhP0zCg";
// System.Net.WebRequest webreq = System.Net.WebRequest::Create("https://usnconeboxax1aos.cloud.onebox.dynamics.com/data/SalesInvoiceBillingsDetails");
System.IO.Stream streamstr,responsestr;
System.Net.WebHeaderCollection httpHeader = new System.Net.WebHeaderCollection();
System.Net.HttpWebRequest request;
CLRObject clrObj;
System.IO.StreamWriter streamWriter;
System.Net.WebResponse webresponse;
System.IO.StreamReader reader;
System.Net.HttpWebResponse response;
System.IO.Stream requestStream, responseStream;
System.IO.StreamReader streamReader;
str responseJSON;
str responseStrFinal;
str sJSON;
str destinationUrl = "https://usnconeboxax1aos.cloud.onebox.dynamics.com/data/CustomersV3";
str token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IjVCM25SeHRRN2ppOGVORGMzRnkwNUtmOTdaRSIsImtpZCI6IjVCM25SeHRRN2ppOGVORGMzRnkwNUtmOTdaRSJ9.eyJhdWQiOiJodHRwczovL3VzbmNvbmVib3hheDFhb3MuY2xvdWQub25lYm94LmR5bmFtaWNzLmNvbS8iLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC81YTIyNDNiY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esBillingMakerCancel(5637151330);
new InteropPermission(InteropKind::ClrInterop).assert();
clrObj = System.Net.WebRequest::Create(destinationUrl);
request = clrObj;
httpHeader.Add("authorization", "Bearer " + token);
httpHeader.Add("CustomerAccount:"+ 'STPL-000021');
request.set_KeepAlive(true);
request.set_Headers(httpHeader);
request.set_Method("PATCH");
request.set_ContentType('application/json');
// requestStream = request.GetRequestStream();
// streamWriter = new System.IO.StreamWriter(request.GetRequestStream());
streamWriter = new System.IO.StreamWriter(request.GetRequestStream(),System.Text.Encoding::get_ASCII());
streamWriter.Write("\"TECCRMUpdated:\"+\"No\"");
streamWriter.Flush();
streamWriter.Close();
// streamWriter.Dispose();
//Response
// new InteropPermission(InteropKind::DllInterop).assert();
webresponse = request.GetResponse();
responseStream = webresponse.GetResponseStream();
streamReader = new System.IO.StreamReader(responseStream);
responseJSON = streamReader.ReadToEnd();
info(responseJSON);
}
catch (Exception::CLRError)
{
ex = CLRInterop::getLastException();
info(ex.ToString());
if (ex != null)
{
ex = ex.get_InnerException();
if ((ex != null) && (ex is System.Net.WebException))
{
webException = ex as System.Net.WebException;
info(webexception.ToString());
}
}
}
catch (Exception::Error)
{
if(strLen(errorMsg)>1)
errorMsg+='\n';
infoEnumerator = SysInfologEnumerator::newData(infolog.cut());
while (infoEnumerator.moveNext())
{
infoMsgStruct = new SysInfologMessageStruct(infoEnumerator.currentMessage());
readException = infoEnumerator.currentException();
if(readException == Exception::Error || readException == Exception::Warning)
{
errorMsg += infoMsgStruct.message() + '\n';
info(webexception.ToString());
}
}
}
}
}
Comments
Post a Comment