Skip to main content

Setup

Add go.addresszen.com/sdk to your module, then create a client with your API key. The SDK needs Go 1.26 or later and has no other dependencies.

Install​

go get go.addresszen.com/sdk

Create a client​

Pass your API key to NewClient(). The package name is addresszen, so import it under that name.

client.gogo
package main

import (
"context"
"fmt"
"log"

addresszen "go.addresszen.com/sdk"
)

func main() {
client := addresszen.NewClient("ak_test")
res, err := client.FindAddress(context.Background(), &addresszen.FindAddressParams{
Query: "1010 Cauthen Ln",
})
if err != nil {
log.Fatal(err)
}
fmt.Println(len(res.Result.Hits), "suggestions")
}

A Client is safe for concurrent use. Create one and share it.

Management Key​

Key details, usage and logs, licensees and configurations need your Management Key, which begins uk_. Pass it with WithManagementKey(). It grants control of your account, so keep it on your server and out of version control.

management.gogo
package main

import (
"context"
"fmt"
"log"
"os"

addresszen "go.addresszen.com/sdk"
)

func main() {
client := addresszen.NewClient("ak_test",
addresszen.WithManagementKey(os.Getenv("AZN_MANAGEMENT_KEY")))
details, err := client.KeyDetails(context.Background(), "ak_test")
if err != nil {
log.Fatal(err)
}
fmt.Println(details.Result.LookupsRemaining)
}

A client without a Management Key returns addresszen.ErrMissingManagementKey from those methods, before it sends a request.

Client options​

NewClient() takes options after the key.

OptionPurpose
WithManagementKey(string)The Management Key for account operations
WithHTTPClient(*http.Client)The HTTP client to send requests through. The default times out after 30 seconds
WithBaseURL(string)Defaults to https://api.addresszen.com/v1
WithUserAgent(string)A product sent ahead of the SDK and Go versions in User-Agent, for example my-app/1.0 addresszen-go-sdk/0.1.0 go/1.27.4

Request timeout​

Set a deadline on the context for one call, or a Timeout on the HTTP client for every call. A request that runs past either returns an error that errors.Is matches to context.DeadlineExceeded, as described in error handling.

timeout.gogo
package main

import (
"context"
"fmt"
"log"
"net/http"
"time"

addresszen "go.addresszen.com/sdk"
)

func main() {
client := addresszen.NewClient("ak_test",
addresszen.WithHTTPClient(&http.Client{Timeout: 10 * time.Second}))

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

res, err := client.AddressVerify(ctx, addresszen.AddressVerifyBody{
Query: "1010 Cauthen Ln, Alamogordo, NM 88310",
}, nil)
if err != nil {
log.Fatal(err)
}
if m := res.Result.AsUsaVerifyMatch(); m != nil {
fmt.Println(m.ZipCode)
}
}

Credentials​

The API key goes in the Authorization header of every address, place, email and phone request. The Management Key goes in the same header of every key, licensee and configuration request, and nowhere else. KeyAvailability() and RetrieveConfig() send no credentials.

To bill requests to a licensee, create a client with the licensee's key, which begins sl_, in place of your API key.

User-Agent​

Every request carries User-Agent: addresszen-go-sdk/<version> go/<Go version>, such as addresszen-go-sdk/0.1.0 go/1.27.4. WithUserAgent() puts your own product in front. The header holds no credentials or address data.