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
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
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
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Rishabh Kanaskar 235
MVP-Daniyal Khaleel 177
Tom_Gioielli 156 Super User 2025 Season 2