Infinity Cliff
Infinity Cliff

Reputation: 354

Spotify Web API play endpoint - play track

I am trying to use the Spotify Web API to play a track when passed the track ID. I am using the PUT https://api.spotify.com/v1/me/player/play endpoint on Spotify's API Console here. When I use the sample data in the PUT Body, and add my Device ID and OAuth token abd click the try it button, the song starts to play. When I change the PUT Body to:

{
  "context_uri": "spotify:track:4ByEFOBuLXpCqvO1kw8Wdm"
}

I get the error:

HTTP/1.1 400 Bad Request
Content-Length: 99
Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE, PATCH
Access-Control-Max-Age: 604800
Access-Control-Allow-Credentials: true
Content-Encoding: gzip
Keep-Alive: timeout=600
Server: nginx
Connection: keep-alive
Cache-Control: private, max-age=0
Date: Wed, 31 Jan 2018 00:56:54 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Accept, Authorization, Origin, Content-Type, Retry-After
Content-Type: application/json; charset=utf-8

{
  "error" : {
    "status" : 400,
    "message" : "Non supported context uri"
  }
}

Any ideas on why it does not work?

Upvotes: 1

Views: 4635

Answers (2)

Infinity Cliff
Infinity Cliff

Reputation: 354

if you pass:

{
  "uris": ["spotify:track:4ByEFOBuLXpCqvO1kw8Wdm"]
}

it will work. You could also, then pass multiple songs in the uris list.

Upvotes: 4

Pankaj Gadge
Pankaj Gadge

Reputation: 2814

If you take a look at the Spotify's API, track is not supported in the context_uri.

Optional. Spotify URI of the context to play.
Valid contexts are albums, artists & playlists.
Example: {context_uri:"spotify:album:1Je1IMUlBXcx1Fz0WE7oPT"}

https://developer.spotify.com/web-api/start-a-users-playback/

Upvotes: 2

Related Questions