Announcements

Help Wizard

Step 1

NEXT STEP

Getting Error 500 while trying to add items to a playlist.

Getting Error 500 while trying to add items to a playlist.

Plan

Premium

Country

Spain (ES)

Device

Desktop computer

Operating System

Linux mint 20.2

 

My Question or Issue

I was trying to add some tracks to one of my playlists, and I keep getting the following error response:

{"error": {"status": 500, "message": "com.schibsted.spt.data.jslt.JsltException: For loop can't iterate over "uris=spotify:track:5yj8QDJ967St7PUG7sFD0n,spotify:track:7ppZPegqYaJszeylK41PfR" at <unknown>:18:7" } }

Here is the code that calls the API:

export async function addItemsToPlaylist(accessToken, userId, playlistId, uris) {
const formattedUris = "uris=" + uris.split(',').map(id => `spotify:track:${id}`);
console.log(formattedUris)

const response = await fetch(`https://api.spotify.com/v1/playlists/${playlistId}/tracks`, {
method: 'POST',
headers: {
Authorization: 'Bearer ' + accessToken,
'Content-Type': 'application/json'
},
body: JSON.stringify({
uris: formattedUris,
})
});
if (!response.ok) {
console.log( await response.text())
throw new Error("Error! Could not add items to playlist: " + await response.text())
}
return await response.json();
}

Is something wrong with the treatment of the IDs? How can I fix the error?

Reply
0 Replies

Suggested posts

Let's introduce ourselves!

Hey there you,   Yeah, you! 😁   Welcome - we're glad you joined the Spotify Community!   While you here, let's have a fun game and get…

ModeratorStaff / Moderator/ 4 years ago  in Social & Random