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

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.

market

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 us for the United States, es for Spain, and fr for France.

offset

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.

Press + to interact
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

name

String

name in the items array is the name of the album.

spotify

Array of objects

This is an external link which can be used to open this album on Spotify.

release_date

String

This is the release date of the album.

popularity

Integer

This index shows how popular an album is on Spotify. It ranges from 0 to 100 with 100 being the most popular.

tracks

Array of objects

This array contains information about the tracks in the album.

images

Array of objects

This array contains cover images of the albums.

id

String

This is the Spotify ID of the album.

copyrights

Array of objects

This contains the information about the copyrights of the album.

artists

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

market

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 us for the United States, es for Spain, and fr for France. If we send an auth code access token in the request header, the user's country will take priority over the country specified in this parameter.

Let's look at the detailed information of Bruno Mars' album Doo-Wops & Hooligan.

Press + to interact
const endpointUrl = new URL('https://api.spotify.com/v1/albums/1uyf3l2d4XYwiEqAb7t7fX');
//1uyf3l2d4XYwiEqAb7t7fX is the ID of Bruno Mars's album Doo-Wops And Hooligans
headerParameters = {
'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

2GeLoefQqCOmRlNhVFCKg4

The Eminem Show (Expanded Edition)

6EzbFdrwvWpnpUjzrR57aU

The Lion King: The Gift [Deluxe Edition]

7kUuNU2LRmr9XbwLHXU9UZ

Mercury - Act 1

4fZIyJn2wKb51QPNnWYnqt

Dylan & Cash - Two Rebels

6umM3iXwTn3vmrTPL4QBzQ

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

name

String

This is the name of the album.

spotify

Array of objects

This is the link to this album on Spotify.

release_date

String

This is the release date of the album.

popularity

Integer

This is the popularity index of the album. It ranges from 0 to 100 with 100 being the most popular.

total_tracks

Integer

This is the number of tracks in the album.

tracks

Array of objects

This array contains information about the tracks in the album.

available_market

Array of objects

This array contains the ISO 3166-1 alpha-2 country code of the markets where this album is available on Spotify.