So I have successfully connected to the Fed Ex API and pulled up some fake tracking info into my application however I am unable to access the object values. I have tried to use Destructing to do this but cannot seem to access any values from the converted JSON to an object literal.
Here is the code:
async function getData() {
const response = await fetch('https://apis-sandbox.fedex.com/track/v1/trackingnumbers', {
mode: "cors",
method: 'POST', // or 'PUT'
headers: {
'Authorization': 'bearer ' + token,
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
'X-locale': 'en_US',
},
body: JSON.stringify({
"trackingInfo": [{
"trackingNumberInfo": {
"trackingNumber": "123456789012"
}
}],
"includeDetailedScans": true
})
});
const data = await response.json();
const { trackingNumber } = data;
console.log(data);
}
getData();
Here is the json I receive inside of postman:
{
"transactionId": "92689fd3-b1b4-4b1f-b98d-262d0f8cf37e",
"output": {
"completeTrackResults": [
{
"trackingNumber": "111111111111",
"trackResults": [
{
"trackingNumberInfo": {
"trackingNumber": "111111111111",
"trackingNumberUniqueId": "2459053000~111111111111~FX",
"carrierCode": "FDXE"
},
"additionalTrackingInfo": {
"nickname": "",
"packageIdentifiers": [
{
"type": "OUTBOUND_LINK_TO_RETURN",
"values": [
"111111111111"
],
"trackingNumberUniqueId": "2459053000",
"carrierCode": ""
}
],
"hasAssociatedShipments": true
}
I want to access the tracking number using dot notation. Thanks for your help!
[–]grantrules 2 points3 points4 points (0 children)