Missing endpoint: get-playlist-cover
Seems to be a missing endpoint/function, unless I just missed it? get-playlist-cover doesn't seem to be implemented...
https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlist-cover/
Well I'll be damned.. You're right. Feel free to implement it @TheBrenny. (Or I will when I get around to it.)
Might be very Stupid to ask this:
Created this In spotify-web-api.js
getPlaylistCover: function (playlistId , callback) {
return WebApiRequest.builder(this.getAccessToken())
.withPath("/v1/playlists/"+playlistId +"/images")
.build()
.execute(HttpManager.get, callback);
}
in a different file with token setup
const getPlaylistCoverFunc = async (id) => {
const data = await spotifyApi.getPlaylistCover('2PmTicZwgLrfB1M3SIYQlq');
console.log(data);
};
getPlaylistCoverFunc();
returns :
{
body: {},
headers: {
'cache-control': 'private, max-age=0',
'x-robots-tag': 'noindex, nofollow',
'access-control-allow-origin': '*',
'access-control-allow-headers': 'Accept, App-Platform, Authorization, Content-Type, Origin, Retry-After, Spotify-App-Version, X-Cloud-Trace-Context, client-token, content-access-token',
'access-control-allow-methods': 'GET, POST, OPTIONS, PUT, DELETE, PATCH',
'access-control-allow-credentials': 'true',
'access-control-max-age': '604800',
'content-encoding': 'gzip',
'strict-transport-security': 'max-age=31536000',
'x-content-type-options': 'nosniff',
date: 'Sun, 14 Feb 2021 09:16:34 GMT',
server: 'envoy',
via: 'HTTP/2 edgeproxy, 1.1 google',
'alt-svc': 'clear',
connection: 'close',
'transfer-encoding': 'chunked'
},
statusCode: 200
}
Why is body returned as an Empty Object ?
Should ideally return this:
[
{
"height": 640,
"url": "https://mosaic.scdn.co/640/ab67616d0000b2730ac4a3584ddda0528af9ec17ab67616d0000b2731555fec10000486f9331fbc8ab67616d0000b2739701faf1c34cc355fd3cd3c0ab67616d0000b273d2be316742edcc853ea55141",
"width": 640
},
{
"height": 300,
"url": "https://mosaic.scdn.co/300/ab67616d0000b2730ac4a3584ddda0528af9ec17ab67616d0000b2731555fec10000486f9331fbc8ab67616d0000b2739701faf1c34cc355fd3cd3c0ab67616d0000b273d2be316742edcc853ea55141",
"width": 300
},
{
"height": 60,
"url": "https://mosaic.scdn.co/60/ab67616d0000b2730ac4a3584ddda0528af9ec17ab67616d0000b2731555fec10000486f9331fbc8ab67616d0000b2739701faf1c34cc355fd3cd3c0ab67616d0000b273d2be316742edcc853ea55141",
"width": 60
}
]
I believe it's because the API is not sending back any Content-Type in its response header, in which case superagent is not able to parse it.
const fetch = require('node-fetch');
let data = fetch(
'https://api.spotify.com/v1/playlists/37i9dQZF1EMcPEQyqIIrLr/images',
{
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization:
'Bearer <AuthToken>',
},
}
)
.then((res) => res.text())
.then((body) => console.log(body));
Output:
[ {
"height" : null,
"url" : "https://lineup-images.scdn.co/wrapped-2020-top100_LARGE-en.jpg",
"width" : null
} ]
This doesn't works.
getPlaylistCover: function (playlistId, callback) {
return WebApiRequest.builder(this.getAccessToken())
.withPath('/v1/playlists/' + playlistId + '/images')
.withHeaders({ 'Content-Type': 'application/json' , 'Accept': 'application/json', })
.build()
.execute(HttpManager.get, callback);
},
Adding Headers still give Empty Object as Response
Yes because in the second case you would still be using superagent. The issue is not with the request headers but the response.
Having another dependency just for this call may not be ideal but a workaround could be reusing getPlaylist (if consistency is not a big concern):
getPlaylistCover: function(playlistId, callback) {
if (!callback) return this.getPlaylist(playlistId).then((data) => data.body.images);
return this.getPlaylist(playlistId, '_', (err, data) => callback(data.body.images));
}