# `client.CreateLicenseeAsync()`

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](/docs/api/create-licensee.md) for this endpoint.

This operation needs a Management Key. Pass it as the second argument to `new IdealPostcodesClient(apiKey, managementKey)`, or set `ManagementKey` in the options; the client sends it in the `Authorization` header. See [setup](/docs/sdks/dotnet/setup.md).

## Signature

```csharp
Task<LicenseeResponse> CreateLicenseeAsync(string key, CreateLicenseeBody body, CancellationToken cancellationToken = default)
```

## Arguments

| Name                | Type                 | Required | Description                                                        |
| ------------------- | -------------------- | -------- | ------------------------------------------------------------------ |
| `key`               | `string`             | yes      | API Key                                                            |
| `body`              | `CreateLicenseeBody` | yes      | The JSON request body. Fields under [Request Body](#request-body). |
| `cancellationToken` | `CancellationToken`  | no       | Cancels the request.                                               |

## Query Parameters

*None.*

## Request Body

Set these on the `body` argument. Each property is the name in PascalCase, such as `PostTown` for `post_town`; required fields are constructor arguments. A property left `null` is not sent.

| 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` | `IReadOnlyList<string>` | no       | A list of allowed URLs. An empty list disables the check.                                   |
| `daily`     | `CreateLicenseeDaily`   | no       |                                                                                             |

## Response

`LicenseeResponse`. Fields are properties in PascalCase, such as `response.Result`; fields this SDK version does not know are kept in `AdditionalProperties`. See [responses](/docs/sdks/dotnet/responses.md).

## Errors

An HTTP error throws `ApiException` with the `StatusCode`, the API error `Code` and the raw `Body`. A success response whose body cannot be read throws `UnserializableResponseException`. Network failures and cancellation throw `HttpClient`'s own `HttpRequestException` and `OperationCanceledException`. See [error handling](/docs/sdks/dotnet/errors.md).

## Example

create-licensee.cscsharp

```csharp
using IdealPostcodes;

using var client = new IdealPostcodesClient("ak_test", "uk_test");

var response = await client.CreateLicenseeAsync("ak_test", new CreateLicenseeBody
{
    Name = "Acme Ltd",
    Address = "9 Malyons Road, Swanley",
    Postcode = "BR8 7RE",
    Whitelist = ["https://www.acme.example"],
});

Console.WriteLine($"Licensee key: {response.Result.Key}");
```
