04-02-2024 3:36 AM - edited 04-02-2024 2:26 PM
Hi,
I have an Odata Query which is working (getting data) fine when i use 'eq' as below:
/sap/opu/odata/SAP/Z*****_01/BPInputsSet?$format=json&$filter= Account eq '800000012341' and Prodtyp eq 'EWR' &$expand=NavtoData1,NavtoData2&$format=json
But when i replace 'EQ' with '=' its throwing error like " 400 : Invalid token detected at position.".etc
How to correct this error?
This is not an error, it’s how it works as per OData spec.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Imagine these two:
Now think about writing a parser for the second option 😉 Also don't forget how URL params work in your browser.
You could also check the spec to learn that $filter doesn't not allow a '=' (scroll to the section): 4.5. Filter System Query Option ($filter)
You need to know, that query parameters (also called CGI parameters, based on an old standard of the 90s) have a special format, where the characters '?', '&', '+', '%' and '=' have a special meaning. Roughly speaking, the format of a URL with query parameters is:
http://hostname:port/path?name1=value1&name2=value2
The ? separates the query parameters from the rest of the URL, the & separates two query parameters from each other, and the = separates the query-name from the query-value. A % sign is used to indicate an "escape sequence" and a +-sign can be used to represent a space inside a name or value. For example a parameter "street" with value "Alan Turing Avenue 42" would be encoded as
?street=Alan+Turing+Avenue+42
That means, if you want to use any of these special characters (and some others) inside the name or value of a query parameter, you need to "URL-encode" it. See HTML URL Encoding Reference (w3schools.com)
In our example, we have a query parameter with the name "$filter" and the value "Account = '800000012341' and Prodtyp = 'EWR'". The = sign needs to be encoded as %3D, leading to the following correct query:
?$format=json&$filter=Account%20%3D%20'800000012341'%20and%20Prodtyp%20%3D%20'EWR'&$expand=NavtoData1%2DNavtoData2
(Note that the algorithm used here, encoded space characters as %20 instead of as a + sign, which is also ok. In general, every character can be encode ("escaped") by %xy, where xy is the hexadecimal value of its ASCII code or its UTF-8 code.)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
74 | |
9 | |
7 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.