0
votes
makePlaylist = event => {
        event.preventDefault()
        let token = localStorage.getItem('token')
        let playlist = {name: this.state.text, public:false}
        axios.post(
            `https://api.spotify.com/v1/users/${this.state.user_id}/playlists`, playlist,
          {headers: {
            "Authorization": 'Bearer ' + token
          }
        }
        )
        .then(response => {
            console.log(response)
        })
        .catch(error => {
            console.log(error)
        })
    }

and I get the following error

https://api.spotify.com/v1/users/my_user_id_here/playlists 403 error

I looked up the documentation online at

https://developer.spotify.com/documentation/web-api/reference/playlists/create-playlist/

and it looks like I'm setting things up as far as I can tell. Anyone know what I'm doing wrong with the request? I know the access token is valid.

1
Can you try specifying the 'Content-Type' header to 'application/json' - FailedUnitTest
Aww tried that. Added line "Content-Type": "application/json" below authorization and got same 403 error. - user2785628
Have you added the playlist-modify-private scope to your authorize request? - seanulus

1 Answers

0
votes

"Trying to create a playlist when you do not have the user’s authorization returns error 403 Forbidden." Make sure that the Spotify app that you made in Dashboard has the proper scope permissions on the user you are trying to create the playlist for.

Here is the scope for creating a private playlist: https://developer.spotify.com/documentation/general/guides/scopes/#playlist-modify-private

Here is the tutorial for setting up authorization with passing in a scope: https://developer.spotify.com/documentation/general/guides/authorization-guide/