Home > Software design >  SharePoint REST API: Not able to get list by getByTitle when list name contains spaces
SharePoint REST API: Not able to get list by getByTitle when list name contains spaces

Time:11-19

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

CodePudding user response:

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

http:(site URL)/_api/web/lists/getbytitle('TWO WORDS')/items
  • Related