Test the json part 2

 internal final class TECGPSevrice

{

    

    /// <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)

    {

          Newtonsoft.Json.Linq.JTokenWriter       writer;

          Newtonsoft.Json.Linq.JObject            jObject;

          ClrObject                               clrObject;

          

          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       token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImtXYmthYTZxczh3c1RuQndpaU5ZT2hIYm5BdyIsImtpZCI6ImtXYmthYTZxczh3c1RuQndpaU5ZT2hIYm5BdyJ9.eyJhdWQiOiJodHRwczovL3VzbmNvbmVib3hheDFhb3MuY2xvdWQub25lYm94LmR5bmFtaWNzLmNvbS8iLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC81YTIyNDNiYS05ODZkLTQxNjAtOTk1NC03MjRmNGM1YzI1ODQvIiwiaWF0IjoxNzA4NTE3NjU5LCJuYmYiOjE3MDg1MTc2NTksImV4cCI6MTcwODUyMTU1OSwiYWlvIjoiRTJWZ1lHQ2E4YlBsd3JkVmZMZm5OMHA5NytsbUF3QT0iLCJhcHBpZCI6ImJhM2U2OTFmLTg2MzUtNDM0OS05Y2Y4LWRmOTYyYzczZmNhYiIsImFwcGlkYWNyIjoiMSIsImlkcCI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0LzVhMjI0M2JhLTk4NmQtNDE2MC05OTU0LTcyNGY0YzVjMjU4NC8iLCJvaWQiOiI1Yzc2MDBjYy1mY2VmLTQ0YmEtOTFkNy00ZDhjNGNjYWMwZGIiLCJyaCI6IjAuQVhJQXVrTWlXbTJZWUVHWlZISlBURndsaEJVQUFBQUFBQUFBd0FBQUFBQUFBQUREQUFBLiIsInN1YiI6IjVjNzYwMGNjLWZjZWYtNDRiYS05MWQ3LTRkOGM0Y2NhYzBkYiIsInRpZCI6IjVhMjI0M2JhLTk4NmQtNDE2MC05OTU0LTcyNGY0YzVjMjU4NCIsInV0aSI6IjBPS1RVYVRHZUUySlBMVTg1ZGtyQUEiLCJ2ZXIiOiIxLjAifQ.OU_g_MFHfg0K-BMQ3BcvXbPYBPuxdgjDDM5jg6ahCGPO5tsm-JkMLzwAs_ChvQ4nc6eU3YnYH_GKkv_eU5Reu1cW9uLkrgCDFq6JOdd4z1dfpz124XJyLV40aXVofwvLDKLFnVnP3lklHCpQNbULy9aS7X6-7oBMmiZEoe2a01o55FbRYhe7VTe3_f7lSUjl7aHqOLIcOU-JGTEZraV6SMyWDu-DcrJf9TF-eUBkzFo7Gis5_ZVzZ-BGpjIePTtqugQ_--06mz1B1o0cXu1Nr_lPTtfbe-dPmS8lucBVQ099T-zgrFkJH9Vsr2zY3tKm61Yz5JClnWpQQR8l0TYjrw";

          str       custaccount = "'STPL-000021'";

          str       dataareaid = "'STPL'";


       

        //  select * from parameters;

          //where

          // setting all header here

          httpHeader = new System.Net.WebHeaderCollection();

          httpHeader.Add("authorization", "Bearer " + token);

         //  httpHeader.Add("CustomerAccount",custaccount);

         // httpHeader.Add("dataAreaId", dataareaid);

        

          try

          {

               

               new InteropPermission(InteropKind::ClrInterop).assert();

             //  clrObj = System.Net.WebRequest::Create("https://usnconeboxax1aos.cloud.onebox.dynamics.com/data/CustomersV3(dataAreaId='STPL',CustomerAccount='STPL-000021')");


                clrObj = System.Net.WebRequest::Create("https://usnconeboxax1aos.cloud.onebox.dynamics.com/data/CustomersV3"+"(dataAreaId="+dataareaid+","+"CustomerAccount="+custaccount+")");

               

               request = clrObj;

            

               request.set_Headers(httpHeader);

               request.set_Method('PATCH');

               request.set_ContentType('application/json');

             

               requestStream = request.GetRequestStream();

               streamWriter = new System.IO.StreamWriter(requestStream);


               writer = new Newtonsoft.Json.Linq.JTokenWriter();

               writer.WriteStartObject();

               writer.WritePropertyName("TECCRMUpdated");

               writer.WriteValue("Yes");

               

               writer.WriteEndObject();


               clrObject   = writer.get_Token();

               jObject     = clrObject;

               reqBodyStr  = jObject.ToString();

        

               // Request

               streamWriter.WriteAsync(reqBodyStr);

               streamWriter.Flush();

               streamWriter.Close();


               //Response

               new InteropPermission(InteropKind::DllInterop).assert();

               response = request.GetResponse();

               requestStream = response.GetResponseStream();

               streamRead = new System.IO.StreamReader(requestStream);

               resBodyStr = streamRead.ReadToEnd();


               if(response.StatusCode == 204)

               {

                    info("Record updated succefuuly");

               }

               //info(strFmt("%1",resBodyStr));

          }

          catch

          {

               info("Error: " + CLRInterop::getLastException().ToString());

          }

    }


}


Comments

Popular posts from this blog

Customization on Sales invoice Report in D365 F&O

75) COC - Create a coc of the table modified method

46) D365 FO: SHAREPOINT FILE UPLOAD USING X++