API keys
The key methods show whether a key can take requests and which countries it covers. They also read limits, change settings and export usage. All of them except KeyAvailability() need a Management Key, passed with WithManagementKey().
Key status
Call KeyAvailability(). It needs no credentials and costs nothing, so it also works as a health check.
package main
import (
"context"
"fmt"
"log"
addresszen "go.addresszen.com/sdk"
)
func main() {
client := addresszen.NewClient("ak_test")
res, err := client.KeyAvailability(context.Background(), "ak_test")
if err != nil {
log.Fatal(err)
}
fmt.Println("available:", res.Result.Available)
for _, country := range res.Result.Contexts {
fmt.Println(country.Emoji, country.Description, country.ISO3)
}
}Available is false when the key has no lookups left, has hit a daily limit or is called from a URL it does not allow. Contexts lists the licensed countries; pass an ISO3 code as Context to FindAddress(). Context is the licensed country that best matches the caller's IP address, or empty.
Remaining lookups
KeyDetails() returns LookupsRemaining, the daily, monthly and per-IP limits, allowed URLs, notification settings and datasets. A limit that is not set is nil.
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")))
res, err := client.KeyDetails(context.Background(), "ak_test")
if err != nil {
log.Fatal(err)
}
fmt.Println(res.Result.LookupsRemaining, "lookups left")
if limit := res.Result.DailyLimit.Limit; limit != nil {
fmt.Println("daily limit", *limit)
}
}Limits
Call UpdateKeyDetails() with only the settings to change. Fields left nil are not sent, and the rest stay as they are.
package main
import (
"context"
"log"
"os"
addresszen "go.addresszen.com/sdk"
)
func main() {
client := addresszen.NewClient("ak_test",
addresszen.WithManagementKey(os.Getenv("AZN_MANAGEMENT_KEY")))
_, err := client.UpdateKeyDetails(context.Background(), "ak_test", addresszen.UpdateKeyDetailsBody{
DailyLimit: map[string]any{"limit": 1000},
AllowedURLs: new([]string{"https://www.example.com"}),
})
if err != nil {
log.Fatal(err)
}
}The nested settings (DailyLimit, MonthlyLimit, IndividualLimit, Notifications, Datasets) are maps keyed by the API's own field names, and a nil value in one is sent as JSON null. So map[string]any{"limit": nil} removes the daily limit, new([]string{}) removes the URL restriction and map[string]any{"enabled": false} in Notifications turns off notification emails. See UpdateKeyDetails() for every field.
Usage export
KeyUsage() returns totals and a daily breakdown. KeyLogs() returns each billable lookup as CSV text. Both take Start and End as time.Time.
package main
import (
"context"
"fmt"
"log"
"os"
"time"
addresszen "go.addresszen.com/sdk"
)
func main() {
ctx := context.Background()
client := addresszen.NewClient("ak_test",
addresszen.WithManagementKey(os.Getenv("AZN_MANAGEMENT_KEY")))
now := time.Now()
start, end := now.AddDate(0, 0, -7), now
usage, err := client.KeyUsage(ctx, "ak_test", &addresszen.KeyUsageParams{Start: start, End: end})
if err != nil {
log.Fatal(err)
}
for _, day := range usage.Result.DailyCount {
fmt.Printf("%s: %d\n", day.Date, day.Count)
}
fmt.Println("Total:", usage.Result.Total)
logs, err := client.KeyLogs(ctx, "ak_test", &addresszen.KeyLogsParams{Start: start, End: end})
if err != nil {
log.Fatal(err)
}
if err := os.WriteFile("lookups.csv", []byte(logs), 0o644); err != nil {
log.Fatal(err)
}
}Set Licensee in the same params to report one licensee's usage.
Saved configs
A config is a named JSON string stored against your key, such as the settings for an ecommerce plugin. ListConfigs(), CreateConfig(), UpdateConfig() and DeleteConfig() need the Management Key. RetrieveConfig() needs no credentials, so an integration can read its own config at runtime. See CreateConfig() for the body.