Skip to main content

client.CreateLicensee()

Create

Creates a licensee on a key and returns it with its generated sl_ key. The key must be enabled for sublicensing.

Endpoint​

POST /keys/{key}/licensees

See the API reference for this endpoint.

This operation needs a Management Key. Pass it with idealpostcodes.WithManagementKey(...) when you create the client, which sends it in the Authorization header. See setup.

Signature​

func (c *Client) CreateLicensee(ctx context.Context, key string, body CreateLicenseeBody) (*LicenseeResponse, error)

Arguments​

NameTypeRequiredDescription
ctxcontext.ContextyesCancels the request and sets its deadline.
keystringyesAPI Key
bodyCreateLicenseeBodyyesThe JSON request body. Fields under Request Body.

Query Parameters​

None.

Request Body​

Set these as fields of body, named in Studly case (post_town is PostTown). An optional field is a pointer, set with new(value), or a map; nil sends nothing.

NameTypeRequiredDescription
namestringnoLicensee individual or organisation name
addressstringnoLicensee's first, second and third line address as well as post town concatenated by commas
postcodestringnoLicensee's postcode
whitelist[]stringnoA list of allowed URLs. An empty list disables the check.
dailymap[string]anyno

Response​

*idealpostcodes.LicenseeResponse. Fields the API may leave out or send as null are pointers. RawJSON() returns the body as received. See responses.

Errors​

An HTTP error returns *idealpostcodes.APIError with the HTTP status, the API error code and the body; match it with errors.AsType. A transport failure returns the net/http error, wrapped. See error handling.

Example​

create-licensee/main.gogo
package main

import (
"context"
"fmt"
"log"

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

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