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

222
Views
How to do Spotify Api Post Request using Axios

I'm trying to add a song to the playback queue using this endpoint:

   const add = async () => {
   

    try {
      
      const url = `https://api.spotify.com/v1/me/player/queue?uri=${songUrl}&device_id=${deviceId}`
     
      await axios.patch(url, {
        headers: {
            Authorization: `Bearer ${to}`
        },
    })
    } catch (error) {
      console.log(error);
    }
   
   
}

I'm getting a status 401 error with a message that says no token provided. But when I console.log the token it shows up.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I haven't worked with the Spotify API yet, however, according to their docs, you need to send a POST request, not a PATCH, which is what you used.

Use axios.post() instead of axios.patch():

const add = async (songUrl, deviceId, token) => {
  try {
    const url = `https://api.spotify.com/v1/me/player/queue?uri=${songUrl}&device_id=${deviceId}`;

    await axios.post(url, {
      headers: {
        Authorization: `Bearer ${token}`,
      },
    });
  } catch (error) {
    console.log(error);
  }
};
about 4 years ago · Juan Pablo Isaza Report

0

The second param of your post request should be body and the third param should be headers. Also, you haven't added all the headers as mentioned in the documentation.

headers: {
      Accept: 'application/json',
      Authorization: 'Bearer ' + newAccessToken,
      'Content-Type': 'application/json',
}

Get your access token from here: https://developer.spotify.com/console/post-queue/

If it still doesn't work try the curl method as mentioned in their docs and if it works, switch it to axios.

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!