# Licenses

These endpoints claim, validate, release and check out a license from the device of your customer. This page describes the objects and the reasons that the endpoints share.

## Endpoints

| Endpoint | Path | Description |
| --- | --- | --- |
| [Claim](claim/) | `POST /v1/licenses/claim` | Takes a seat for the user and binds the device, if the policy binds them. |
| [Validate](validate/) | `POST /v1/licenses/validate` | Checks that the license can be used on this device. |
| [Heartbeat](heartbeat/) | `POST /v1/licenses/heartbeat` | Starts the lease of the device again. |
| [Release](release/) | `POST /v1/licenses/release` | Removes the binding of the device. |
| [Check out](check-out/) | `POST /v1/licenses/check-out` | Returns a signed license file for offline use. |

## Order of calls

1. Claim the license once, on the first run.
2. Validate the license on each start.
3. Send heartbeats while your application runs, if the policy requires them.
4. Release the license when the user signs out or moves to another device.

Check out a license file if your application must work without a network. See [Add your application](../../guides/licensing/add-your-application/) and [Offline validation](../../guides/offline-use/offline-validation/).

## License check object

Claim, validate and heartbeat answer with this object. The process endpoints [spawn](../processes/spawn/) and [heartbeat](../processes/heartbeat/) answer with it too. Release and check-out have their own answers.

| Field | Type | Description |
| --- | --- | --- |
| `valid` | boolean | `true` if your application can use the license. Your application must decide on this field. |
| `status` | string | The status of the license: `active`, `grace`, `expired` or `suspended`. See [Status and validity](#status-and-validity). |
| `expired` | boolean | `true` if the expiry date and the grace period have passed. |
| `reason` | string | The cause when `valid` is `false`. It is null when `valid` is `true`. See [Reasons](#reasons). |
| `license` | object | The license. See [License](#license). |
| `entitlements` | array | The entitlements of the license. See [Entitlements](#entitlements). |
| `limits` | object | The limits of the license. See [Limits](#limits). |
| `device` | object | The binding of the device. See [Device](#device). |
| `heartbeat` | object | The heartbeat settings of the policy. See [Heartbeat](#heartbeat). |
| `process` | object | The process of the request. It is null in the answers of the license endpoints. See [Processes](../processes/). |
| `process_heartbeat` | object | The process settings of the policy. See [Process heartbeat](#process-heartbeat). |

Every field is always in the answer. A field without a value is null. See [Refused answers](#refused-answers).

### License

| Field | Type | Description |
| --- | --- | --- |
| `id` | string | The ID of the license. |
| `name` | string | The name of the license. It is null if the license has no name. |
| `expires_at` | string | The expiry date of the license. It is null if the license has no expiry date. |
| `activated_at` | string | The time of the first claim. It is null if the license was never claimed. See [Activation](../../concepts/licenses/#activation). |

The answer never contains the license key.

### Entitlements

Each item of the array has these fields:

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | The code of the entitlement. Check this value in your application. |
| `name` | string | The name of the entitlement. |

The array holds the entitlements of the policy and the extra entitlements of the license. See [Entitlements](../../concepts/entitlements/).

### Limits

| Field | Type | Description |
| --- | --- | --- |
| `max_devices` | integer | The device limit. |
| `max_seats` | integer | The seat limit. |
| `max_processes` | integer | The limit on concurrent runs on each device. See [Concurrent runs](../../concepts/concurrent-runs/). |

Null means that there is no limit. The values include the overrides of the license. See [License overrides](../../concepts/policies/#license-overrides).

### Device

| Field | Type | Description |
| --- | --- | --- |
| `id` | string | The ID of the device binding. |
| `expires_at` | string | The end of the heartbeat lease. It is null if the policy does not require heartbeats. This is not the expiry date of the license. |

The `device` object is null if the policy does not bind devices. See [Heartbeats and leases](../../concepts/seats-and-devices/#heartbeats-and-leases).

### Heartbeat

| Field | Type | Description |
| --- | --- | --- |
| `required` | boolean | `true` if the policy requires heartbeats. |
| `interval_seconds` | integer | The number of seconds between two heartbeats. It is null if heartbeats are not required. |
| `grace_seconds` | integer | The extra seconds that the lease lasts after the interval. It is null if the policy has no heartbeat grace. |

### Process heartbeat

| Field | Type | Description |
| --- | --- | --- |
| `tracked` | boolean | `true` if Seatify counts the concurrent runs of your application. The process endpoints work only when this field is `true`. |
| `interval_seconds` | integer | The number of seconds between two process heartbeats. It is null if `tracked` is `false`. |
| `grace_seconds` | integer | The extra seconds that the process lease lasts after the interval. It is null if the policy has no process grace. |

## Refused answers

When `valid` is `false`, some fields have no value:

- An unknown license key, or a key of another product, answers only `valid`, `expired` and `reason`. The other objects are null, and `entitlements` is empty.
- Every other refusal also has `status`, `license`, `limits`, `heartbeat` and `process_heartbeat`. `entitlements` is empty, and `device` is null.

So your application can show the status of a suspended or expired license.

```json
{
  "valid": false,
  "status": null,
  "expired": false,
  "reason": "license_not_found",
  "license": null,
  "entitlements": [],
  "limits": null,
  "device": null,
  "heartbeat": null,
  "process": null,
  "process_heartbeat": null
}
```

## Status and validity

`status` and `valid` are two different things. `status` is the state of the license. `valid` says whether your application can use it now. For example, an expired license is still valid if the policy uses Keep access or Perpetual fallback. The answer then has `valid` and `expired` set to `true`.

Your application must decide on `valid`. It can show `status` to the user. See [Statuses](../../concepts/licenses/#statuses).

## Reasons

| Reason | Endpoints | Description |
| --- | --- | --- |
| `license_not_found` | All | No license has this key. |
| `product_mismatch` | All | The license belongs to another product than the publishable key. |
| `suspended` | Claim, validate, heartbeat, check-out | The license is suspended. |
| `expired` | Claim, validate, heartbeat, check-out | The license has expired, and the policy uses Expire. |
| `device_required` | Claim, validate, check-out | The policy binds devices, and the request has no device. |
| `customer_required` | Claim | The policy binds customers, and the request has no customer. |
| `device_limit_reached` | Claim | All device slots of the license are taken. |
| `seat_limit_reached` | Claim | All seats of the license are taken. |
| `not_claimed` | Validate, heartbeat, release, check-out | The device has no binding on this license. |
| `heartbeat_not_required` | Heartbeat | The policy does not require heartbeats. |
| `offline_validation_not_enabled` | Check-out | The policy does not allow offline validation. |

The process endpoints have more reasons. See [Processes](../processes/).

