// Authorization token that must have been created previously. See : https://developer.spotify.com/documentation/web-api/concepts/authorization const token = 'BQDDM9ajxK7-rMU6FUjFPEZpA_FSQ1ck0nJBR0MadPTbMxobyJmDC0WkLGvROI92JWARoKZ3Dw-PD4VF_mlpOghGOMrm_fjsBwVHVKIYyFN03-efuzA-cGoxY2j0scLJnqD29xdL8EZzuxE2L4NBWMGWWC0K1nbRXcfPiFaCbGBe1oURO8HR5loXTb48Fmk6RusDvA1ZTiquRvSNNo6wdc0kJiG-QsTJbCQc8sKeShUJPI0K16GeS8xYLxB8YaReObL8GfAC5SPCJRfRBa8U-UbB'; async function fetchWebApi(endpoint, method, body) { const res = await fetch(`https://api.spotify.com/${endpoint}`, { headers: { Authorization: `Bearer ${token}`, }, method, body:JSON.stringify(body) }); return await res.json(); } async function getTopTracks(){ // Endpoint reference : https://developer.spotify.com/documentation/web-api/reference/get-users-top-artists-and-tracks return (await fetchWebApi( 'v1/me/top/tracks?time_range=long_term&limit=5', 'GET' )).items; } const topTracks = await getTopTracks(); console.log( topTracks?.map( ({name, artists}) => `${name} by ${artists.map(artist => artist.name).join(', ')}` ) );