Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Dyanmics 365 web API giving "Bad Request - Error in query syntax" error.

Posted on by 505

I'm posting the following json to create an order product in Dynamics 365 online (V 9.0).

"{\"productid@odata.bind\":\"/products(ea69cd50-5e58-e811-a954-000d3a33e5a2)\",\"salesorderid@odata.bind\":\"/salesorders({3818B268-D25D-E811-A958-000D3A33E5A2})\",\"uomid@odata.bind\":\"/uoms(9964520C-7B37-E811-A953-000D3A3099E5)\",\"wo_lotnumber\":\"5$\",\"priceperunit\":1000,\"isproductoverridden\":false}"

The API is giving "Bad Request - Error in query syntax" error.

Can someone let me know what could be wrong with my Json?

*This post is locked for comments

  • Dyanmics 365 web API giving "Bad Request - Error in query syntax" error.
    Came in to validate this. It applies even to context.WebApi.CreateRecord in PCF controls. So frustrating because you would NEVER be able to gather this from the error message. You can use string replace like this:
     
    let value = "{f98f4441-09d7-4f00-a19d-70c27d9216a5}";
    return value.replace(/[{}]/g, "");
  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Dyanmics 365 web API giving "Bad Request - Error in query syntax" error.

    Try to use

    "{\"productid@odata.bind\":\"/products(ea69cd50-5e58-e811-a954-000d3a33e5a2)\",\"salesorderid@odata.bind\":\"/salesorders(3818B268-D25D-E811-A958-000D3A33E5A2)\",\"uomid@odata.bind\":\"/uoms(9964520C-7B37-E811-A953-000D3A3099E5)\",\"wo_lotnumber\":\"5$\",\"priceperunit\":1000,\"isproductoverridden\":false}"

    instead of your original request. As you mentioned without curly brackets around salesorderid - works, when you have it like in initial request - it does not.

  • Priyank Bhavsar Profile Picture
    Priyank Bhavsar 505 on at
    RE: Dyanmics 365 web API giving "Bad Request - Error in query syntax" error.

    Thanks a lot Andrew the curly braces was the culprit. I misunderstood what you meant to say in the first reply but now got your point.

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Dyanmics 365 web API giving "Bad Request - Error in query syntax" error.

    Hello,

    WebApi doesn't like curly brackets. My first shot is try to replace

    "/salesorders({3818B268-D25D-E811-A958-000D3A33E5A2})\"

    with

    "/salesorders(3818B268-D25D-E811-A958-000D3A33E5A2)\"

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