No, this is not an error in WordPress on this server – “Bad Request – Error in query syntax.” is in fact the intended subject for this Blog post :-).
If you are running OData WebServices towards you Microsoft Dynamics NAV or 365 Business Central (DBC) and you get this error – and you have a forward slash ( “/” ) in the company name in question, then this Blog post is for you :-).
You have just discovered that Excel, PowerShell.exe and/or older version of PowerShell ISE cannot work with OData URLs with a forward slash in the …/Company(‘<my company name>’)/… part of the URL.
A obvious solution is to rename the company in NAV/DBC – but that is not really a neat solution, is it?
According to this Microsoft blog post, another far superior solution exists. NAV/DBC supports two syntaxes when stating the company name.
The “classic” one you use for OData version 3 when you got the error:
https://<my hostname>:<my odata port>/<my instance>/OData/Company('<my company')/<my webservice>
…or the corresponding OData version 4 one:
https://<my hostname>:<my odata port>/<my instance>/ODataV4/Company('<my company')/<my webservice>
…and another one for working around this error:
https://<my hostname>:<my odata port>/<my instance>/OData/<my webservice>?company='<my company>'
…or the corresponding OData version 4 one:
https://<my hostname>:<my odata port>/<my instance>/ODataV4/<my webservice>?company='<my company>'
Note that you can off cause add additonal parameters (selecting tenant or setting filters etc.) to the URL using the ampersand sign ( “&” ) – just like you do when construction any URL.
Congratulations – you solved your problem 🙂
If you want to learn more about OData towards NAV/DBC, I suggest you visit these links:
- Using NAV/DBC OData from PowerShell: https://scblog.lynge.org/?p=1105
Yes, one of the authors is me :-). Although the blog text is in Danish (sorry), the code example is in English… - Using filtering in OData: https://docs.microsoft.com/en-us/dynamics-nav/using-filter-expressions-in-odata-uris
- Using FlowFilters in OData: https://docs.microsoft.com/en-us/dynamics-nav/how-to–use-flowfilters-in-odata-uris
Note: This one also shows how to do a lookup using the primary key. - Sorting and other interesting parameters for OData version 4: http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part1-protocol/odata-v4.0-errata02-os-part1-protocol-complete.html#_Toc406398305
Disclaimer: I’m not sure everything works when NAV/DBC is the OData target – you’ll have to check that yourself…