16

Trying to use the SP2013 REST API to ping a library with the title "Prep & Admin Docs" and I can't use getbyID as this snippet will be used in multiple sites where the GUID of the list will vary.

I've tried multiple methods of encoding but nothing seems to be working.

/_api/lists/getbytitle('Prep & Admin Docs')
/_api/lists/getbytitle('Prep & Admin Docs')
/_api/lists/getbytitle('Prep %26 Admin Docs')

When I check /_api/lists I can see the list there and the title shows up exactly as I have it. But I can't seem to use that string in the query. It's most likely something simple that I'm missing.

Is there a way to query by EntityTypeName?

  • Any help from my answer? – Atish Dipongkor - MVP Dec 23 '15 at 4:02
  • 2
    It did not help me... M facing the same issue – Ankitkumar Malde Aug 18 '16 at 9:28
  • Please consider marking the answers that provide a solution as "solution". There was a missing quote, that maybe the reason why it didnt work for you. – Alberto Feb 25 at 17:58
8

EntityTypeName is not needed. List title is the only need. If your list title contains any special character, then you can use encodeURI().

For example

var listNameAsencodeURI = encodeURI('Prep & Admin Docs');

It will output something like

"Prep%20&%20Admin%20Docs"

Now use above output in API end-point

/_api/lists/getbytitle('Prep%20&%20Admin%20Docs')

OR

"/_api/lists/getbytitle('"+encodeURI('Prep & Admin Docs')+"')"

Note: All special characters except , / ? : @ & = + $ # are needed to be encoded if we use them in list name.

|improve this answer|||||
  • 3
    I have tried your suggestions for the URL but still m getting error " A potentially dangerous Request.Path value was detected from the client (&). ". Can u please help. – Ankitkumar Malde Aug 18 '16 at 9:27
  • 1
    I'm too getting this issue. Please help me to resolve this error. – Dikesh Gandhi Aug 26 '16 at 5:37
  • What's your title? – Atish Dipongkor - MVP Aug 26 '16 at 6:18
4

Reading some of the replies, I'd like to supplement with the following article:

http://xkr.us/articles/javascript/encode-compare/

I am on Office 365 and I made a library where I tried your approaches. Note that there might be differences between the latest version of SP and the one running on premise.

Performing some tests I found that both & and %26 work fine for me, but not if I try using &.

The other thing worth noting is that the GetByTitle method takes a string, as indicated by the ' characters. This means that when using the various escaping methods in javascript, the ' will never be escaped, so you have to do that yourself.

For example if you have a list named Bob's Bacon & Eggs you'd use /_api/Lists/GetByTitle('Bob''s Bacon & Eggs') to access the data.

If you wish to have a variable for the name of the list, you could escape it using the following approach: "/_api/Lists/GetByTitle('" + encodeURIComponent(listName).replace(/\'/g, "''") + "')"

|improve this answer|||||
4

Try querying the endpoint as: /_api/web/lists/getbytitle('Pre%20%26%20Admin%20Docs')

More details on this good article here

enter image description here

In the case of working out the "&", just replace it with "%26", as the picture shows.

hope this will help you!

|improve this answer|||||
0

There's a big difference in SPOnline and on-premises SP. I haven't been able to find a way to make this work with any sort of encoding with SP2013 on-prem, but it works with no endcoding at all to the SPOnline REST API.

/_api/lists/getbytitle('Prep & Admin Docs')

It's another one of those maddening ways that SP is consistently inconsistent.

|improve this answer|||||
-1

This work for me. See the screenshot. Strange !!!

/_api/web/lists/getbytitle(Pre%20&%20Admin%20Docs')

enter image description here

enter image description here

|improve this answer|||||

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.