# Licensees

A licensee is one of your customers using AddressZen through your key. Sub-licensing lets a platform serve many customers from one account and one bill while tracking each customer's usage separately. The licensee methods create, list, update and cancel them.

Your key must be enabled for sub-licensing; [contact us](https://addresszen.com/contact) to switch one over. Every licensee method needs a [Management Key](/docs/sdks/go/setup.md#management-key). The [sub-licensing guide](/docs/guides/sublicensing.md) covers billing.

## Add a licensee

Call `CreateLicensee()` with the customer's name and address. The result carries the licensee's own key, beginning `sl_`, in `Key`, and its `ID`.

create.gogo

```go
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.CreateLicensee(context.Background(), "ak_test", addresszen.CreateLicenseeBody{
		Name:      new("Example Inc"),
		Address:   new("1010 Cauthen Ln, Alamogordo, NM"),
		Postcode:  new("88310"),
		Whitelist: new([]string{"https://www.example.com"}),
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(res.Result.ID, res.Result.Key)
}
```

`Postcode` takes the customer's ZIP or postal code, whatever their country. `Whitelist` lists the URLs the licensee's key may be used from.

## List licensees

`ListLicensees()` returns 10 per call by default and up to 100 with `Limit`, oldest first. Canceled licensees are left out. `Query` filters by name. `HasMore` says whether another page exists: to fetch it, set `StartingAfter` to the `ID` of the last licensee on this one.

list.gogo

```go
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")))
	params := &addresszen.ListLicenseesParams{Limit: 100}
	for {
		res, err := client.ListLicensees(context.Background(), "ak_test", params)
		if err != nil {
			log.Fatal(err)
		}
		licensees := res.Result.Licensees
		for _, licensee := range licensees {
			fmt.Printf("%s: %d lookups today\n", licensee.Name, licensee.Daily.Count)
		}
		if !res.Result.HasMore || len(licensees) == 0 {
			break
		}
		params.StartingAfter = licensees[len(licensees)-1].ID
	}
}
```

## Update or delete a licensee

Pass your key and the licensee's key:

* `UpdateLicensee()` changes the `Address`, `Postcode`, allowed URLs (`Whitelist`) or `Daily` limit. The name cannot change after creation
* `RegenerateLicenseeKey()` issues a new `sl_` key and stops the old one immediately
* `DeleteLicensee()` cancels the licensee and stops its key. Contact us to undo it

`RetrieveLicensee()` returns one licensee.

## Licensee usage

Set `Licensee` on `KeyUsageParams` or `KeyLogsParams`. See [API keys](/docs/sdks/go/keys.md#usage-export).

To send requests on a licensee's behalf, create a client with its `sl_` key in place of your API key.

See [`CreateLicensee()`](/docs/sdks/go/endpoints/create-licensee.md) and [`ListLicensees()`](/docs/sdks/go/endpoints/list-licensees.md) for the body and parameters.
