US Extract
Data ValidationExtract US Address Data using SmartyStreets API - API Example in JavaScript
If you're looking to extract address data from various sources like websites, forms or documents, SmartyStreets' US Extract API is a great option. This API can extract the full spectrum of address information, from house numbers to ZIP codes, and everything in between.
Here's how to use SmartyStreets' US Extract API with JavaScript -
Prerequisites
- A SmartyStreets account. You can sign up for a free trial account here.
- Copy of jQuery v3.x.
API Request Example
$(document).ready(function() {
$("#btnExtraction").click(function() {
var authId = 'MY_AUTH_ID';
var authToken = 'MY_AUTH_TOKEN';
var url = 'https://us-extract.api.smartystreets.com/';
var payload = {
"auth-id": authId,
"auth-token": authToken,
"html": $("#textAreaInput").val(),
"aggressive": true
};
$.post({
url: url,
data: payload,
success: function(response) {
$("#output").html(JSON.stringify(response, null, 2));
}
},
"json"
);
});
});
In the above example code, we're creating a payload
object containing auth-id
and auth-token
, which are required for authentication purposes. We're also sending the input text to the SmartyStreets API endpoint via the html
property of the payload.
You also have the option to set the aggressive
flag to true or false as per requirement.
API Response Example
{
"addresses": [
{
"text": "1600 Pennsylvania Ave NW\nWashington, DC 20500",
"verified": true,
"line_1": "1600 Pennsylvania Ave NW",
"city": "Washington",
"state": "DC",
"zip": "20500",
"delivery_point": "00",
"country": "US",
"latitude": 38.89767,
"longitude": -77.03655,
"analysis": {
"verification_status": "success",
"address_precision": "Premise",
"max_address_precision": "Premise",
"candidates": 1,
"input_index": 0,
"delivery_line_1": "1600 Pennsylvania Ave NW",
"last_line": "Washington DC 20500-0003",
"delivery_point_validation": "Yes",
"suitelink_match": false
}
}
]
}
The API returns an object that contains an array of addresses
. Each address contains various properties like line_1
, city
, state
, zip
, latitude
, longitude
, and more. The analysis
object within each address contains additional verification information.
That's it! You now know how to use SmartyStreets US Extract API to extract US address data with JavaScript.
Happy coding!