In REST API when I pass a value with &(ex: India & China), it throws error and when I checked it in browser it shows &amnp; in place of &.

https://test/_api/web/lists/GetByTitle('Team')/Items?$filter=(Title eq 'India & China')

What shall I do to fix this?


You need to use encodeURIComponent() not encodeURI()

Query Url should look like

/_api/web/lists/GetByTitle('Team')/Items?$filter=(Title eq '"+encodeURIComponent("India & China")+"')

encodeURIComponent() vs encodeURI()

If list name contains any special character like /, ?, :, @, &, =, +, $ or #, then use encodeURI().

In $filter always use encodeURIComponent().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.