$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 as the second argument to IdealPostcodes::client(), which sends it in the Authorization header. See setup.
Signature
public function createLicensee(string $key, array $body): LicenseeResponse
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
$key | string | yes | API Key |
$body | array | yes | The JSON request body. Keys under Request Body. |
Query Parameters
None.
Request Body
Pass these as keys of $body.
| Name | Type | Required | Description |
|---|---|---|---|
name | string | no | Licensee individual or organisation name |
address | string | no | Licensee's first, second and third line address as well as post town concatenated by commas |
postcode | string | no | Licensee's postcode |
whitelist | string|list<string> | no | A list of allowed URLs. An empty list disables the check. |
daily | array<string, mixed> | no |
Response
IdealPostcodes\Responses\LicenseeResponse. Read fields as properties, such as $response->result, or as an array with the API's field names. toArray() returns the decoded body.
Errors
An HTTP error throws ApiException with the HTTP status, the API error code from getCode() and the decoded body. A transport failure throws TransporterException. See error handling.
Example
create-licensee.phpphp
<?php
declare(strict_types=1);
use IdealPostcodes\IdealPostcodes;
require 'vendor/autoload.php';
$client = IdealPostcodes::client('ak_test', 'uk_test');
$response = $client->createLicensee('ak_test', [
'name' => 'Acme Ltd',
'address' => '9 Malyons Road, Swanley',
'postcode' => 'BR8 7RE',
'whitelist' => ['https://www.acme.example'],
]);
echo 'Licensee key: ', $response->result->key, PHP_EOL;