Skip to content

Process Address

Introduction

Once a user has selected an address from the address suggestions provided by a search/lookup, that address suggestion needs to be passed to the AddressIT Process API function in order for it to be returned as a fully matched and parsed address.

Process takes an input parameter of an address line object, e.g.

{
  "addressLine1": "2 KELLY ST",
  "addressLine2": "",
  "addressLine3": "BATTERY POINT TAS 7018"
}

and in this case returns a resulting matched and parsed address, e.g.

{
  "DPID": "40323312",
  "HouseNBR1": "2",
  "HouseNBR1SFX": "",
  "HouseNBR2": "",
  "HouseNBR2SFX": "",
  "FlatUnitType": "",
  "FlatUnitNBR": "",
  "FloorLevelType": "",
  "FloorLevelNBR": "",
  "BLDGPropName1": "",
  "BLDGPropName2": "",
  "LotNBR": "",
  "PostalDeliveryNBR": "",
  "PostalDeliveryNBRPfx": "",
  "PostalDeliveryNBRSfx": "",
  "StreetName": "KELLY",
  "StreetType": "ST",
  "StreetSfx": "",
  "Locality": "BATTERY POINT",
  "State": "TAS",
  "Postcode": "7004",
  "Line1": "2 KELLY ST",
  "Line2": "",
  "Line3": "BATTERY POINT TAS 7004",
  "Zone": 54,
  "CompletionCode": 213
}

The returned address structure can then be used for populating individual address data entry fields or in any way as required by the web form. Note that the Process step is required as part of the terms of using the AddressIT API service for a web form, even if the parsed individual address components are not needed.

See the Swagger Docs for more information on the Process function.

Implementation

See below for instructions and code examples of a basic implementation of this, again using JavaScript.

Send the Selected Address to Process

See the function below, which directly uses the selected address string, splits it into 3 address lines, and uses them as the body of the POST API request to Process. The returned data is the JSON parsed address structure as shown in the example above.

  const processSelectedAddress = async (selectedAddress: string) => {
    const [addressLine1, addressLine2, addressLine3] =
      selectedAddress.split(/\r?\n/);

    const body = JSON.stringify({
      addressLine1,
      addressLine2,
      addressLine3,
    });

    const token = "<my_api_token>";
    const method = 'POST';
    const headers = {
      Authorization: `Bearer ${token}`,
      "content-type": "application/json",
    };

    fetch("https://api.addressit.isw.net.au/process", {
      headers,
      method,
      body,
    })
    .then((response) => {
      return response.json().then((data) => {
        const { ok, status, statusText } = response;
        if (!ok) {
          return Promise.reject({
            message: data.message || data.errmsg || data.name,
            status,
            statusText,
            data,
          });
        }
        return data;
      });
    })
    .catch((err) => {
      console.log("Fetch error", err);
      return Promise.reject(err);
    });
  };

See optional step Parse Address for information on how to handle the situation where a user can't find their address in the address suggestions returned by the Lookup function.