Scenario:
Recently working with REST API to get items from SharePoint list filtered by title field, I got stuck. it was working fine while having data without special character. But having special character - single quote/apostrophe (') in filter parameter was giving an error. I tried by passing value using EncodeURIComponent, but it didn't work either and getting the error as shown below:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBzbNArxDJxHUiUOt156U_8EH7jYkMf8Oe6yrR3LjKaq3kvhC0D6NDp3dfu7Bd866LZPaiVltQhjiQER6-t5j4fQLghEMdm_Dk3MBPfwYky3Q6E07cUZbCE7bzbZmAIInA_q9PXD-bUIE/s1600/23.png)
Reason:
EncodeURIComponent, Escape or EncodeURI functions
can’t escape few special characters: - _ . ! ~ * ' ( )
Solution:
For such special characters as filter parameter, we should double the character (2 single quotes) and use it.
Example:
Example:
Non-working REST API:
https://{Site URL} /_api/web/lists/GetByTitle('listname')/items? select=ID&$filter=Title eq 'what's up'
https://{Site URL} /_api/web/lists/GetByTitle('listname')/items? select=ID&$filter=Title eq 'what's up'
Working REST API:
https://{Site
URL} /_api/web/lists/GetByTitle('listname')/items? select=ID&$filter=Title
eq 'what''s up'
If you have any questions you can reach out our SharePoint Consulting team here.
No comments:
Post a Comment