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
package addresses;

import com.easypost.exception.EasyPostException;
import com.easypost.model.Address;
import com.easypost.service.EasyPostClient;

import java.util.HashMap;

public class VerifyParam {
    public static void main(String[] args) throws EasyPostException {
        EasyPostClient client = new EasyPostClient(System.getenv("EASYPOST_API_KEY"));

        HashMap<String, Object> params = new HashMap<String, Object>();

        params.put("street1", "000 unknown street");
        params.put("city", "Not A City");
        params.put("state", "ZZ");
        params.put("zip", "00001");
        params.put("country", "US");
        params.put("email", "test@example.com");
        params.put("phone", "5555555555");
        params.put("verify", true);

        Address address = client.address.create(params);

        System.out.println(address);
    }
}
JSON Response
{
  "id": "adr_3a98ffc7bafa11eeb8fcac1f6bc539ae",
  "object": "Address",
  "created_at": "2024-01-24T20:50:38+00:00",
  "updated_at": "2024-01-24T20:50:38+00:00",
  "name": null,
  "company": "EasyPost",
  "street1": "000 unknown street",
  "street2": null,
  "city": "Not A City",
  "state": "ZZ",
  "zip": "00001",
  "country": "US",
  "phone": "5555555555",
  "email": "test@example.com",
  "mode": "test",
  "carrier_facility": null,
  "residential": null,
  "federal_tax_id": null,
  "state_tax_id": null,
  "verifications": {
    "zip4": {
      "success": false,
      "errors": [
        {
          "code": "E.ADDRESS.NOT_FOUND",
          "field": "address",
          "message": "Address not found",
          "suggestion": null
        }
      ],
      "details": null
    },
    "delivery": {
      "success": false,
      "errors": [
        {
          "code": "E.ADDRESS.NOT_FOUND",
          "field": "address",
          "message": "Address not found",
          "suggestion": null
        }
      ],
      "details": {}
    }
  }
}
Verifying an invalid Address
package addresses;

import com.easypost.exception.EasyPostException;
import com.easypost.model.Address;
import com.easypost.service.EasyPostClient;

import java.util.HashMap;

public class VerifyFailure {
    public static void main(String[] args) throws EasyPostException {
        EasyPostClient client = new EasyPostClient(System.getenv("EASYPOST_API_KEY"));

        HashMap<String, Object> params = new HashMap<String, Object>();

        params.put("street1", "000 unknown street");
        params.put("city", "Not A City");
        params.put("state", "ZZ");
        params.put("zip", "00001");
        params.put("country", "US");
        params.put("email", "test@example.com");
        params.put("phone", "5555555555");

        Address address = client.address.create(params);

        System.out.println(address);
    }
}
JSON Response
{
  "error": {
    "code": "ADDRESS.VERIFY.FAILURE",
    "message": "Unable to verify address.",
    "errors": [
      {
        "code": "E.ADDRESS.NOT_FOUND",
        "field": "address",
        "message": "Address not found",
        "suggestion": null
      }
    ]
  }
}
Strict-Verifying Addresses
package addresses;

import com.easypost.exception.EasyPostException;
import com.easypost.model.Address;
import com.easypost.service.EasyPostClient;

import java.util.HashMap;

public class VerifyStrictParam {
    public static void main(String[] args) throws EasyPostException {
        EasyPostClient client = new EasyPostClient(System.getenv("EASYPOST_API_KEY"));

        HashMap<String, Object> params = new HashMap<String, Object>();

        params.put("street1", "000 unknown street");
        params.put("city", "Not A City");
        params.put("state", "ZZ");
        params.put("zip", "00001");
        params.put("country", "US");
        params.put("email", "test@example.com");
        params.put("phone", "5555555555");
        params.put("verify_strict", true);

        Address address = client.address.create(params);

        System.out.println(address);
    }
}
JSON Response
{
  "error": {
    "code": "ADDRESS.VERIFY.FAILURE",
    "message": "Unable to verify address.",
    "errors": [
      {
        "code": "E.ADDRESS.NOT_FOUND",
        "field": "address",
        "message": "Address not found",
        "suggestion": null
      }
    ]
  }
}
Verify an already created Address
package addresses;

import com.easypost.exception.EasyPostException;
import com.easypost.model.Address;
import com.easypost.service.EasyPostClient;

import java.util.HashMap;

public class Verify {
    public static void main(String[] args) throws EasyPostException {
        EasyPostClient client = new EasyPostClient(System.getenv("EASYPOST_API_KEY"));

        HashMap<String, Object> params = new HashMap<String, Object>();

        params.put("street1", "417 Montgomery Street");
        params.put("city", "SF");
        params.put("state", "CA");
        params.put("zip", "94104");
        params.put("country", "US");
        params.put("company", "EasyPost");
        params.put("phone", "415-123-4567");
        params.put("verify_strict", true);

        Address address = client.address.create(params);

        Address verifiedAddress = client.address.verify(address.getId());

        System.out.println(verifiedAddress);
    }
}
JSON Response
{
  "address": {
    "id": "adr_3b15ed39bafa11ee83ed3cecef1b359e",
    "object": "Address",
    "created_at": "2024-01-24T20:50:39+00:00",
    "updated_at": "2024-01-24T20:50:39+00:00",
    "name": null,
    "company": "EASYPOST",
    "street1": "417 MONTGOMERY ST FL 5",
    "street2": "",
    "city": "SAN FRANCISCO",
    "state": "CA",
    "zip": "94104-1129",
    "country": "US",
    "phone": "4151234567",
    "email": null,
    "mode": "test",
    "carrier_facility": null,
    "residential": false,
    "federal_tax_id": null,
    "state_tax_id": null,
    "verifications": {
      "zip4": {
        "success": true,
        "errors": [],
        "details": null
      },
      "delivery": {
        "success": true,
        "errors": [],
        "details": {
          "latitude": 37.79342,
          "longitude": -122.40288,
          "time_zone": "America/Los_Angeles"
        }
      }
    }
  }
}