USPS post XML

by George Obregon

JavaScript

var rawXMLOrig = '<AddressValidateRequest'
 +'USERID="378MTOMC3397">'
      +'<Address>'
      +'<Address1></Address1> '
      +'<Address2>6406 IVY LANE</Address2> '
      +'<City>GREENBELT</City>'
      +'<State>MD</State>'
      +'<Zip5>20770</Zip5>'
      +'<Zip4></Zip4>'
      +'</Address>'
      +'</AddressValidateRequest>';
  
  
 /* var rawXML = '<AddressValidateRequest '
    +'USERID="378MTOMC3397">'
      +'<Address>'
      +'<Address1></Address1> '
      +'<Address2>'+I_address+'</Address2> '
      +'<City>'+I_city+'</City>'
      +'<State>'+I_state+'</State>'
      +'<Zip5>'+I_zip+'</Zip5>'
      +'<Zip4></Zip4>'
      +'</Address>'
      +'</AddressValidateRequest>'; */

  
var options1 = {
  'method' : 'get',
  'contentType': 'text/xml',
  // Convert the JavaScript object to a JSON string.
//  'payload' : JSON.stringify(data)
    'payload' : rawXMLOrig
};
  var productionURL = 'https://secure.shippingapis.com/ShippingAPI.dll?API=Verify&XML=' + rawXMLOrig;
  
   console.log(productionURL);
  
  var options2 = {
mode: 'cors', // 'cors' by default
  method: 'POST',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/xml'
  },
  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"
}
}
})
};


fetch(productionURL)
  .then(function(response) {
    // The response is a Response instance.
    // You parse the data into a useable format using `.json()`
    console.log(response);
    return response.body;
 ...