Add Tracks To Playlist API Error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey guys, I've been working on a project, and within it, I have to add tracks to a freshly created playlist. When I do it, I get a 201 response and a snapshot ID, indicating a successful request. But when I check the actual playlist, nothing has been added to the track. I can't get it to work in Javascript or Python.
Does anyone know what the cause might be? I made sure my URIs are correctly formatted, and I'm authenticated with the proper scope. I have provided a piece of the code below if it helps.
function addTracksToPlaylist(playlistId, trackUris, token) {
//use a batchSize of 90 to avoid errors with too long strings
const batchSize = 90;
// Split trackUris into batches of batchSize
for (let i = 0; i < trackUris.length; i += batchSize) {
const batch = trackUris.slice(i, i + batchSize);
// Make the POST request using fetch for each batch
fetch(url, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ uris: batch })
})
.then(response => response.json())
.then(result => {
if (result.snapshot_id) {
console.log('Batch added successfully:', result);
} else {
console.error('Error adding batch:', result);
}
})
.catch(error => console.error('Error:', error));
}
}
Labels:
- Labels:
-
api
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page