I am trying to fetch the attributes from the JSON.How to get the attribute url from the below JSON body?
I am receiving undefined in console
Here is my cloud function from
// shipmentai map tracking
exports.shipmentmaptracking = functions.https.onRequest((req, res) => {
var request = require("request");
var trackid = req.body.Tracking;
let d = {
"tracking_pages": [
{
"branded_tracking_theme_guid": "440bed90-617b-43ba-bd0e-31512ac66e23",
"tracking_number": "9400111699000367101815",
"carrier_code": "stamps_com",
"service_code": "usps_priority_mail",
}
]
};
var options = {
method: 'POST',
url: 'https://api.shipengine.com/v-beta/tracking_page',
headers: {
'Content-Type': 'application/json',
'api-key': 'Wyo4gpVIXfElQSDgF9p/L9aQ9kX3Um60X8hRSo8VAes'
},
body: JSON.stringify(d),
};
console.log('Sending a ' + options.method + ' request to ' + options.url);
request(options, function (error, response, body) {
console.log('Successfully received a response from ShipEngine')
if (error) {
console.log('An error was returned: ' + error.message);
res.status(500).send(error.message);
}
else if (response.statusCode >= 400) {
console.log('An error was returned: ' + response.statusCode + ' ' + response.statusMessage);
console.log(body);
res.status(response.statusCode).send(body);
}
else {
console.log('A successful response was returned');
console.log(body);
console.log(d.tracking_pages[0].url);
//res.status(200).send({'URL':shippp.tracking_pages[0].url});
console.log('statusCode:', response && response.statusCode);
}
});
});
Here is my Json output How to fetch the attribute URL from the JSON below
{
"tracking_pages": [
{
"carrier_code": "stamps_com",
"tracking_number": "9400111699000367101815",
"branded_tracking_theme_guid": "440bed90-617b-43ba-bd0e-31512ac66e23",
"token": "l1XKcsYaEECc903KqBvtaA",
"url": "https://track.shipengine.com/se/v1/g/l1XKcsYaEECc903KqBvtaA",
"service_code": "usps_priority_mail"
}
],
"page": 0,
"pages": 0,
"total": 0
}
Thanks in advance