Hi there,
I’m fairly new to New Relic but I’m trying to find a way to pass the validation test.
I tried to send POST request to get the user access token, and then use that token to send a GET request to fetch some user information.
However, I always got the error: TypeError: Cannot read property ‘statusCode’ of undefined. I am thinking it might be some syntax error or some bad request from my side. Can you take a look of my code? Let me know if you need more information. Thanks in advance.
var info,token;
var assert = require(‘assert’);
var $http = require(‘request’)
var options = {
uri: ‘https://qa-apixxxxxx/token’,
body: {
‘username’:‘xxxxxxx’,
‘password’:‘xxxxxxxx’,
‘grant_type’:‘password’,
‘scope’:‘openid’
},
headers: {
‘Content-Type’: ‘application/x-www-form-urlencoded’,
‘Accept’:‘text/plain’
}
}
$http.post(options,function (err, response, body) {
console.log(response.statusCode);
console.log(body);
info = JSON.parse(body);
token=info.access_token;
console.log(‘Security token retrieved successfully’);
console.log(token);
assert.ok(response.statusCode == 200, ‘Expected 200 response’);
}
);
var options2 = {
uri: ‘https://qa-apixxxxx/users’,
headers: {
// ‘access_key’: token,
‘Accept’:‘application/json’,
‘Authorization’: token
//‘Content-Type’: ‘application/json’
},
body: {
‘username’:‘xxxxxxxx’
}
}
$http.get(options2,function (err, response, body) {
console.log(response.statusCode);
console.log(body);
assert.ok(response.statusCode == 200, ‘Expected 200 response’);
}
);