> ## Documentation Index
> Fetch the complete documentation index at: https://chariow.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Activate License

> Activate a license on a device

Activates a license for a device by recording activation details and incrementing the activation count. The system automatically captures the requesting IP address and user agent. On the first activation, the license status changes from `pending_activation` to `active`, and the expiration date is calculated based on the product's validity period settings.

Each activation is tracked individually, allowing you to view the complete activation history. The license cannot be activated if it has been revoked, has expired, or if the maximum activation limit has been reached.

## Path Parameters

<ParamField path="licenseKey" type="string" required>
  The license key to activate (e.g., `ABC-123-XYZ-789`)
</ParamField>

## Request Body

<ParamField body="device_identifier" type="string">
  Optional unique identifier for the device (e.g., MAC address, hardware UUID, machine ID). Max 255 characters.
</ParamField>

<Note>
  The IP address and user agent are automatically captured from the request and do not need to be provided.
</Note>

## Response

<ResponseField name="data" type="object">
  <Expandable title="properties">
    <ResponseField name="id" type="string">
      Unique license identifier
    </ResponseField>

    <ResponseField name="license_key" type="string">
      The license key string
    </ResponseField>

    <ResponseField name="status" type="string">
      License status (will be `active` after successful activation)
    </ResponseField>

    <ResponseField name="activated_at" type="string">
      ISO 8601 timestamp when first activated
    </ResponseField>

    <ResponseField name="expires_at" type="string">
      ISO 8601 expiration timestamp (calculated on first activation)
    </ResponseField>

    <ResponseField name="activation_count" type="integer">
      Current number of activations (incremented)
    </ResponseField>

    <ResponseField name="max_activations" type="integer">
      Maximum number of activations allowed
    </ResponseField>

    <ResponseField name="activations_remaining" type="integer">
      Number of activations remaining
    </ResponseField>

    <ResponseField name="is_active" type="boolean">
      Whether the license is currently active
    </ResponseField>

    <ResponseField name="can_activate" type="boolean">
      Whether the license can be activated again
    </ResponseField>

    <ResponseField name="product" type="object">
      Product information
    </ResponseField>
  </Expandable>
</ResponseField>

## Error Responses

<ResponseField name="400 Bad Request" type="object">
  Returned when:

  * License has been revoked
  * License has expired
  * Activation limit has been reached
</ResponseField>

<ResponseField name="404 Not Found" type="object">
  Returned when the license key doesn't exist or doesn't belong to your store
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.chariow.com/v1/licenses/ABC-123-XYZ-789/activate" \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "device_identifier": "00:1B:44:11:3A:B7"
    }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch(
    'https://api.chariow.com/v1/licenses/ABC-123-XYZ-789/activate',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        device_identifier: '00:1B:44:11:3A:B7'
      })
    }
  );
  const data = await response.json();
  ```

  ```php PHP theme={null}
  $ch = curl_init('https://api.chariow.com/v1/licenses/ABC-123-XYZ-789/activate');
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
      'Authorization: Bearer YOUR_API_KEY',
      'Content-Type: application/json'
  ]);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
      'device_identifier' => '00:1B:44:11:3A:B7'
  ]));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  $response = curl_exec($ch);
  ```
</RequestExample>

<ResponseExample>
  ```json Success (200) theme={null}
  {
    "message": "License activated successfully",
    "data": {
      "id": "lic_abc123",
      "sale_id": 156,
      "customer_id": 89,
      "license_key": "ABC-123-XYZ-789",
      "status": "active",
      "activated_at": "2025-01-15T10:30:00.000000Z",
      "expires_at": "2026-01-15T10:30:00.000000Z",
      "expired_at": null,
      "revoked_at": null,
      "activation_count": 1,
      "max_activations": 10,
      "activations_remaining": 9,
      "is_active": true,
      "is_expired": false,
      "can_activate": true,
      "metadata": null,
      "created_at": "2025-01-15T09:00:00.000000Z",
      "updated_at": "2025-01-15T10:30:00.000000Z",
      "product": {
        "id": 42,
        "name": "Premium Software License"
      }
    },
    "errors": []
  }
  ```

  ```json License Revoked (400) theme={null}
  {
    "message": "License has been revoked",
    "data": [],
    "errors": []
  }
  ```

  ```json Activation Limit Reached (400) theme={null}
  {
    "message": "Activation limit reached",
    "data": [],
    "errors": []
  }
  ```

  ```json License Expired (400) theme={null}
  {
    "message": "License has expired",
    "data": [],
    "errors": []
  }
  ```

  ```json License Not Found (404) theme={null}
  {
    "message": "No query results for model [App\\Models\\IssuedLicense].",
    "data": [],
    "errors": []
  }
  ```
</ResponseExample>

## Implementation Notes

### First Activation

When a license is activated for the first time:

* Status changes from `pending_activation` to `active`
* `activated_at` is set to the current timestamp
* `expires_at` is calculated based on the product's validity period (if configured)

### Subsequent Activations

* `activation_count` is incremented
* A new activation record is created in the activation history
* The license status remains `active`

### Device Tracking

Each activation is tracked with:

* `device_identifier` (optional, provided by you)
* `activated_by_ip` (automatically captured)
* `user_agent` (automatically captured)
* `created_at` (timestamp of activation)

You can retrieve the full activation history using the [Get License Activations](/api-reference/licenses/get-activations) endpoint.

## Example: Desktop Application

```javascript theme={null}
class LicenseActivator {
  constructor(apiKey) {
    this.apiKey = apiKey;
    this.baseUrl = 'https://api.chariow.com/v1';
  }

  async activate(licenseKey) {
    // Get unique device identifier
    const deviceId = this.getDeviceIdentifier();

    try {
      const response = await fetch(
        `${this.baseUrl}/licenses/${licenseKey}/activate`,
        {
          method: 'POST',
          headers: {
            'Authorization': `Bearer ${this.apiKey}`,
            'Content-Type': 'application/json'
          },
          body: JSON.stringify({
            device_identifier: deviceId
          })
        }
      );

      if (!response.ok) {
        const error = await response.json();
        throw new Error(error.message);
      }

      const result = await response.json();
      console.log('License activated successfully');
      console.log(`Activations remaining: ${result.data.activations_remaining}`);

      return result.data;
    } catch (error) {
      console.error('Activation failed:', error.message);
      throw error;
    }
  }

  getDeviceIdentifier() {
    // Implementation depends on your platform
    // Examples: MAC address, hardware UUID, machine ID
    return 'unique-device-id-here';
  }
}

// Usage
const activator = new LicenseActivator('sk_live_your_api_key');
await activator.activate('ABC-123-XYZ-789');
```
