Announcements

Help Wizard

Step 1

NEXT STEP

Web API search with a query > 144 characters returns 404

Solved!

Web API search with a query > 144 characters returns 404

Plan: Premium


Hello, third party app developer here.

I hit a strange issue in development while searching for a very long track title.
It appears that there is a hard limit of 144 characters for the `q` query parameter in the Web API /search endpoint.

Sending a query with q >= 145 characters returns a 404, which  I found to be quite surprising.

If the query parameter is too long, I would expect the endpoint to return an appropriate error rather than a 404 status with a "Not Found" error.

Here is an example query that correctly returns a 200 response:
https://api.spotify.com/v1/search?type=track&q=This%20song%20does%20not%20exist%20i%20just%20want%20...

The same query with one additional character at the end returns a 404 response:
https://api.spotify.com/v1/search?type=track&q=This%20song%20does%20not%20exist%20i%20just%20want%20...

The error is as follows:
{
"error" : {
"status" : 404,
"message" : "Not found."
}
}

 

 

Reply

Accepted Solutions
Marked as solution

The search endpoint has a character limit of 100 characters. If you have any more than that, the endpoint will throw an exception.

View solution in original post

3 Replies
Marked as solution

The search endpoint has a character limit of 100 characters. If you have any more than that, the endpoint will throw an exception.

Thank you for the response Ximzend, and for confirming there is a limit to the query length.

As far as my testing went, the limit is 144 characters rather than 100.
I guess this should be added somewhere to the documentation of the endpoint to avoid bad surprises.

More preoccupying though is the fact that the endpoint does not return an expected error informing the user that the query is invalid, but rather returns a 404 as if the /search endpoint did not exist.

I've tried it this week and it seems to have been increased to 250 characters, send in a query of 251 characters and it returns a 400 error, 250 characters works fine though.

Suggested posts