Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

Bug in Search API: Always returning null

Bug in Search API: Always returning null

Country

Germany

Operating System

Windows 10

 

My Question or Issue

Hello fellow developers,

 

I'm currently experiencing an issue with the /search endpoint in the API. My ultimate goal is to obtain the Spotify IDs for songs listed in the listening history JSON files (which only contain title and artist).

 

When GETting the endpoint with the required parameters I always get an empty response with this payload:

 

 

{\n  "tracks" : {\n    "href" : "https://api.spotify.com/v1/search?query=artist%3AKendrick%2520Lamar%2Btrack%3Agood%2520kid&type=track&offset=0&limit=20",\n    "items" : [ ],\n    "limit" : 20,\n    "next" : null,\n    "offset" : 0,\n    "previous" : null,\n    "total" : 0\n  }\n}

 

 

You can see the provided parameters in the URL, here are the required Auth headers for that request:

 

 

headers = {
        "Authorization" : f"Bearer {access}",
        "Accept" : "application/json",
        "Content-Type" : "application/json"
    }

 

 

The variable "access" is a valid access token acquired through the auth code flow, I have verified that it works through the get playlist items endpoint, which works flawlessly.

 

The same thing btw happens when using the official Spotify API console with a generated access token (see attached screenshot).

So in short, I'm reporting that the /search endpoint is not working for me, can others reproduce this?

 

My Python code:

 

 

def getSongId(access: str, title: str, artist: str):
    url = "https://api.spotify.com/v1/"
    endpoint = "search"
    data = {
        "q" : f"artist:{artist}+track:{title}",
        "type" : ["track"]
    }
    headers = {
        "Authorization" : f"Bearer {access}",
        "Accept" : "application/json",
        "Content-Type" : "application/json"
    }
    resp = requests.get(url=url+endpoint,params=data,headers=headers)
    print(resp.content)

 

 

PS: would there be another way to programmatically obtain Spotify IDs for songs of whom only title and artist are known when the /search endpoint turns out to be broken?

spotifyconsole.png
Reply
2 Replies

Just ran into the same issue. All you need to do is add the `market` parameter.

Actually the market parameter is not needed for Search, it will take the market from the user's token instead.  OP's issue is that he was using a plus (+) in his q string when it should have been a space.  You'll see if you search in the Spotify app for "artist:Kendrick Lamar+track:good kid" it will return nothing.

Suggested posts

Type a product name