Hey there,
I was working on POST request which would create new playlist. I have a weird to me error which I tried to google and find a solution but I think I do not understand it properly. Below is the method in which when i try to use “name” like this “body: JSON.stringify({ name: name })” react fails to compile.
I don’t get what am i supposed to replace “name” with since it is appreciated by JS in general. In the video tutorial mentor uses exactly body: JSON.stringify({ name: name })".
PLease advice. I’m stuck again.
savePlaylist(playListName, arrayOfTrackURI) {
if (!playListName || !arrayOfTrackURI.length) {
return;
}
const accessToken = Spotify.getAccessToken();
const headers = { Authorization: `Bearer ${accessToken}` };
let userId;
return fetch("https://api.spotify.com/v1/me", { headers: headers }).then(
(resp) =>
resp.json().then((jsonResp) => {
userId = jsonResp.id;
return fetch(`https://api.spotify.com/v1/users/${userId}/playlists`, {
headers: headers,
method: "POST",
body: JSON.stringify({ name: name }),
})
.then((resp) => resp.json())
.then((jsonResp) => {
const playListId = jsonResp.id;
return fetch();
});
})
);
},