Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
Getting 401 error while making a PUT request to the Spotify API

I am trying to make a put request to create a playlist for a user and I keep getting a status: 401, message: "No token provided" error. Can someone help me take a look at my code and tell me what I am doing wrong?

    const createNewPlaylist = () => {
    var user_id = ''
    axios.get(' https://api.spotify.com/v1/me',{

        headers:{
            'Authorization':"Bearer " + localStorage.getItem("accessToken")
        }

    }).then((response)=>{
        user_id = response.data.id
        console.log(localStorage.getItem("accessToken"))
        axios.post('https://api.spotify.com/v1/users/'+user_id+'/playlists',
        {
            headers:{
                'Authorization':"Bearer " + localStorage.getItem("accessToken")
            },
            data:{
                "name": "huhsss",
                "description": "New playlist description",
                "public": false
            }
        }

    ).then((res)=>{
            console.log(res)
    })

    })
}

I have already added all the required scopes for this specific call and my token actually works for every other requests I make. It even works for the first GET request I make.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

For an axios post request, the data is the second argument and options (including headers) are the third argument:

axios.post(
  "https://api.spotify.com/v1/users/" + user_id + "/playlists",
  {
    name: "huhsss",
    description: "New playlist description",
    public: false,
  },
  {
    headers: {
      Authorization: "Bearer " + localStorage.getItem("accessToken"),
    },
  }
);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda