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.
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. |
Let's look at how this endpoint is used to get a list of albums saved in a user profile.
const endpointUrl = new URL('https://api.spotify.com/v1/me/albums');headerParameters = {'Content-Type': 'application/json','Authorization': 'Bearer {{AUTHORIZATION_CODE_ACCESS_TOKEN}}'}const options = {method: 'GET',headers: headerParameters};async function fetchSavedAlbums() {try {const response = await fetch(endpointUrl, options);printResponse(response);}catch (error) {printError(error);}}fetchSavedAlbums();
Let's look at our code:
Lines 1–6: We define the URL and the header parameters.
Lines 8–11: We set the request type and the header.
Lines 13–22: We define a function named
fetchSavedAlbums()
. In this function, we call the endpoint in line 15 and print the response in line 17.
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 |
Let's look at the detailed information of Bruno Mars' album Doo-Wops & Hooligan.
const endpointUrl = new URL('https://api.spotify.com/v1/albums/1uyf3l2d4XYwiEqAb7t7fX');//1uyf3l2d4XYwiEqAb7t7fX is the ID of Bruno Mars's album Doo-Wops And HooligansheaderParameters = {'Content-Type': 'application/json','Authorization': 'Bearer {{CLIENT_CREDENTIALS_ACCESS_TOKEN}}'}const options = {method: 'GET',headers: headerParameters};async function fetchAlbumInfo() {try {const response = await fetch(endpointUrl, options);printResponse(response);}catch (error) {printError(error);}}fetchAlbumInfo();
Let's look at how we modified our code:
Line 1: We change the URL to
https://api.spotify.com/v1/albums/1uyf3l2d4XYwiEqAb7t7fX
.Line 6: We change the type of access token. Unlike in the previous code widget, we use the client credentials access token here.
Line 14: We change the function's name to
fetchAlbumInfo()
.
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. |