# 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 `licensees()` methods create, list, update and cancel them.

Your key must be a sublicensing key; [contact us](https://ideal-postcodes.co.uk/contact-us) to convert one. Every method needs a [Management Key](/docs/sdks/php/setup.md#when-do-i-need-a-management-key).

## How do I 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.phpphp

```php
use IdealPostcodes\IdealPostcodes;

$client = IdealPostcodes::client('ak_test', getenv('IDPC_MANAGEMENT_KEY'));
$licensee = $client->createLicensee('ak_test', [
    'name' => 'Example Ltd',
    'address' => '9 Malyons Road, Swanley',
    'postcode' => 'BR8 7RE',
    'whitelist' => ['https://www.example.com'],
])->result;

echo $licensee->id, ' ', $licensee->key, PHP_EOL;
```

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

## How do I list licensees?

`listLicensees()` returns 10 per call by default and up to 100 with `limit`, oldest first, without cancelled ones. To fetch the next page, pass the last licensee's `id` as `starting_after`. `hasMore` says whether another page exists.

list.phpphp

```php
use IdealPostcodes\IdealPostcodes;

$client = IdealPostcodes::client('ak_test', getenv('IDPC_MANAGEMENT_KEY'));
$params = ['limit' => 100];

do {
    $page = $client->listLicensees('ak_test', $params)->result;
    foreach ($page->licensees as $licensee) {
        echo $licensee->name, ': ', $licensee->daily->count, ' lookups today', PHP_EOL;
        $params['starting_after'] = $licensee->id;
    }
} while ($page->hasMore);
```

## How do I change or cancel one?

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`.

## How is a licensee billed?

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 passing `licensee` to `keyUsage()` or `keyLogs()`. See [API keys](/docs/sdks/php/keys.md).

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