Hello Guys
We are now new to support Dynamics platform . To change order status in Dynamics , we used XRM tool box and it worked fine. But when trying to automate using WebAPI Call it throws error Object Reference not set to instance of object.
Can you please help me to resolve this issue??
Regards
Praveen
Hi,
Use below C# web api code to update status of order. Make sure you pass correct Statecode and statuscode integer values. Combinations should be correct.
using (HttpClient httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri(Resource); httpClient.Timeout = new TimeSpan(0, 2, 0); httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0"); httpClient.DefaultRequestHeaders.Add("OData-Version", "4.0"); httpClient.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _authResult.AccessToken); //update order status JObject updateOrder = new JObject { {"statecode", 0}, {"statuscode", 2} }; HttpResponseMessage updateResponse = await httpClient.SendAsJsonAsync(new HttpMethod("PATCH"), "api/data/v8.2/salesorders(" salesorderid{replace with guid of order} ")", updateorder); }
Please find below link which has sample Web API c# code to perform basic operations in CRM.
https://github.com/jlattimer/CrmWebApiCSharp/blob/master/CrmWebApiCSharp/Program.cs
Hy Praveen,
Hope this post finds you well. Can you please share the code and explain in detail what you are trying to achieve.
Thanks,
Ankit Sabharwal
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... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156