2

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?

4
  • You are missing to close the value in the end. ('). Jan 14, 2016 at 8:48
  • 1
    Try use encodeURI() on your value (see sharepoint.stackexchange.com/questions/164673/…) Jan 14, 2016 at 8:51
  • Any help from my answer? @vikashkumar Jan 18, 2016 at 4:42
  • yes, but it was not working by directly putting it to the url so I have taken a variable to store encodeURIComponent("India & China")+"') and then I added it to url.
    – KumarV
    Jan 18, 2016 at 5:50

1 Answer 1

6

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 and acknowledge you have read our privacy policy.

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