Licensees

A licensee is a client of yours that uses Ideal Postcodes data under your key. Sublicensing lets a platform serve many clients from one account and one bill, with each client's usage kept separate. The licensee methods create, list, update and cancel them.

Your key must be a sublicensing key; contact us to convert one. Every method needs a Management Key.

Add a licensee​

Call CreateLicensee() with the client's legal name and address. The result carries the licensee's own key, beginning sl_, in Key, and its ID for the other methods.

create.gogo
package main

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

	idealpostcodes "go.ideal-postcodes.co.uk/sdk"
)

func main() {
	client := idealpostcodes.NewClient("ak_test",
		idealpostcodes.WithManagementKey(os.Getenv("IDPC_MANAGEMENT_KEY")))
	res, err := client.CreateLicensee(context.Background(), "ak_test", idealpostcodes.CreateLicenseeBody{
		Name:      new("Example Ltd"),
		Address:   new("9 Malyons Road, Swanley"),
		Postcode:  new("BR8 7RE"),
		Whitelist: new([]string{"https://www.example.com"}),
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(res.Result.ID, res.Result.Key)
}

Your licensees must accept Royal Mail's terms of use. Including them in your own terms is enough.

List licensees​

ListLicensees() returns 10 per call by default and up to 100 with Limit, oldest first, without cancelled ones. HasMore says whether more exist: to fetch the next page, set StartingAfter to the ID of the last licensee on this one. Set Query to filter by name.

list.gogo
package main

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

	idealpostcodes "go.ideal-postcodes.co.uk/sdk"
)

func main() {
	client := idealpostcodes.NewClient("ak_test",
		idealpostcodes.WithManagementKey(os.Getenv("IDPC_MANAGEMENT_KEY")))
	params := &idealpostcodes.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
	}
}

Change or cancel​

Pass the key and the licensee's ID:

  • UpdateLicensee() changes the Name, Address, Postcode, allowed URLs (Whitelist) or Daily limit
  • RegenerateLicenseeKey() issues a new sl_ key. The old one stops working at once
  • DeleteLicensee() cancels the licensee. Its key stops working. Contact us to reverse it

RetrieveLicensee() returns one licensee by ID.

Billing​

Each licensee buys lookups in blocks of 100, so a client who uses 60 lookups is billed for 100 and the next 40 cost nothing. Report one licensee's usage by setting Licensee on KeyUsageParams or KeyLogsParams. See API keys.

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

See CreateLicensee() and ListLicensees() for the body and parameters.