javalistrestsharepoint-2010sharepoint-2013

SharePoint REST API: Not able to get list by getByTitle when list name contains spaces


I am trying to fetch SharePoint list using the SharePoint REST API from my Java application.

When the list's name does not contain a space, it works. If it contains a space it does NOT work. For example when I do the following: http:(site URL)/_api/web/lists/getbytitle('ONEWORD')/items --> it works

But when I try on another list like this: http:(site URL)/_api/web/lists/getbytitle('TWO WORDS')/items --> it DOESN'T work

I tried encoding the list name with the following in Java: String encoded= URLEncoder.encode("TWO WORDS", "UTF-8"); But it didn't work.

I know there are many questions about this same issue, however everyone is suggesting to get list items by List GUID but I can't use this solution as I'm developing a dynamic tool for several lists with the same name. (Not the same GUID).

Any suggestions? Thank you


Solution

  • You will need to use %20 to replace space. In your case it will be like following url

    http:(site URL)/_api/web/lists/getbytitle('TWO%20WORDS')/items