Forum Discussion
_anomDiebolt_
9 years agoQrew Elite
You have to obtain a key from USPS and reference their docs:
https://www.usps.com/business/web-tools-apis/general-api-developer-guide.pdf
Here is the relevant code applied from the console that used the second example on page 16 as a test case.
See the annotated screenshot of applying these commands from the console:
Note that the USPS API does not support https so you will have to click on the shield that appears to the right of the address bar to allow mixed content (https and http on same page).
https://www.usps.com/business/web-tools-apis/general-api-developer-guide.pdf
Here is the relevant code applied from the console that used the second example on page 16 as a test case.
//Emulate Filling In Address2, City, State and Zip5 fields
_fid_7.value = "8 Wildwood Drive";
_fid_8.value = "Old Lyme";
_fid_9.value = "CT";
_fid_10.value = "06371";
//Form the URL using HTTP (HTTPS not Allowed)
var url = '';
url += 'http://production.shippingapis.com/ShippingAPITest.dll?API=Verify';
url += '&XML=<AddressValidateRequest USERID="416NETEL6870">';
url += '<Address ID="1">';
url += '<Address1></Address1>';
url += '<Address2>' + _fid_7.value + '</Address2>';
url += '<City>' + _fid_8.value + '</City>';
url += '<State>' + _fid_9.value + '</State>';
url += '<Zip5>' + _fid_10.value + '</Zip5>';
url += '<Zip4>' + _fid_11.value + '</Zip4>';
url += '</Address>';
url += '</AddressValidateRequest>';
//jQuery to Fill in Zip4 field from server XML response
$.get(url)
.then(function(xml) {
console.dirxml(xml);
var Address2 = $("Address2", xml).text();
var City = $("City", xml).text();
var State = $("State", xml).text();
var Zip5 = $("Zip5", xml).text();
var Zip4 = $("Zip4", xml).text();
_fid_11.value = Zip4;
});
See the annotated screenshot of applying these commands from the console:
Note that the USPS API does not support https so you will have to click on the shield that appears to the right of the address bar to allow mixed content (https and http on same page).