> For the complete documentation index, see [llms.txt](https://docs.licensespring.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.licensespring.com/license-api/license-activation-and-deactivation/activate-license-online-method.md).

# Activate License (Online Method)

### Endpoint

* Method: `POST`
* Path: `/api/v4/activate_license`
* Description: Activates a license for a device and returns the license payload.

### Authentication

These requests are authenticated and signed. See [License API Authorization](/license-api/license-api-authorization.md).

#### Required headers

* `Date` (string) — RFC7231 GMT date string (example: `Thu, 17 Nov 2022 20:51:35 GMT`)
* `Authorization` (string) — signature or bearer token (depending on auth method)

#### Recommended headers

* `Accept: application/json`
* `Content-Type: application/json`

### Request

#### Body parameters

Required:

* `hardware_id` (string) — Unique hardware ID generated for the client device
* `product` (string) — Product short code

One of (depending on product authorization method):

* `license_key` (string) — Required for key-based products
* `username` + `password` (string) — Required for user-based products
* `id_token` (use access\_token value) + `customer_account_code` (string) — Required for SSO Implicit grant
* `code` + `customer_account_code` (string) — Required for SSO Authorization Code grant

Optional:

* `license_id` (number) — Ensures the action affects only the license with this ID
* `app_ver` (string)
* `app_name` (string)
* `sdk_ver` (string)
* `variables` (object) — Device variables as a JSON object
* `redirect_uri` (string)
* `bundle_code` (string)
* `include_metadata_string` (boolean)

#### Minimal example (JSON)

```json
{
  "hardware_id": "some-unique-id",
  "product": "XY",
  "license_key": "AAAA-BBBB-CCCC-DDDD"
}
```

***

### Schema

#### Request Body

<details>

<summary><strong>Request schema (TypeScript + JSON Schema)</strong></summary>

**TypeScript**

```typescript
type LicenseActivationRequestBody = ({

  // for key-based licenses:
  license_key: string

} | {

  // for user-based licenses, using username & password authentication:
  username: string
  password: string

} | {

  // for user-based licenses, using single sign-on Implicit grant authentication:
  id_token: string
  customer_account_code: string

} | {

  // for user-based licenses, using single sign-on Authorization code grant authentication:
  code: string
  customer_account_code: string

}) & {

  // required properties:
  hardware_id: string
  product: string

  // optional properties:
  bundle_code?: string | undefined
  license_id?: number | undefined
  app_ver?: string | undefined
  app_name?: string | undefined
  sdk_ver?: string | undefined
  redirect_uri?: string | undefined
  include_metadata_string?: string | undefined
  variables?: { [key: string]: string } | undefined
}
```

**JSON Schema**

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "allOf": [
    {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "license_key": { "type": "string" }
          },
          "required": ["license_key"],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "username": { "type": "string" },
            "password": { "type": "string" }
          },
          "required": ["username", "password"],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "id_token": { "type": "string" },
            "customer_account_code": { "type": "string" }
          },
          "required": ["id_token", "customer_account_code"],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "code": { "type": "string" },
            "customer_account_code": { "type": "string" }
          },
          "required": ["code", "customer_account_code"],
          "additionalProperties": false
        }
      ]
    },
    {
      "type": "object",
      "properties": {
        "hardware_id": { "type": "string" },
        "product": { "type": "string" },
        "bundle_code": { "type": "string" },
        "redirect_uri": { "type": "string" },
        "license_id": { "type": "number" },
        "app_ver": { "type": "string" },
        "app_name": { "type": "string" },
        "sdk_ver": { "type": "string" },
        "include_metadata_string": { "type": "boolean" },
        "variables": {
          "type": ["object", "null"],
          "additionalProperties": { "type": "string" }
        }
      },
      "required": ["hardware_id", "product"],
      "additionalProperties": false
    }
  ]
}
```

</details>

***

#### Response Body

<details>

<summary><strong>Response schema (TypeScript + JSON Schema)</strong></summary>

Full response schemas are shared across activation endpoints. See [Activate License *Offline Method*](/license-api/license-activation-and-deactivation/activate-license-offline-method.md) for the complete response TypeScript shape.

**TypeScript**

```typescript
// See Activate License (Offline) for the full shape.
type LicenseActivationResponseBody = object;
```

**JSON Schema**

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "$comment": "See Activate License (Offline) for the full schema."
}
```

</details>

Response objects contain a `license_signature` value which the client app can use to verify authenticity (see [**Response Signature**](/license-api/license-api-authorization/response-signature.md)).

***

### License Authorization Method

There are two types of product licenses based on how the client application authorizes itself to interact with a license:

#### Key-based product licenses

Each license assigned to the product requires the client to provide a license key (license\_key) in order to activate, check or deactivate the license. The response will contain license\_key and product\_details.authorization\_method will be "license-key".

#### User-based product licenses

Each license has a corresponding "license user" instead of a license key. Ways to access:

