Artist’s Albums
Search for albums of an artist using the Spotify ID of the artist.
We'll cover the following
Everyone has a favorite musician to whom they can listen endlessly. No matter which valley we wander off to, we do always end up circling back to the same artist.
The Get Artist’s Albums endpoint can help us get our favorite artists’ albums.
The base URL https://api.spotify.com/v1/artists/{id}/albums
is used to get information about the albums of an artist. The path parameter {id}
is replaced with the artist’s ID whose albums we want to fetch. So if we’re going to fetch albums of an artist whose Spotify ID is sample_id
, the URL will be https://api.spotify.com/v1/artists/sample_id/albums
.
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 can be used to filter the albums based on the artist's involvement in the album. The possible values for We can also assign multiple values to this parameter by separating those values using a comma (,). |
| 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 see how we can use this endpoint to get an artist's albums.
const endpointUrl = new URL('https://api.spotify.com/v1/artists/0TnOYISbd1XYRBk9myaseg/albums');//0TnOYISbd1XYRBk9myaseg is the ID of Pitbull a.k.a. Mr. WorldwideheaderParameters = {'Content-Type': 'application/json','Authorization': 'Bearer {{CLIENT_CREDENTIALS_ACCESS_TOKEN}}'}const options = {method: 'GET',headers: headerParameters};async function fetchAlbum() {try {const response = await fetch(endpointUrl, options);printResponse(response);}catch (error) {printError(error);}}fetchAlbum();
Let's look at the code explanation:
Line 1: We set the URL to
https://api.spotify.com/v1/artists/0TnOYISbd1XYRBk9myaseg/albums
. We can change the Spotify ID to get the albums of another artist.Lines 14–23: We define a function named
fetchAlbum()
. This function calls the defined endpoint and prints the response.
Note: We can use the Search for Item endpoint to get the Spotify ID of an artist.
We can filter the results we got above by using some query parameters. For example, try to fetch only the solo albums of an artist. For this, we need to append the following query parameter to URL
: ?include_groups=single
.
Response fields
Some important response fields are given in the table below:
Response field | Type | Description |
| String |
|
| Array | This is an external link which can be used to open this album on Spotify. |
| String | This is the release date of the album. |
| Array of objects | This array contains information about the artist. |
| Array of objects | This array contains cover images of the albums. |
| String | This is the Spotify ID of the album. |
| Array of objects | This array contains the ISO 3166-1 alpha-2 country code of the countries in which this album is available. |
| Integer | This tells us the total number of albums that we get in response. |