Skip to content

Get Last Listened Tracks

To display the user’s last listened tracks, you can use the getLastListenedTracks method. This method returns an array of the user’s last listened tracks.

async function getLastListenedTracks(userId, amount){
try {
const tracks = await vibify.getLastListenedTracks(userId, amount);
console.log('Last Listened Tracks:', tracks);
} catch (error) {
console.error('Error:', error);
}
}
getLastListenedTracks('user-id', 1);

Or with cURL:

Terminal window
curl -H "x-api-key: (your api key)" "http://localhost:3000/recently-played/(user-id)?amount=1"

Returns

{
"items":[
{
"track":{
"album":{
"album_type":"album",
"total_tracks":12,
"available_markets":[
"AR",
"AU",
"..."
],
"external_urls":{
"spotify":"https://open.spotify.com/album/2ViqUaFAwiL0ILIr7eexgl"
},
"href":"https://api.spotify.com/v1/albums/2ViqUaFAwiL0ILIr7eexgl",
"id":"2ViqUaFAwiL0ILIr7eexgl",
"images":[
{
"url":"https://i.scdn.co/image/ab67616d0000b2735fe4aed1ea5a0bf343cf7283",
"height":640,
"width":640
},
{
"url":"https://i.scdn.co/image/ab67616d00001e025fe4aed1ea5a0bf343cf7283",
"height":300,
"width":300
},
{
"url":"https://i.scdn.co/image/ab67616d000048515fe4aed1ea5a0bf343cf7283",
"height":64,
"width":64
}
],
"name":"Like Vines",
"release_date":"2006-06-06",
"release_date_precision":"day",
"type":"album",
"uri":"spotify:album:2ViqUaFAwiL0ILIr7eexgl",
"artists":[
{
"external_urls":{
"spotify":"https://open.spotify.com/artist/1RCoE2Dq19lePKhPzt9vM5"
},
"href":"https://api.spotify.com/v1/artists/1RCoE2Dq19lePKhPzt9vM5",
"id":"1RCoE2Dq19lePKhPzt9vM5",
"name":"The Hush Sound",
"type":"artist",
"uri":"spotify:artist:1RCoE2Dq19lePKhPzt9vM5"
}
]
},
"artists":[
{
"external_urls":{
"spotify":"https://open.spotify.com/artist/1RCoE2Dq19lePKhPzt9vM5"
},
"href":"https://api.spotify.com/v1/artists/1RCoE2Dq19lePKhPzt9vM5",
"id":"1RCoE2Dq19lePKhPzt9vM5",
"name":"The Hush Sound",
"type":"artist",
"uri":"spotify:artist:1RCoE2Dq19lePKhPzt9vM5"
}
],
"available_markets":[
"AR",
"AU",
"..."
],
"disc_number":1,
"duration_ms":154173,
"explicit":false,
"external_ids":{
"isrc":"USAT21101922"
},
"external_urls":{
"spotify":"https://open.spotify.com/track/7puGwAJbm1hhbSkKVrvrdT"
},
"href":"https://api.spotify.com/v1/tracks/7puGwAJbm1hhbSkKVrvrdT",
"id":"7puGwAJbm1hhbSkKVrvrdT",
"name":"Wine Red",
"popularity":51,
"preview_url":"https://p.scdn.co/mp3-preview/f24eeb69663999e98993362e161d8e3f19a00e8b?cid=bd747a3119c04456abd0edfac3d9d42c",
"track_number":9,
"type":"track",
"uri":"spotify:track:7puGwAJbm1hhbSkKVrvrdT",
"is_local":false
},
"played_at":"2024-02-19T13:18:40.613Z",
"context":null
}
]
}