Fetch POST JSON
by George Obregon
JavaScript
fetch('https://onlinetools.ups.com/rest/XAV', {
mode: 'no-cors', // 'cors' by default
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"UPSSecurity": {
"UsernameToken": {
"Username": "geo.obregon",
"Password": "l1fE1sg00d"
},
"ServiceAccessToken": {
"AccessLicenseNumber": "5D514B0BAAB6F5BC"
}
},
"XAVRequest": {
"Request": {
"RequestOption": "1",
"TransactionReference": {
"CustomerContext": "Your Customer Context"
}
},
"MaximumListSize": "10",
"AddressKeyFormat": {
"ConsigneeName": "Consignee Name",
"BuildingName": "Building Name",
"AddressLine": "12380 Morris Road",
"PoliticalDivision2": "Alpharetta",
"PoliticalDivision1": "GA",
"PostcodePrimaryLow": "30009",
"CountryCode": "US"
}
}
})
})
.then(data => console.log(data.body))
/* .then(data => {
const countryFrequency = data.reduce((countries, value) => {
countries[value.destinationcountry] = countries[value.destinationcountry] ? countries[value.destinationcountry] + 1 : 1;
return countries;
}, {});
console.log(countryFrequency);
}) */
.catch(err => console.log(err));