* username & password
* id\_token (use access\_token value) & customer\_account\_code (SSO Implicit grant)
* code & customer\_account\_code (SSO Authorization code grant)

In the response, product\_details.authorization\_method will be "user" and the response will contain a user object.

***

### License Types

license\_type property values:

* Perpetual: perpetual
* Time-limited: time-limited
* Subscription: subscription
* Consumption: consumption

See: [License Types](/license-entitlements/license-types.md)

***

### Errors

If an error occurs, HTTP status will be 400 or higher and the response body will have:

```typescript
{
  status: number,
  code: string,
  message: string
}
```

JSON Schema

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "status": { "type": "number" },
    "code": { "type": "string" },
    "message": { "type": "string" }
  },
  "required": [
    "status",
    "code",
    "message"
  ],
  "additionalProperties": false
}
```

List of exceptions:

> unknown\_product (400): Provided product was not found

> license\_not\_found (400): License with the provided license user not found

> license\_not\_enabled (400): The license is not enabled

> vm\_not\_allowed (400): Virtual machine not allowed

> offline\_floating\_cloud\_not\_supported (400): Floating cloud licenses cannot be activated offline

> license\_start\_date\_error (400): This license cannot be activated before start date: {date}

> blacklisted (400): This device is blacklisted

> license\_activated\_max\_times (400): This license key has already been activated the maximum number of times

> license\_user\_activated\_max\_times (400): License user has activated this license max times

> license\_expired (400): License validity period has expired

> license\_transferred\_max\_times (400): This license has already been transferred the maximum number of times

> license\_device\_exists (409): A device matching this hardware\_id is already created on the license.

> product\_version\_not\_supported (400): License product version does not support the app\_ver sent in the request

***

### Examples

{% tabs %}
{% tab title="curl" %}

```bash
curl --location --request POST '/api/v4/activate_license' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Date: string' \
--header 'Authorization: string' \
--data-raw '{
  "hardware_id": "some-unique-id",
  "product": "XY",
  "license_key": "AAAA-BBBB-CCCC-DDDD"
}'
```

{% endtab %}

{% tab title="nodejs" %}

```javascript
var request = require('request');

var options = {
  method: 'POST',
  url: '/api/v4/activate_license',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
    'Date': 'string',
    'Authorization': 'string'
  },
  body: JSON.stringify({
    hardware_id: 'some-unique-id',
    product: 'XY',
    license_key: 'AAAA-BBBB-CCCC-DDDD'
  })
};

request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});
```

{% endtab %}

{% tab title="javascript (fetch)" %}

```javascript
var myHeaders = new Headers();
myHeaders.append("Accept", "application/json");
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Date", "string");
myHeaders.append("Authorization", "string");

var raw = JSON.stringify({
  hardware_id: "some-unique-id",
  product: "XY",
  license_key: "AAAA-BBBB-CCCC-DDDD"
});

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("/api/v4/activate_license", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
```

{% endtab %}

{% tab title="python" %}

```python
import requests

url = "/api/v4/activate_license"

payload = {
  "hardware_id": "some-unique-id",
  "product": "XY",
  "license_key": "AAAA-BBBB-CCCC-DDDD"
}

headers = {
  "Accept": "application/json",
  "Content-Type": "application/json",
  "Date": "string",
  "Authorization": "string"
}

response = requests.post(url, json=payload, headers=headers)
print(response.text)
```

{% endtab %}

{% tab title="ruby" %}

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

url = URI("/api/v4/activate_license")

http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Accept"] = "application/json"
request["Content-Type"] = "application/json"
request["Date"] = "string"
request["Authorization"] = "string"
request.body = JSON.dump({
  hardware_id: "some-unique-id",
  product: "XY",
  license_key: "AAAA-BBBB-CCCC-DDDD"
})

response = http.request(request)
puts response.read_body
```

{% endtab %}
{% endtabs %}

#### Single-Sign-On License Activation

{% hint style="info" %}
SSO setup and how to get the SSO URL: [Single Sign On URL](/license-api/single-sign-on-url.md).
{% endhint %}

```bash
curl --location --request POST 'https://api.licensespring.com/api/v4/activate_license/' \
--header 'Date: Mon, 10 May 2021 13:14:18 GMT' \
--header 'Authorization: algorithm="hmac-sha256",headers="date",signature="{generated_signature}",apikey="{your_api_key}"' \
--header 'Content-Type: application/json' \
--data-raw '{
    "id_token": "{access_token_here}",
  	"code": "{code_here}",
    "customer_account_code": "acme_inc",
    "hardware_id": "some-unique-id",
    "product": "XY"
}'
```

{% hint style="warning" %}
Use either id\_token or code, not both at the same time.
{% endhint %}

***

### Device Variables

The optional `variables` property lets you set device variables during activation. See [Device Variables](/license-api/device-variables.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.licensespring.com/license-api/license-activation-and-deactivation/activate-license-online-method.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
