User Saved Albums and Album's Information
Learn to get the albums saved in a user profile and information about any album using the Spotify API.
Overview
Spotify provides an endpoint that fetches a list of albums saved in a user profile. We can then get further information about these albums using the Get Albums endpoint. In this lesson, we'll look at these two endpoints.
The base URL https://api.spotify.com/v1/me/albums
is used to get information about the albums saved in the current user’s profile. We used this endpoint to save and remove albums from a user profile using PUT
and DELETE
requests respectively. Now, we’ll send a GET
request to this endpoint to get a list of the albums saved in the user’s profile.
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 | String | 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 |
| Optional | Integer | This parameter can be used to offset the first item we get in response. |
Get a list of user's saved albums
Let's look at how this endpoint is used to get a list of albums saved in a user profile.
url = 'https://api.spotify.com/v1/me/albums'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))
Try using the query parameters to filter the response.
Response fields
The response of this endpoint contains the following information:
Response field | Type | Description |
| String |
|
| Array of objects | This is an external link which can be used to open this album on Spotify. |
| String | This is the release date of the album. |
| Integer | This index shows how popular an album is on Spotify. It ranges from |
| Array of objects | This array contains information about the tracks in the album. |
| Array of objects | This array contains cover images of the albums. |
| String | This is the Spotify ID of the album. |
| Array of objects | This contains the information about the copyrights of the album. |
| Array of objects | This array contains the information about the artists who performed in this album. |
We can use the information we collect from this endpoint as a seed to display the content that the user enjoys.
The base URL https://api.spotify.com/v1/albums/{id}
is used to get information about an album. The path parameter {id}
is replaced with the ID of the album we want to get information about. So if we want to get information about an album whose Spotify ID is sample_id
, the URL will be https://api.spotify.com/v1/albums/sample_id
.
Request parameters
The information obtained by calling this endpoint can be filtered using the following query parameter:
Query parameter | Category | Type | Description |
| Optional | String | 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 |
Get information about an album
Let's look at the detailed information of Bruno Mars' album Doo-Wops & Hooligan.
url = 'https://api.spotify.com/v1/albums/1uyf3l2d4XYwiEqAb7t7fX'#1uyf3l2d4XYwiEqAb7t7fX is the ID of Bruno Mars's album Doo-Wops And Hooligansheaders = {'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 in line 1 to get information about a different album. The Spotify IDs of some albums are listed below:
Album | Spotify ID |
Bring It On |
|
The Eminem Show (Expanded Edition) |
|
The Lion King: The Gift [Deluxe Edition] |
|
Mercury - Act 1 |
|
Dylan & Cash - Two Rebels |
|
Note: We can use the Search for Item endpoint to get Spotify IDs of albums using their names.
We can also use the market
query parameter to filter the content based on its availability in a specific country.
Note: This endpoint's response changes if we use the authorization code access token for authentication when making an API call. It will only return the content available in the country associated with our Spotify ID in response.
Response fields
The response of this endpoint will contain the following information:
Response field | Type | Description |
| String | This is the name of the album. |
| Array of objects | This is the link to this album on Spotify. |
| String | This is the release date of the album. |
| Integer | This is the popularity index of the album. It ranges from |
| Integer | This is the number of tracks in the album. |
| Array of objects | This array contains information about the tracks in the album. |
| Array of objects | This array contains the ISO 3166-1 alpha-2 country code of the markets where this album is available on Spotify. |