Symptom
This KBA helps in understanding how to deal with the special characters in an OData API url and also lists out the restricted vs non-restricted characters.
Environment
- SAP SuccessFactors HCM Suite
- OData API
Resolution
1. Understanding Special Characters in OData URLs
OData API URLs often need to include various special characters. However, certain characters can cause errors if not properly handled. It's important to distinguish between restricted and non-restricted characters.
2. Restricted Characters
Restricted characters are those that cannot be used directly in OData URLs. They must be percent-encoded to ensure the URL is correctly interpreted by the API. The following characters are restricted:
- Space (
- Double quote (
"
) - Hash (
#
) - Percent (
%
) - Ampersand (
&
) - Plus (
+
) - Question mark (
?
) - Slash (
/
) - Backslash (
\
) - Colon (
:
) - Semicolon (
;
) - Less than (
<
) - Greater than (
>
) - Equal (
=
) - Pipe (
|
) - Caret (
^
) - Tilde (
~
) - Opening and closing square brackets (
[
and]
) - Opening and closing curly braces (
{
and}
) - Grave accent/backtick (
`
)
3. Non-restricted Characters
Non-restricted characters can be used directly in OData URLs without needing to be encoded. These include:
- Alphabets (A-Z, a-z)
- Digits (0-9)
- Hyphen (
-
) - Underscore (
_
) - Period (
.
) - Exclamation mark (
!
) - Dollar sign (
$
) - Asterisk (
*
) - Apostrophe (
'
) - Opening and closing parentheses (
(
and)
)
4. Handling Restricted Characters
To handle restricted characters, you need to encode them using percent-encoding. This involves replacing the restricted character with a %
symbol followed by its ASCII hexadecimal value. For example:
- Space (
%20
- Double quote (
"
) becomes%22
- Hash (
#
) becomes%23
- Percent (
%
) becomes%25
- Ampersand (
&
) becomes%26
5. Example
Consider the following URL which includes restricted characters:
https://api.example.com/odata/Product('ABC 123')?$filter=Price gt 20&Category='Electronics & Gadgets'
The corrected URL with percent-encoding for the restricted characters would be:
https://api.example.com/odata/Product('ABC%20123')?$filter=Price%20gt%2020&Category='Electronics%20&%20Gadgets'
For more details and a comprehensive list of restricted and non-restricted characters, refer to the link below:
https://help.sap.com/viewer/d599f15995d348a1b45ba5603e2aba9b/latest/en-US/c39284943ddd4476bdbd9d2b66e01abe.html
Keywords
OData, API, URL, Special Characters, Restricted Characters, Percent-Encoding For more details and a comprehensive list of restricted and non-restricted characters, refer to the SAP Help Portal. , KBA , LOD-SF-INT-ODATA , OData API Framework , LOD-SF-INT , Integrations , Problem