Affinity is a measure of the expected preference a user has for a particular track or artist.  It is based on user behavior, including play history, but does not include actions made while in incognito mode. Light or infrequent users of Spotify may not have sufficient play history to generate a full affinity data set.

As a user’s behavior is likely to shift over time, this preference data is available over three time spans. See time_range in the query parameter table for more information.

For each time range, the top 50 tracks and artists are available for each user. In the future, it is likely that this restriction will be relaxed. This data is typically updated once each day for each user.

Endpoint

GET https://api.spotify.com/v1/me/top/{type}

Request Parameters

Path Parameters

Path Parameter Value
type The type of entity to return. Valid values: artists or tracks.

Header Fields

Header Field Value
Authorization Required. A valid access token from the Spotify Accounts service: see the Web API Authorization Guide for details. The access token must have been issued on behalf of the current user.
Getting details of a user’s top artists and tracks requires authorization of the user-top-read scope. See Using Scopes.

Query Parameters

Query Parameter Value
limit Optional. The number of entities to return. Default: 20. Minimum: 1. Maximum: 50. For example: limit=2
offset Optional. The index of the first entity to return. Default: 0 (i.e., the first track). Use with limit to get the next set of entities.
time_range Optional. Over what time frame the affinities are computed. Valid values: long_term (calculated from several years of data and including all new data as it becomes available), medium_term (approximately last 6 months), short_term (approximately last 4 weeks). Default: medium_term.

Response Format

On success, the HTTP status code in the response header is 200 OK and the response body contains a paging object of Artists or Tracks. On error, the header status code is an error code and the response body contains an error object.

Examples

Get the current user’s top artists

curl -X GET "https://api.spotify.com/v1/me/top/artists" -H "Authorization: Bearer {your access token}"
{
  "items" : [ {
    "external_urls" : {
      "spotify" : "https://open.spotify.com/artist/0I2XqVXqHScXjHhk6AYYRe"
    },
    "followers" : {
      "href" : null,
      "total" : 7753
    },
    "genres" : [ "swedish hip hop" ],
    "href" : "https://api.spotify.com/v1/artists/0I2XqVXqHScXjHhk6AYYRe",
    "id" : "0I2XqVXqHScXjHhk6AYYRe",
    "images" : [ {
      "height" : 640,
      "url" : "https://i.scdn.co/image/2c8c0cea05bf3d3c070b7498d8d0b957c4cdec20",
      "width" : 640
    }, {
      "height" : 300,
      "url" : "https://i.scdn.co/image/394302b42c4b894786943e028cdd46d7baaa29b7",
      "width" : 300
    }, {
      "height" : 64,
      "url" : "https://i.scdn.co/image/ca9df7225ade6e5dfc62e7076709ca3409a7cbbf",
      "width" : 64
    } ],
    "name" : "Afasi & Filthy",
    "popularity" : 54,
    "type" : "artist",
    "uri" : "spotify:artist:0I2XqVXqHScXjHhk6AYYRe"
  },{
   ...
  }],
  "next" : "https://api.spotify.com/v1/me/top/artists?offset=20",
  "previous" : null,
  "total" : 50,
  "limit" : 20,
  "href" : "https://api.spotify.com/v1/me/top/artists"
}

Try it

artist (full)

Key Value Type Value Description
external_urls an external URL object Known external URLs for this artist.
followers A followers object Information about the followers of the artist.
genres array of strings A list of the genres the artist is associated with. For example: "Prog Rock" , "Post-Grunge". (If not yet classified, the array is empty.)
href string A link to the Web API endpoint providing full details of the artist.
id string The Spotify ID for the artist.
images array of image objects Images of the artist in various sizes, widest first.
name string The name of the artist
popularity int The popularity of the artist. The value will be between 0 and 100, with 100 being the most popular. The artist’s popularity is calculated from the popularity of all the artist’s tracks.
type string The object type: "artist"
uri string The Spotify URI for the artist.

track (full)

Key Value Type Value Description
album a simplified album object The album on which the track appears. The album object includes a link in href to full information about the album.
artists an array of simplified artist objects The artists who performed the track. Each artist object includes a link in href to more detailed information about the artist.
available_markets array of strings A list of the countries in which the track can be played, identified by their ISO 3166-1 alpha-2 code.
disc_number integer The disc number (usually 1 unless the album consists of more than one disc).
duration_ms integer The track length in milliseconds.
explicit Boolean Whether or not the track has explicit lyrics ( true = yes it does; false = no it does not OR unknown).
external_ids an external ID object Known external IDs for the track.
external_urls an external URL object Known external URLs for this track.
href string A link to the Web API endpoint providing full details of the track.
id string The Spotify ID for the track.
is_playable boolean Part of the response when Track Relinking is applied. If true , the track is playable in the given market. Otherwise false.
linked_from a linked track object Part of the response when Track Relinking is applied, and the requested track has been replaced with different track. The track in the linked_from object contains information about the originally requested track.
name string The name of the track.
popularity integer The popularity of the track. The value will be between 0 and 100, with 100 being the most popular.
The popularity of a track is a value between 0 and 100, with 100 being the most popular. The popularity is calculated by algorithm and is based, in the most part, on the total number of plays the track has had and how recent those plays are.
Generally speaking, songs that are being played a lot now will have a higher popularity than songs that were played a lot in the past. Duplicate tracks (e.g. the same track from a single and an album) are rated independently. Artist and album popularity is derived mathematically from track popularity. Note that the popularity value may lag actual popularity by a few days: the value is not updated in real time.
preview_url string A link to a 30 second preview (MP3 format) of the track. Can be null
track_number integer The number of the track. If an album has several discs, the track number is the number on the specified disc.
type string The object type: “track”.
uri string The Spotify URI for the track.

paging object

Key Value Type Value Description
href string A link to the Web API endpoint returning the full result of the request.
items an array of objects The requested data.
limit integer The maximum number of items in the response (as set in the query or by default).
next string URL to the next page of items. ( null if none)
offset integer The offset of the items returned (as set in the query or by default).
previous string URL to the previous page of items. ( null if none)
total integer The total number of items available to return.