0

I have a below code which is giving me response but when i try to access properties of the response, i am getting 'undefined'

const request = require('request-promise');

const option= {
method: 'GET',
uri: 'urihere',
qs: {
    q: 'Mark'
},
json: true,
resolveWithFullResponse: true,
headers: {
    'User-Agent': 'requestXYZPromise',
    'Authorization': ''
}
}

request(option)
    .then(response => {

})
.catch(error => {
})

What's wrong here? Please suggest.

Update - Response data. I am trying to get 'score'

{
"responseHeader":{
"ist":"json",
"version":"1.0"}},
"response":{"score":2,"start":0,"maxScore":18.9204}
}
Lara
  • 2,821
  • 7
  • 39
  • 72

2 Answers2

0

Your response has itself a property called response. To access your score value you would need to call response.response.score.

Raekh Void
  • 441
  • 3
  • 11
-2
{
  "response": {
    "score": 2,
    "start": 0,
    "maxScore": 18.9204
  }
}

This is your response and you can access as below.

request(option)
    .then(response => {
      console.log(response.response.score)
})
.catch(error => {
})
Krina Soni
  • 870
  • 6
  • 14