Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!