I am trying to connect to a SharePoint URL and pull the data in the form of a .json file. My URL looks like this:

.../_api/web/lists/GetByTitle('titles list')/items

If I give the URL as it is without any encoding, it fails with a HTTP/1.1 400 Bad Request error. I tried using -G and --data-urlencode as follows:

curl -v -G -L --ntlm --user user:password -H 'Accept: application/json;odata=verbose' ".../_api/web/lists/GetByTitle" --data-urlencode "('titles list')" -d "/items"

Doing this converts my URL to .../_api/web/lists/GetByTitle?%28%27titles%20list%27%29&/items

But it fails with HTTP/1.1 404 Not Found since using -G will append a ? and & to the URL. Having the ? and & present will give me a different URL and hence the 404 not found error.

I have no issues accessing other end points such as ../_api/web/lists since - I believe - there is no need to encode this URL?

How do I properly encode my URL and get the data without any errors?


I was able to solve the issue by directly using encoded characters in the URL of the cURL command.

Here is an example:

curl -v -L --ntlm --user user:password -H 'Accept: application/json;odata=verbose' ".../_api/web/lists/GetByTitle%28%27titles%20list%27%29/items"

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.