SpotifyAPI-NET
SpotifyAPI-NET copied to clipboard
SearchRequest breaks any request using "+"
tl;dr: + in search request turns into %2b, making spotify API not understand it properly.
Hello,
I'm trying to use this library for a simple Discord RPC project, and I noticed a very specific behavior.
Whenever I'm calling Search API, as documented on Spotify docs here, using additional query information, such as +artist:X
query automatically translates the plus into "htmlified" plus, namely %2b
.
Problem is, Spotify API itself does not understand such encoding, and instead of reacting to(example):
https://api.spotify.com/v1/search?type=album&limit=50&offset=0&query=Reprise+artist%3AFeint
throws an empty search result, because what actually library sends is:
https://api.spotify.com/v1/search?type=album&limit=50&offset=0&query=Reprise%2Bartist%3AFeint
.
This is the code that makes a request:
Here is the caught request in Visual Studio's diagnostic tools.
Proof that + and %2b are treated differently in Postman, both are using a fresh token to ensure API is not at fault:
Version with %2b
Version with +
Hi,
Thanks for the detailed report. It seems like even their web console doesnt support it correctly...
https://developer.spotify.com/console/get-search-item/?q=remaster%2520track%3ADoxy%2Bartist%3AMiles%2520Davis&type=track%2Cartist&market=ES&limit=10&offset=5&include_external=
Can you try replacing '+' with a normal space? It will get replaced by %20
, which the spotify API seems to understand. But not sure if the actual response data matches the query...maybe you can check that
Looking at the response in more detail, it seems like %20
is not treated correctly as a seperator...
I'm gonna check if we can disable +
encoding, as it's normally not necessary at all
Yeah, this is rather ridiculous... There is a reason why most people I know that work with this API aren't exactly in love with it. Sigh.
As to why I used plus - the aforementioned console had it as an example to make the queries more precise. Ironic.
In case of any further assistance being required I'll gladly help.
It seems to work well for me with a simple blank. However, I have a related question: How can I specify e.g. market, but also offset and limit, if at all?
You add it to the search request object:
const request = new SearchRequest(SearchRequest.Types.Album, "Muse");
request.Market = "DE";
request.Limit = 50;
request.Offset = 10;
// ...
Next time, please open a seperate discussion, thanks!
If I read the latest documentation correctly, they switched to using spaces (%20
) as separator. This should work correctly with our encoding. Let me know if it doesn't!