Can I write my own autocomplete service?
If you decide to write your own autocomplete service, then you will need to follow these guidelines.
Make a GET request
AddressFinder is expecting that an HTTP GET request is made. Although an HTTP POST request is supported, it will add extra complexity for your developers. The user experience will be degraded with a POST request as a CORS pre-flight request will be required.
Use a simple request
Requests to the AddressFinder API from a browser are classified as “Cross Origin” as they are made to a different domain than the main web page. These requests are subject to the CORS mechanisms which are built into all modern browsers.
Simple requests are HTTP GET requests that meet certain criteria such as allowing headers and content types. You can read more about the criteria here:
Make a secure requests (HTTPS)
You should always make requests to our secure endpoint using HTTPS. Support of unencrypted HTTP requests is only retained for backwards compatibility purposes, and will eventually be disabled.
In addition, use of HTTPS endpoint will allow the browser to make HTTP version 2 requests. These are substantially faster, and will give a better user experience.
For authentication, the requests must be sent from a domain which has been approved on your AddressFinder account. The Referer header, which is automatically included by the browser, is used for this purpose.
You should not include the API secret token in any of your API calls. The secret is intended for server-to-server API calls only. By including the secret in a browser-based API call, this value would be visible to 3rd parties. This could result in your account being abused by malicious parties.
The AddressFinder API performs a safety check to ensure that the secret value has not been included. It will return a 1008 error if the secret has been included. See https://addressfinder.nz/api/nz/address/autocomplete/#errors
The domain parameter is not intended for use in the web browser. If you include it, the API will return an error result.
Address Autocomplete and Metadata APIs
The Address Autocomplete API must be used in conjunction with the Address Metadata API.
We expect that several calls to the Autocomplete API would be made as the user types in a portion of their address. The results of the Autocomplete API should be displayed to the user, normally in a popup style panel.
When the user identifies the desired address, they would select that address. At that point, you should make a call to the Address Metadata API. This would return all of the individual metadata for that address.
General Request Parameters
Include other request parameters in your request string as necessary. These will determine the types of addresses and data returned in the response. https://addressfinder.nz/api/nz/address/autocomplete/#build