{"id":261,"date":"2019-06-20T19:17:58","date_gmt":"2019-06-20T19:17:58","guid":{"rendered":"https:\/\/www.dabbler.dk\/?p=261"},"modified":"2019-06-20T19:20:54","modified_gmt":"2019-06-20T19:20:54","slug":"bad-request-error-in-query-syntax","status":"publish","type":"post","link":"https:\/\/www.dabbler.dk\/index.php\/2019\/06\/20\/bad-request-error-in-query-syntax\/","title":{"rendered":"Bad Request &#8211; Error in query syntax."},"content":{"rendered":"\n<p>No, this is not an error in WordPress on this server  &#8211; &#8220;Bad Request &#8211; Error in query syntax.&#8221; is in fact the intended subject for this Blog post :-).<\/p>\n\n\n\n<p>If you are running OData WebServices towards you Microsoft Dynamics NAV or 365 Business Central (DBC) and you get this error &#8211; and you have a forward slash ( &#8220;\/&#8221; ) in the company name in question, then this Blog post is for you :-). <\/p>\n\n\n\n<p>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 \u2026\/Company(&#8216;&lt;my company name&gt;&#8217;)\/\u2026 part of the URL.<\/p>\n\n\n\n<p>A obvious solution is to rename the company in NAV\/DBC &#8211; but that is not really a neat solution, is it?<\/p>\n\n\n\n<p>According to <a aria-label=\"this Microsoft blog post (opens in a new tab)\" href=\"https:\/\/cloudblogs.microsoft.com\/dynamics365\/it\/2018\/09\/24\/how-to-get-odata-urls-with-company-names-that-contain-forward-slashes\/\" target=\"_blank\" rel=\"noreferrer noopener\">this Microsoft blog post<\/a>, another far superior solution exists. NAV\/DBC supports two syntaxes when stating the company name.<\/p>\n\n\n\n<p>The &#8220;classic&#8221; one you use for OData version 3 when you got the error:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">https:\/\/&lt;my hostname&gt;:&lt;my odata port&gt;\/&lt;my instance&gt;\/OData\/Company('&lt;my company')\/&lt;my webservice&gt;<\/pre>\n\n\n\n<p>&#8230;or the corresponding OData version 4 one:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">https:\/\/&lt;my hostname&gt;:&lt;my odata port&gt;\/&lt;my instance&gt;\/ODataV4\/Company('&lt;my company')\/&lt;my webservice&gt;<\/pre>\n\n\n\n<p>&#8230;and another one for working around this error:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">https:\/\/&lt;my hostname&gt;:&lt;my odata port&gt;\/&lt;my instance&gt;\/OData\/&lt;my webservice&gt;?company='&lt;my company&gt;'<\/pre>\n\n\n\n<p>&#8230;or the corresponding OData version 4 one:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">https:\/\/&lt;my hostname&gt;:&lt;my odata port&gt;\/&lt;my instance&gt;\/ODataV4\/&lt;my webservice&gt;?company='&lt;my company&gt;'<\/pre>\n\n\n\n<p>Note that you can off cause add additonal parameters (selecting tenant or setting filters etc.) to the URL using the ampersand sign ( &#8220;&amp;&#8221; ) &#8211; just like you do when construction any URL.<\/p>\n\n\n\n<p>Congratulations &#8211; you solved your problem \ud83d\ude42<\/p>\n\n\n\n<p>If you want to learn more about OData towards NAV\/DBC, I suggest you visit these links:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Using NAV\/DBC OData from PowerShell: <a aria-label=\"https:\/\/scblog.lynge.org\/?p=1105 (opens in a new tab)\" href=\"https:\/\/scblog.lynge.org\/?p=1105\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/scblog.lynge.org\/?p=1105<\/a><br>Yes, one of the authors is me :-). Although the blog text is in Danish (sorry), the code example is in English&#8230;<br><\/li><li>Using filtering in OData: <a aria-label=\"https:\/\/docs.microsoft.com\/en-us\/dynamics-nav\/using-filter-expressions-in-odata-uris (opens in a new tab)\" href=\"https:\/\/docs.microsoft.com\/en-us\/dynamics-nav\/using-filter-expressions-in-odata-uris\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/docs.microsoft.com\/en-us\/dynamics-nav\/using-filter-expressions-in-odata-uris<\/a><br><\/li><li>Using FlowFilters in OData: <a aria-label=\"https:\/\/docs.microsoft.com\/en-us\/dynamics-nav\/how-to--use-flowfilters-in-odata-uris (opens in a new tab)\" href=\"https:\/\/docs.microsoft.com\/en-us\/dynamics-nav\/how-to--use-flowfilters-in-odata-uris\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/docs.microsoft.com\/en-us\/dynamics-nav\/how-to&#8211;use-flowfilters-in-odata-uris<\/a> <br>Note: This one also shows how to do a lookup using the primary key.<br><\/li><li>Sorting and other interesting parameters for OData version 4: <a aria-label=\"http:\/\/docs.oasis-open.org\/odata\/odata\/v4.0\/errata02\/os\/complete\/part1-protocol\/odata-v4.0-errata02-os-part1-protocol-complete.html#_Toc406398305 (opens in a new tab)\" href=\"http:\/\/docs.oasis-open.org\/odata\/odata\/v4.0\/errata02\/os\/complete\/part1-protocol\/odata-v4.0-errata02-os-part1-protocol-complete.html#_Toc406398305\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/docs.oasis-open.org\/odata\/odata\/v4.0\/errata02\/os\/complete\/part1-protocol\/odata-v4.0-errata02-os-part1-protocol-complete.html#_Toc406398305<\/a><br>Disclaimer: I&#8217;m not sure everything works when NAV\/DBC is the OData target &#8211; you&#8217;ll have to check that yourself&#8230;<\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>No, this is not an error in WordPress on this server &#8211; &#8220;Bad Request &#8211; Error in query syntax.&#8221; 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 &#8211; and you have &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.dabbler.dk\/index.php\/2019\/06\/20\/bad-request-error-in-query-syntax\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Bad Request &#8211; Error in query syntax.&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":263,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,11,5],"tags":[27,32,25,24,26,12],"class_list":["post-261","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dynamics-nav","category-powershell","category-software","tag-bug","tag-business-central","tag-dynamics","tag-microsoft","tag-nav","tag-powershell"],"_links":{"self":[{"href":"https:\/\/www.dabbler.dk\/index.php\/wp-json\/wp\/v2\/posts\/261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dabbler.dk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dabbler.dk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dabbler.dk\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dabbler.dk\/index.php\/wp-json\/wp\/v2\/comments?post=261"}],"version-history":[{"count":7,"href":"https:\/\/www.dabbler.dk\/index.php\/wp-json\/wp\/v2\/posts\/261\/revisions"}],"predecessor-version":[{"id":269,"href":"https:\/\/www.dabbler.dk\/index.php\/wp-json\/wp\/v2\/posts\/261\/revisions\/269"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.dabbler.dk\/index.php\/wp-json\/wp\/v2\/media\/263"}],"wp:attachment":[{"href":"https:\/\/www.dabbler.dk\/index.php\/wp-json\/wp\/v2\/media?parent=261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dabbler.dk\/index.php\/wp-json\/wp\/v2\/categories?post=261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dabbler.dk\/index.php\/wp-json\/wp\/v2\/tags?post=261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}