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

129
Views
Why is my response object empty using Express.js?

I am trying to authenticate Spotify API using the OAuth2.0 client credentials flow. Generally the flow is as follows:

  1. Send GET request to /authenticate endpoint with required parameters, including a callback endpoint that i have set to my http://localhost:8888/callback
const open = require('open')

responseType = 'token'
clientID = 'CLIENT_ID'
redirectURI = 'http%3A%2F%2Flocalhost%3A8888%2Fcallback'
scope = 'streaming+user-read-email+user-modify-playback-state+user-read-private+user-library-read+user-library-modify+user-read-currently-playing'
contentType = 'application/json'

params = {
  'response_type' : responseType,
  'client_id' : clientID,
  'redirect_uri' : redirectURI,
  'scope' : scope
}

headers = {
  'Content-Type' : contentType
}

// send user to browser to grant data permissions
open(`https://accounts.spotify.com/en/authorize?response_type=${responseType}&client_id=${clientID}&redirect_uri=${redirectURI}&scope=${scope}&show_dialog=true`)

-- this part is fine, i have no issues sending user to browser to login and grant my app permission and the Express server i have listening on port 8888 lets me know when the callback pings with the response

  1. Receive Authentication Token in params of callback from Authentication endpoint. Spotify API handles this part and sends the authentication token that i need as part of the header in the response. it looks like this http://localhost:8888/callback#authentication_token=2iais820zg...fh9IHkLDI&timeout=3600 -- this is what i am having problems with.

here is my how i am handling the api callback in my Express server's /callback endpoint:

app.get('/callback', function (req, res) {
    console.log('someone made a request!\n')
    ///                             ////
    console.log(req + '\n')
    console.log(res + '\n')
    ///                             ////
    console.log(req.body)
    res.json(req.body)
    res.send('GET request to callback endpoint took you here')
    res.end()
})

but the console output is as follows:

> server is listening on port 8888 ...
someone made a request!

[object Object]

[object Object]

{}

where everything is empty.

how can i access the URL parameters of the callback GET request? i have tried changing the handling from GET to POST as people have told me that a GET request doesn't contain params but the callback can't find the endpoint (bc it's not making a POST request..)

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

0

you should put the parameters into request body not in the header as you mentioned to let you use req.body with no problem

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!