Announcements

Help Wizard

Step 1

NEXT STEP

401 error for GET search request but not other GET requests?

Solved!

401 error for GET search request but not other GET requests?

I have previously had no issues with GET requests from /v1/playlists/<playlist-id> or /v1/playlists/<playlist-id>/tracks endpoints, but now I can't seem to GET from a search endpoint. I have the following code snippet for a GET search request:

 

 

var responseApi = await fetch('https://api.spotify.com/v1/search?q=' + query + '&type=track', {
    'Authorization': 'Bearer ' + token
  });

 

 

token is defined prior and works for other GET requests.

query could be something like "artist:The Weeknd track:Blinding Lights". I've tried passing the query through encodeURIComponent() as well without luck.

 

Have I made a syntax error? Any tips are appreciated.

Reply

Accepted Solutions
Marked as solution

Update: I spotted my mistake. I was missing {headers:}.

var responseApi = await fetch('https://api.spotify.com/v1/search?q=' + query + '&type=track', {
  headers: {
    'Authorization': 'Bearer ' + token
  }});

 

View solution in original post

1 Reply
Marked as solution

Update: I spotted my mistake. I was missing {headers:}.

var responseApi = await fetch('https://api.spotify.com/v1/search?q=' + query + '&type=track', {
  headers: {
    'Authorization': 'Bearer ' + token
  }});

 

Suggested posts

Let's introduce ourselves!

Hey there you,   Yeah, you! 😁   Welcome - we're glad you joined the Spotify Community!   While you here, let's have a fun game and get…

ModeratorStaff / Moderator/ 4 years ago  in Social & Random