Address Verification Guide

The goal of this guide is to walk you through EasyPost's Address Verification services. We'll give you some background on general AVS, as well as a quick tutorial on how to verify addresses using the EasyPost API. Since this guide requires you to have some knowledge of the EasyPost API, we recommend you check out our Getting Started Guide if you haven't used EasyPost before.

Address verification works through our Address Object and our Verifications Object. Please note that EasyPost will not flag or verify any address unless the verify or verify_strict parameters are used.

When you create an Address Object for your shipment with the aforementioned parameters, you also create associated zip4 or delivery attributes. zip4 only works for U.S. addresses and is used to verify the Zip+4 code of the address. delivery checks the rest of the address to determine its deliverability, and will make minor corrections to spelling/format if applicable.

The results of the verification will show up in the Verifications Object of the Address. The possible responses are:

  • success: the address is verified successfully.
  • errors: the address can't be verified due to an error, which will include error messaging with the response.
  • details: extra data related to the verification, specifically the longitude and latitude of the address.

International AVS works slightly differently. The objects and responses are similar, but zip4 is no longer a valid input to the verify and verify_strict parameters, since international addresses don't have the USPS' Zip+4 postal code. International AVS is also a premium, stand-alone service that must be subscribed to in order to be used. If you'd like to learn more about International AVS, contact our representatives for more information.

Verifying an Address
import com.easypost.EasyPost;
import com.easypost.exception.EasyPostException;

EasyPost.apiKey = "<YOUR_TEST/PRODUCTION_API_KEY>";

Map<String, Object> addressHash = new HashMap<String, Object>();

addressHash.put("street1", "417 montgomery streat"); // street1 will get cleaned up
addressHash.put("street2", "5");
addressHash.put("city", "SF");
addressHash.put("state", "CA");
addressHash.put("zip", "94104");
addressHash.put("country", "US");
addressHash.put("company", "EasyPost");
addressHash.put("phone", "415-123-4567");

List<String> verificationList = new ArrayList<>();
verificationList.add("delivery");
addressHash.put("verify", verificationList);

// This address will be verified
Address address = Address.create(addressHash);

System.out.println(address.getStreet1());
// 118 MONTGOMERY ST FL 5


    
JSON Response
{
  "id": "adr_3dc0df9695654f1f8a788e1c872a0769",
  "object": "Address",
  "created_at": "2017-05-08T19:31:54Z",
  "updated_at": "2017-05-08T19:31:54Z",
  "name": null,
  "company": "EASYPOST",
  "street1": "417 MONTGOMERY ST STE 500",
  "street2": "",
  "city": "SAN FRANCISCO",
  "state": "CA",
  "zip": "94104-1100",
  "country": "US",
  "phone": "4151234567",
  "email": null,
  "mode": "test",
  "carrier_facility": null,
  "residential": false,
  "federal_tax_id": null,
  "state_tax_id": null,
  "verifications": {
    "delivery": {
      "success": true,
      "errors": [],
      "details": {
        "longitude": -122.40288,
        "latitude": 37.79298,
        "time_zone": "America/Los_Angeles"
      }
    }
  }
}
Verifying an invalid Address
import com.easypost.EasyPost;
import com.easypost.exception.EasyPostException;

EasyPost.apiKey = "<YOUR_TEST/PRODUCTION_API_KEY>";

Map<String, Object> addressHash = new HashMap<String, Object>();

addressHash.put("street1", "UNDELIEVRABLE ST");
addressHash.put("city", "SF");
addressHash.put("state", "CA");
addressHash.put("zip", "94104");
addressHash.put("country", "US");
addressHash.put("company", "EasyPost");
addressHash.put("phone", "415-123-4567");

List<String> verificationList = new ArrayList<>();
verificationList.add("delivery");
addressHash.put("verify", verificationList);

// This address will not be verified
Address address = Address.create(addressHash);

System.out.println(address.getVerifications());
// {delivery=com.easypost.model.AddressVerification@4cf4d529}



    
JSON Response
{
  "id": "adr_3618edae14874ff88d54ddfe94f21a41",
  "object": "Address",
  "created_at": "2017-05-08T19:43:41Z",
  "updated_at": "2017-05-08T19:43:41Z",
  "name": null,
  "company": "EasyPost",
  "street1": "UNDELIVERABLE ST",
  "street2": null,
  "city": "SAN FRANCISCO",
  "state": "CA",
  "zip": "94104",
  "country": "US",
  "phone": "4151234567",
  "email": null,
  "mode": "test",
  "carrier_facility": null,
  "residential": false,
  "federal_tax_id": null,
  "state_tax_id": null,
  "verifications": {
    "delivery": {
      "success": false,
      "errors": [
        {
          "suggestion": null,
          "code": "E.ADDRESS.NOT_FOUND",
          "field": "address",
          "message": "Address not found"
        },
        {
          "suggestion": null,
          "code": "E.HOUSE_NUMBER.MISSING",
          "field": "street1",
          "message": "House number is missing"
        }
      ],
      "details": {}
    }
  }
}
Strict-Verifying Addresses
import com.easypost.EasyPost;
import com.easypost.exception.EasyPostException;

EasyPost.apiKey = "<YOUR_TEST/PRODUCTION_API_KEY>";

Map<String, Object> addressHash = new HashMap<String, Object>();

addressHash.put("street1", "UNDELIEVRABLE ST");
addressHash.put("city", "SF");
addressHash.put("state", "CA");
addressHash.put("zip", "94104");
addressHash.put("country", "US");
addressHash.put("company", "EasyPost");
addressHash.put("phone", "415-123-4567");

List<String> verificationList = new ArrayList<>();
verificationList.add("delivery");
addressHash.put("verify_strict", verificationList);

try {
  // This request will result in an error
  Address address = Address.create(addressHash);
}
catch (com.easypost.exception.EasyPostException e) {
  System.out.println(e.getMessage());
  // Response code: 400 Response body: {"error":{"code":"ADDRESS.VERIFY.FAILURE","message":"Address not found","errors":[]}}
}



    
JSON Response
{
  "error": {
    "code": "ADDRESS.VERIFY.FAILURE",
    "message": "Unable to verify address.",
    "errors": [
      {
        "suggestion": null,
        "code": "E.ADDRESS.NOT_FOUND",
        "field": "address",
        "message": "Address not found"
      },
      {
        "suggestion": null,
        "code": "E.HOUSE_NUMBER.MISSING",
        "field": "street1",
        "message": "House number is missing"
      }
    ]
  }
}