User Saved Tracks and Track Information
Learn how to get information about the tracks saved by the user on Spotify using the Spotify API.
Overview
In this lesson, we'll look at how we can get a list of tracks and their details that are saved in a user profile.
We can get information about a user’s taste in music using the Get User’s Saved Tracks endpoint. The base URL https://api.spotify.com/v1/me/tracks
provides a list of tracks saved in the current user profile. We have already used PUT
and DELETE
requests with this endpoint to save and remove tracks from a user profile, respectively. Now, we’ll use the GET
request to fetch the list of tracks saved in a user profile.
Request parameters
The information obtained by calling this endpoint can be filtered using the following query parameters.
Query parameter | Type | Category | Description |
| Integer | Optional | This limits the number of items to be returned in the response. Its value ranges from |
| String | Optional | This is an ISO 3166-1 alpha-2 country code that we can use to fetch only the content available in a specific country. Some examples of country codes are |
| Integer | Optional | This parameter can be used to offset the first item we get in response. |
Get a list of tracks saved in the user's profile
The code below demonstrates how to get the saved tracks from a user profile with the authorization access token.
url = "https://api.spotify.com/v1/me/tracks"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))
Save the ID of the first track, which is automatically extracted from the response to use it further in this lesson.
Response fields
The table below contains the important fields that we get in response to an API call to this endpoint.
Response field | Type | Description |
| Array | This array contains the information about the album of the track saved in the user's profile. |
| String | This is the name of the track. |
| String | This is the link to the Spotify page of the item. |
| String | This shows how popular a track is. It ranges from |
| String | This is the URL for a 30 seconds preview of the track. |
| Array | This array contains the information about the artists of the track saved in the user's profile. |
| String | This is the Spotify ID of the track. |
| Array | This is the list of markets in which the track is available. |
| String | This contains the date and time at which the tracks was saved by the user. |
The Get Track endpoint is used to get information about a track. The base URI of this endpoint is https://api.spotify.com/v1/tracks/{id}
. The path parameter {id}
is replaced with the ID of the track we want to get. So if we want to fetch a track whose Spotify ID is sample_id
, the URL will be https://api.spotify.com/v1/tracks/sample_id
.
Request parameters
The information obtained by calling this endpoint can be filtered using the following query parameters.
Query parameter | Type | Category | Description |
| String | Optional | This is an ISO 3166-1 alpha-2 country code that we can use to fetch only the content available in a specific country. Some examples of country codes are |
Retrieve details of a track
Let's look at how to use this endpoint to get the information of a track. We're getting the information about the track whose ID was saved in the previous executable.
url = "https://api.spotify.com/v1/tracks/{{TRACK_ID}}"#11dFghVXANMlKmJXsNCbNl is the Spotify ID of the song Cut To The Feelingheaders = {'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 id of the track in line 1 to get information for a different track. Here are some track IDs:
Track | Spotify ID |
Love Without Question |
|
Without Me |
|
Perfect Duet |
|
Bones |
|
Highwayman |
|
Response fields
The response of this endpoint contains the following information:
Response field | Type | Description |
| Array | This contains the information about the album of the track. |
| String | This is the name of the track. |
| String | This contains the links for the tracks of the artist. |
| Integer | This index defines how popular a track is on Spotify. It ranges from |
| String | This is the link to a 30 seconds preview of the track. It may be |