# Create Licensee

**POST** `/v1/keys/{key}/licensees`

Creates a licensee on a key and returns it with its generated `sl_` key. The key must be enabled for sub-licensing.

## Example request

**curl**

```bash
curl -X POST 'https://api.addresszen.com/v1/keys/ak_test/licensees?user_token=uk_secret' \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "Qwerty Widgets Limited",
    "address": "12 High Street, Manchester",
    "postcode": "BR8 7RE",
    "whitelist": [],
    "daily": {
      "limit": 10000
    }
  }'
```

**JavaScript**

```javascript
import { createZenClient, createLicensee } from '@addresszen/sdk';

const client = createZenClient({ apiKey: 'ak_test', userToken: 'uk_secret' });

const { data } = await createLicensee({
  client,
  path: { key: 'ak_test' },
  body: {
    name: 'Qwerty Widgets Limited',
    address: '12 High Street, Manchester',
    postcode: 'BR8 7RE',
    whitelist: [],
    daily: {
      limit: 10000,
    },
  },
});
```

**Python**

```python
# pip install addresszen
from addresszen import AddressZen

with AddressZen("ak_test") as client:
    result = client.create_licensee(
        "ak_test",
        user_token="uk_secret",
        name="Qwerty Widgets Limited",
        address="12 High Street, Manchester",
        postcode="BR8 7RE",
        whitelist=[],
        daily={"limit": 10000},
    )
```

**Ruby**

```ruby
require "net/http"
require "json"

uri = URI("https://api.addresszen.com/v1/keys/ak_test/licensees?user_token=uk_secret")
body = {
  name: "Qwerty Widgets Limited",
  address: "12 High Street, Manchester",
  postcode: "BR8 7RE",
  whitelist: [],
  daily: {
    limit: 10000,
  },
}
response = Net::HTTP.post(uri, body.to_json, "Content-Type" => "application/json")
result = JSON.parse(response.body)["result"]
```

**PHP**

```php
<?php
$ch = curl_init("https://api.addresszen.com/v1/keys/ak_test/licensees?user_token=uk_secret");
curl_setopt_array($ch, [
  CURLOPT_POST => true,
  CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
  CURLOPT_POSTFIELDS => json_encode([
    "name" => "Qwerty Widgets Limited",
    "address" => "12 High Street, Manchester",
    "postcode" => "BR8 7RE",
    "whitelist" => [],
    "daily" => [
      "limit" => 10000,
    ],
  ]),
  CURLOPT_RETURNTRANSFER => true,
]);
$result = json_decode(curl_exec($ch), true)["result"];
```

## Example body

```json
{
  "name": "Qwerty Widgets Limited",
  "address": "12 High Street, Manchester",
  "postcode": "BR8 7RE",
  "whitelist": [
    "https://www.example.com"
  ],
  "daily": {
    "limit": 10000
  }
}
```

## Example response

**200 OK**

```json
{
  "result": {
    "id": "56a11209ebe230380bf104c3",
    "key": "sl_ijoiqsxeQgXW2gkiE0X94",
    "createdAt": "2016-01-21T17:14:49.971Z",
    "name": "Qwerty Widgets Limited",
    "address": "12 High Street, Manchester",
    "postcode": "BR8 7RE",
    "whitelist": [
      "https://www.example.com"
    ],
    "daily": {
      "limit": 10000,
      "count": 232,
      "updatedAt": "2016-08-05T16:43:28.865Z"
    }
  },
  "code": 2000,
  "message": "Success"
}
```

## Path parameters

* `key` string

  **API Key**

  The API Key. Begins `ak_`.

  Example: `ak_test`

## Query parameters

* `user_token` string optional

  **Management Key**

  A secret key used to manage your account and API Keys. It was previously called the user token.

  Your management key can be retrieved and managed from your [accounts page](https://addresszen.com/account).

  Typically begins `uk_`. Prefer sending it in the `Authorization` header as `Bearer uk_...` instead of this query parameter. The `Authorization: user_token="uk_..."` header also works.

  Example: `uk_B59ScW1p1HHouf1VqclEPZUx`

## Request body

Submit a JSON object with the licensee details:

* `body` LicenseeEditable

  Licensee object which can be defined by user

  * `name` string optional

    Licensee individual or organisation name

    Example: `Qwerty Widgets Limited`

  * `address` string optional

    Licensee's first, second and third line address as well as post town concatenated by commas

    Example: `12 High Street, Manchester`

  * `postcode` string optional

    Licensee's postcode

    Example: `BR8 7RE`

  * `whitelist` string\[] optional

    A list of allowed URLs. An empty list disables the check.

    A request is allowed when its `Origin` or `Referer` header matches an entry. Use one of these formats:

    * `https://www.example.com` allows one site. Scheme and host must match
    * `*.example.com` allows the domain and all its subdomains

  * `daily` object optional

    * `limit` number optional

      The maximum number of lookups this licensee can perform in a day. `null` indicates the limit is not active

      Format: `int32`

      Example: `10000`

## Response

`result` is the created licensee object. Each licensee includes an immutable `id` and a unique `key` (beginning `sl_`) used for subsequent requests.

* `result` Licensee

  * `id` string

    An immutable ID provided for every licensee. Primarily used for paginated list requests.

    Example: `56a11209ebe230380bf104c3`

  * `key` string

    Uniquely identifies a licensee for a key.

    Required to perform paid lookups for a specific licensee. Typically begins `sl_`.

    Example: `sl_ijoiqsxeQgXW2gkiE0X94`

  * `createdAt` string

    Timestamp for when the licensee was created

    Example: `2016-01-21T17:14:49.971Z`

  * `name` string

    Licensee individual or organisation name

    Example: `Qwerty Widgets Limited`

  * `address` string

    Licensee's first, second and third line address as well as post town concatenated by commas

    Example: `12 High Street, Manchester`

  * `postcode` string

    Licensee's postcode

    Example: `BR8 7RE`

  * `whitelist` string\[]

    A list of allowed URLs. An empty list disables the check.

    A request is allowed when its `Origin` or `Referer` header matches an entry. Use one of these formats:

    * `https://www.example.com` allows one site. Scheme and host must match
    * `*.example.com` allows the domain and all its subdomains

  * `daily` object

    | Field       | Type   | Description                                                                                                                                   |
    | ----------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------- |
    | `limit`     | number | The maximum number of lookups this licensee can perform in a day. `null` indicates the limit is not active. Format: `int32`. Example: `10000` |
    | `count`     | number | The number of lookups performed by the licensee on the day represented by `licensees.daily.updatedAt`. Format: `int32`. Example: `232`        |
    | `updatedAt` | string | The timestamp when the limit was last used. Example: `2016-08-05T16:43:28.865Z`                                                               |

The `result` sits inside the standard `{ result, code, message }` envelope. See the [API reference](/docs/api/api-reference.md) for the wrapper format.
