User Playlists and Playlist Information
Take a look at how to get information about the playlists the current user is interested in.
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 |
| Optional | Integer | This limits the number of items to be returned in the response. Its value ranges from |
| 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:
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 |
| String | This is the description of the playlist written by its owner. |
| Array of objects | This contains information about the owner of the playlist. |
| Array of objects | This contains information about the tracks in the playlist. |
| Array of objects | This contains the link for the cover image of the playlist and its dimensions. |
| String | This is the ID of the playlist. |
| 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 |
| Optional | String | This contains the types of items, separated by commas, that the user's subscription allows to access. Its possible values are |
| Optional | String | This contains the list of fields that the user wants in response, separated by commas. |
| 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.
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 |
| String | This is the desciption of the playlist that the creator wrote. |
| Boolean | This shows whether the playlist is public or not. |
| Array of objects | This array contains the information of the owner. |
| Array of objects | This contains the information of the tracks in the playlist. |
| Array of objects | This contains the information about the followers of the playlist. |
| String | This is the link to the cover of the playlist. |
| String | This is the title of the playlist. |