Jamming is not saving songs to spotify

Hello, I am REALLY STRUGGLING with this jammming app. I finished it and when I tried to perform saving to spotify , it create the playlist name BUT not add the songs there I was checking the code twice but I can’t realize which is the reason because the app saving the track to the playlist created. Sorry guys but I am really newbie coding.


Facing similar issues. Maybe you and I have the same problem - elaborating for help. Spotify API throwing a 401 error while retrieving userId.

As per https://developer.spotify.com/documentation/web-api/#response-status-codes ,
401 error code is :
Unauthorized - The request requires user authentication or, if the request included authorization credentials, authorization has been refused for those credentials.

whereas i am passing the correct header with accessToken because rest of the functions like search are working.

Please help!!!

console and code screenshot

Im having the same problem with the Original Poster, but yours @kushalsogani is a different issue.
Check out your headers object. An object is always in the form of key : value pair(s)

return fetch("https://api.spotify.com/v1/me", { headers: headers })

You’ll have to post your code for help. Too many variables it could be otherwise.

I actually managed to fix it, forgot to include “spotify.com” to the url… felt so stupid :sweat_smile:
Can post code if @jpiazza37 still has that issue

Hey all, I am struggling with the same thing. The last POST method throws a 404 error. ‘Something is not found’, but I do not get what. I checked and I get an array of trackUris, accessToken. Is there something wrong in the code? This is the error i get:

P.S.When I enter the search term for the first time and press Search, the tracklist populates but then the page reloads itself and the tracklist stays empty. Instead, the page link changes with extensions of access_token and expires_in. Only after typing the term again and pressing Search, the tracklist populates again and stays as expected. Is there some connection here with this strange behaviour?

 savePlaylist(name, trackUris) {
        if (!name || !trackUris.length) {

        const accessToken = Spotify.getAccessToken();
        const headers = { Authorization: `Bearer ${accessToken}` };
        let userId;

        return fetch('https://api.spotify.com/v1/me', { headers: headers }
        ).then(response => response.json()
        ).then(jsonResponse => {
            userId = jsonResponse.id;
            return fetch(`https://api.spotify.com/v1/users/${userId}/playlists`, {
                headers: headers,
                method: 'POST',
                body: JSON.stringify({ name: name })
            }).then(response => response.json()
            ).then(jsonResponse => {
                const playlistId = jsonResponse.id;
                return fetch(`­https://api.spotify.com/v1/users/${userId}/playlists/${playlistId}/tracks`,
                        headers: headers,
                        method: 'POST',
                        body: JSON.stringify({ uris: trackUris }) 

@apalaio Hi! Can you elaborate on the spotify.com addition to the url? Can you, please, post the code with the change you made? Thanks!

I resolved the issue via Stackoverflow. The video tutorial for this project uses outdated POST method to add tracks. See the answer here: https://stackoverflow.com/questions/60747151/spotify-web-api-why-is-the-newly-created-playlist-not-populated-with-chosen-so


[quote=“scriptace90348, post:6, topic:456055”]
n I enter the search term for the first time and press Sea

Thanks I will try this the next days , i will keep you posted

Thanks for this mate!

Thank you!! This solved my issue and now the songs actually appear in the playlist along with the title.

Sorry guys but I still watching the same issue for sure I might be doing some wrong from my end , but could I send my repo in git , cause not sure what is the issue!