Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

Moving Order State Working using XRM but not by WebAPI

Posted on by 5

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

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Moving Order State Working using XRM but not by WebAPI

    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

    If found helpful, Please mark my answer verified.

  • RE: Moving Order State Working using XRM but not by WebAPI

    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

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.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans