# Release a license

Removes the binding of the current device from a license. The device slot is then free for another device.

`POST /v1/licenses/release`

## When to release

Release the license when the user signs out, or when the user moves the license to another device. Then remove the stored license key from the device.

If your application stops without a release and the policy requires heartbeats, Seatify releases the device when its lease ends. See [Heartbeats and leases](../../../concepts/seats-and-devices/#heartbeats-and-leases).

If the device is lost, release its binding in the dashboard.

## Validity

A release does not check the license. It also works on an expired or suspended license. So a user can always move the license to a new device.

## Effects

- The device binding is removed. The device slot is free immediately, and another device can claim the license.
- The seat stays. The License API cannot release a seat. See [Seats](../../../concepts/seats-and-devices/#seats).
- The device stays in your account, because it can be bound to other licenses.
- The processes of the device end. See [Concurrent runs](../../../concepts/concurrent-runs/).
- A license file that the device checked out keeps working until it expires. See [Devices with no internet](../../../guides/offline-use/devices-with-no-internet/).
- Seatify records each release in the activity of the license, a refused one too. See [Activity](../../../concepts/activity/).

## Authentication

Send the publishable key of the product. See [Authentication](../../authentication/).

## Request

| Header | Required | Description |
| --- | --- | --- |
| `Seatify-Publishable-Key` | Yes | The publishable key of the product. |
| `Content-Type` | Yes | Always `application/json`. |
| `Seatify-Nonce` | No | A new random value that the signature includes. See [Signed responses](../../#signed-responses). |
| `Seatify-Signing-Key` | No | The key ID of the signing key in your application. See [Signed responses](../../#signed-responses). |

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `key` | string | Yes | The license key. |
| `device` | object | Yes | The device to release. A release always needs the device, whatever the policy. |

The `device` object has these fields:

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `fingerprint` | string | Yes | The fingerprint that the device sent in its claim. The fingerprint is case-sensitive. See [Devices](../../../concepts/seats-and-devices/#devices). |
| `hostname` | string | No | The name of the device. A release does not use the name. So your application can send the same `device` object as in the claim. |

A `device` object with no values counts as a missing device.

## Response

The answer is not a license check object. It has only these fields:

| Field | Type | Description |
| --- | --- | --- |
| `released` | boolean | `true` if Seatify removed the device binding. |
| `reason` | string | The cause when `released` is `false`. It is null when `released` is `true`. |

The answer does not show the state of the license. Validate the license to get it.

## Reasons

A refused release answers with the status 200, `released` set to `false` and a reason. The refused release does not change the license, its seats or its devices.

| Reason | Description |
| --- | --- |
| `license_not_found` | No license has this key. |
| `product_mismatch` | The license belongs to another product. |
| `not_claimed` | The device has no binding on this license. The device never claimed the license, it was released before, or its heartbeat lease has ended. It is also the answer when the policy does not bind devices. |

After `not_claimed`, the device holds no slot. Your application can remove the stored key as after a successful release.

See [Reasons](../#reasons).

## Errors

| Status | Reason | Description |
| --- | --- | --- |
| 400 | `The request body could not be read.` | The body is not valid JSON. |
| 400 | `The submitted details are not valid.` | A field is not valid. The `errors` field names it. See the table below. |
| 400 | `The signing key is not known.` | Your organization has no signing key with the ID in `Seatify-Signing-Key`. |
| 400 | `The nonce must be at most 255 characters.` | The value of `Seatify-Nonce` is too long. |
| 401 | `A publishable key is required.` | The request has no `Seatify-Publishable-Key` header, or the header is empty. |
| 401 | `The publishable key is not valid.` | No product has this key. |
| 429 | `There are too many requests. Try again later.` | See [Rate limits](../../#rate-limits). |

These fields can be in `errors`:

| Field | Description |
| --- | --- |
| `key` | The license key is missing or too long. |
| `device` | The request has no device. |
| `device.fingerprint` | The `device` object has no fingerprint, or the fingerprint is too long. |
| `device.hostname` | The hostname is too long. |

See [Errors](../../#errors).

## Example

{{< tabs >}}
{{< tab name="curl" >}}
```bash
curl https://license.seatify.dev/v1/licenses/release \
  -H "Seatify-Publishable-Key: $SEATIFY_PUBLISHABLE_KEY" \
  -H "Content-Type: application/json" \
  --data @- <<EOF
{
  "key": "$LICENSE_KEY",
  "device": { "fingerprint": "$DEVICE_FINGERPRINT" }
}
EOF
```
{{< /tab >}}
{{< tab name="Swift" >}}
```swift
import Foundation

struct ReleaseResult: Decodable {
    let released: Bool
    let reason: String?
}

let body: [String: Any] = [
    "key": licenseKey,
    "device": ["fingerprint": fingerprint],
]

var request = URLRequest(url: URL(string: "https://license.seatify.dev/v1/licenses/release")!)
request.httpMethod = "POST"
request.setValue(publishableKey, forHTTPHeaderField: "Seatify-Publishable-Key")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try JSONSerialization.data(withJSONObject: body)

let (data, _) = try await URLSession.shared.data(for: request)
let result = try JSONDecoder().decode(ReleaseResult.self, from: data)
```
{{< /tab >}}
{{< tab name="C#" >}}
```csharp
using System.Net.Http.Json;

using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Seatify-Publishable-Key", publishableKey);

var response = await client.PostAsJsonAsync("https://license.seatify.dev/v1/licenses/release", new
{
    key = licenseKey,
    device = new { fingerprint },
});
var result = await response.Content.ReadFromJsonAsync<ReleaseResult>();

record ReleaseResult(bool Released, string? Reason);
```
{{< /tab >}}
{{< tab name="Go" >}}
```go
body, err := json.Marshal(map[string]any{
	"key":    licenseKey,
	"device": map[string]string{"fingerprint": fingerprint},
})
if err != nil {
	return err
}

req, err := http.NewRequest("POST", "https://license.seatify.dev/v1/licenses/release", bytes.NewReader(body))
if err != nil {
	return err
}
req.Header.Set("Seatify-Publishable-Key", publishableKey)
req.Header.Set("Content-Type", "application/json")

res, err := http.DefaultClient.Do(req)
if err != nil {
	return err
}
defer res.Body.Close()

var result struct {
	Released bool    `json:"released"`
	Reason   *string `json:"reason"`
}
err = json.NewDecoder(res.Body).Decode(&result)
```
{{< /tab >}}
{{< tab name="JavaScript" >}}
```javascript
const response = await fetch("https://license.seatify.dev/v1/licenses/release", {
  method: "POST",
  headers: {
    "Seatify-Publishable-Key": publishableKey,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    key: licenseKey,
    device: { fingerprint },
  }),
});
const result = await response.json();
```
{{< /tab >}}
{{< /tabs >}}

```json
{
  "released": true,
  "reason": null
}
```

