User Playlists and Playlist Information

Overview

Spotify provides an endpoint that is used to get the list of playlists owned or followed by the current user. We can then get information about these playlists using the Get Playlist endpoint.

Playlists owned or followed by the current user

The base URL https://api.spotify.com/v1/me/playlists is used to get information about these playlists. This can help us analyze what kind of content a user is interested in. We can then suggest similar content to the user.

Request parameters

The information obtained by calling this endpoint can be filtered using the following query parameters.

Query parameter

Category

Type

Description

limit

Optional

Integer

This limits the number of items to be returned in the response. Its value ranges from 0 to 50 and the default value is 20.

offset

Optional

Integer

This parameter can be used to offset the first item we get in response.

Get a list of user's playlists

Let's see how we can use this endpoint to get the information about a playlist in the code widget below:

Press + to interact
url = 'https://api.spotify.com/v1/me/playlists'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer {{AUTHORIZATION_CODE_ACCESS_TOKEN}}'
}
response = requests.request("GET", url, headers=headers)
print(json.dumps(response.json(), indent=4))

We'll get a list of playlists in response. We're extracting the ID of the first playlist to use it with the second endpoint that we'll discuss in this lesson.

Try limiting the number of playlists we get in response by using the query parameter limit.  For example, for only ten playlists to appear in the result, append ?limit=10 to the base URI in line 1. This will limit the output to ten playlists.

Response fields

The response of this endpoint contains the following information:

Response field

Type

Description

description

String

This is the description of the playlist written by its owner.

owner

Array of objects

This contains information about the owner of the playlist.

tracks

Array of objects

This contains information about the tracks in the playlist.

images

Array of objects

This contains the link for the cover image of the playlist and its dimensions.

id

String

This is the ID of the playlist.

name

String

This is the name of the playlist.

Playlist details

The Get Playlist endpoint is used to retrieve information about a playlist using its Spotify ID. Its base URI is https://api.spotify.com/v1/playlist/{id}. The path parameter {id} is replaced with the playlist ID when making an API call. Let's assume that we want to get information for a playlist with Spotify ID sample_id. Our URL, in this case, will be https://api.spotify.com/v1/artists/sample_id.

Request parameters

The information obtained by calling this endpoint can be filtered using the following query parameters.

Query parameter

Category

Type

Description

additional_types

Optional

String

This contains the types of items, separated by commas, that the user's subscription allows to access. Its possible values are tracks and episodes. Its default value is tracks.

fields

Optional

String

This contains the list of fields that the user wants in response, separated by commas.

market

Optional

String

This is an ISO 3166-1 alpha-2 country code that can be used to filter the content available in a country. In case we send an auth token in the request header, the user's country will take priority over the country specified in this parameter.

Get playlist's information

Let's look at how to use this endpoint to get the information about a playlist.

Press + to interact
url = 'https://api.spotify.com/v1/playlists/{{PLAYLIST_ID}}'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer {{CLIENT_CREDENTIALS_ACCESS_TOKEN}}'
}
response = requests.request("GET", url, headers=headers)
print(json.dumps(response.json(), indent=4))

Try changing the playlist ID in line 1 to get information about any other Spotify playlist.

Note: The playlist’s ID can be obtained using the Search for Item endpoint.

Response fields

The response data returned by this endpoint contains the following important information:

Response field

Type

Description

description

String

This is the desciption of the playlist that the creator wrote.

public

Boolean

This shows whether the playlist is public or not.

owner

Array of objects

This array contains the information of the owner.

tracks

Array of objects

This contains the information of the tracks in the playlist.

followers

Array of objects

This contains the information about the followers of the playlist.

images

String

This is the link to the cover of the playlist.

name

String

This is the title of the playlist.