# `client.create_licensee`

Create

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

## 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 `management_key:` to `AddressZen::Client.new`, which sends it in the `Authorization` header. See [setup](/docs/sdks/ruby/setup.md).

## Signature

```ruby
def create_licensee(key, name: nil, address: nil, postcode: nil, whitelist: nil, daily: nil)
```

## Arguments

| Name       | Type                | Required | Description                                                                                                |
| ---------- | ------------------- | -------- | ---------------------------------------------------------------------------------------------------------- |
| `key`      | `String`            | yes      | API Key                                                                                                    |
| `keywords` | `keyword arguments` | no       | One per [body field](#request-body), named as the API names them. A keyword left out or `nil` is not sent. |

## Query Parameters

*None.*

## Request Body

Pass these as keyword arguments too; the SDK sends them as the JSON 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` | `Array<String>` | no       | A list of allowed URLs. An empty list disables the check.                                   |
| `daily`     | `Hash`          | no       |                                                                                             |

## Response

`AddressZen::Responses::LicenseeResponse`. Read fields with readers named as the API names them, such as `response.result`, or with `response["result"]`. `to_h` returns the decoded body.

## Errors

An HTTP error raises `AddressZen::ApiError` with the HTTP `status`, the API error `code` and the decoded `body`. A transport failure raises `AddressZen::TransportError`. See [error handling](/docs/sdks/ruby/errors.md).

## Example

create-licensee.rbruby

```ruby
require "addresszen"

client = AddressZen::Client.new(api_key: "ak_test", management_key: "uk_test")

response = client.create_licensee(
  "ak_test",
  name: "Acme Inc",
  address: "1010 Cauthen Ln, Alamogordo, NM",
  postcode: "88310",
  whitelist: ["https://www.acme.example"]
)

puts "Licensee key: #{response.result.key}"
```
