# Activate a license

```
POST 
https://api.freemius.com/v1/products/{product_id}/licenses/activate.json
```

<!-- -->

***

Activate a license and if needed, create an install with the given properties.

> No Authorization header is required. If the provided license doesn't have an associated user, the endpoint will require the `first_name`, `last_name`, and `user_email` parameters to create a new user and associate it with the license.

This endpoint can return the following error codes:

* `license_expired`: License has already expired.
* `invalid_license_key`: License key is invalid (e.g., does not match any record).
* `license_error`: General error while validating the license.
* `license_utilized`: License quota has reached maximum capacity.
* `license_activated`: License is already activated on the given install. This usually indicates your app is out of sync with Freemius. You may accept the license and grant premium features. If needed, re-establish the connection by calling the [deactivation endpoint](https://freemius.com/help/help/api/licenses/licenses/deactivate) and activating again.

All errors include a descriptive message from the API, which you may choose to display to the user. For example:

* `license_expired`: Your license has expired on 2025-01-01 (id = 12345).
* `invalid_license_key`: Invalid license key.
* `license_error`: License activation is not authorized for the site(s) listed below. Please follow the provided link to whitelist the site(s) from the User Dashboard.
* `license_activated`: License is already activated on install 12345.
* `license_utilized`: Your license quota of 1234 production site(s) has been reached. If you believe this is a mistake, please contact support at <example@freemius.com>.

You can get the error code from the `response.error.code`. For example

```
fetch(activationEndpoint).then((response) => {

    return response.json();

}).then((data) => {

    if (data.error) {

        // Error detected

        const errorCode = data.error.code;

        const errorMessage = data.error.message;

        // handleError(errorCode, errorMessage);

    } else {

        // Operation successful

    }

}).catch((error) => {

    // Handle network error

});
```

## Request[​](#request "Direct link to request")

### Path Parameters

* **product\_id**
  <!-- -->
  integer\<int64>[](#param-property-licenses-activate-param-path-product-id "Direct link to product_id")required

  The ID of the product.

  **Possible values:** `>= 1`

  **Example:<!-- -->&#x20;**`1234`

application/json

### Body**required**

* **uid**string\<uid>[](#schema-property-licenses-activate-request-body-uid-string-uid "Direct link to uid")required

  Unique identifier of the caller. The UID must be same when pinging and when activating or deactivating a license. The generation of the UID is a responsibility of the client.

  **Possible values:** `>= 32 characters` and `<= 32 characters`

  **Example:<!-- -->&#x20;**`7W131pej6bJYV8WYM9KgGoBNB9bCiSrY`

  **license\_key**string[](#schema-property-licenses-activate-request-body-license-key-string "Direct link to license_key")required

  The license key. This is used for activating the license on the user's site.

  **Example:<!-- -->&#x20;**`sk_123FGqM456Pa786WtOp%^+67Y+;sXXz`

  **url**string[](#schema-property-licenses-activate-request-body-url-string "Direct link to url")

  Site's homepage URL.

  **title**string[](#schema-property-licenses-activate-request-body-title-string "Direct link to title")

  Site's title.

  **version**string[](#schema-property-licenses-activate-request-body-version-string "Direct link to version")

  Product's version.

  **is\_marketing\_allowed**boolean[](#schema-property-licenses-activate-request-body-is-marketing-allowed-boolean "Direct link to is_marketing_allowed")nullable

  Whether or not the user has given their consent for marketing materials. A `null` value indicates that the user has not made a decision yet.

  **install\_id**integer[](#schema-property-licenses-activate-request-body-install-id-integer "Direct link to install_id")

  Install ID when activating on an already existing install. If provided must belong to the same user as the license owner and must have the same UID. The new license will be activated for the install and existing one will be deactivated.

  **first\_name**string[](#schema-property-licenses-activate-request-body-first-name-string "Direct link to first_name")

  First name of the user (only needed when activating a ghost license).

  **last\_name**string[](#schema-property-licenses-activate-request-body-last-name-string "Direct link to last_name")

  Last name of the user (only needed when activating a ghost license).

  **user\_email**string[](#schema-property-licenses-activate-request-body-user-email-string "Direct link to user_email")

  Email address of the user (only needed when activating a ghost license).

  **allow\_unreleased\_plan\_activation**boolean[](#schema-property-licenses-activate-request-body-allow-unreleased-plan-activation-boolean "Direct link to allow_unreleased_plan_activation")

  Whether to allow license activation if the plans of the product has not been released yet. Useful for testing purpose only.

## Responses[​](#responses "Direct link to Responses")

* 200
* 400
* 402
* 404

License activated successfully.

application/json

**Schema**

**user\_id**string\<int64>[](#schema-property-licenses-activate-response-schema-user-id-string-int64 "Direct link to user_id")

The unique identifier of the entity.

**Possible values:** `>= 1`

**Example:<!-- -->&#x20;**`123456`

**user\_secret\_key**string[](#schema-property-licenses-activate-response-schema-user-secret-key-string "Direct link to user_secret_key")

The secret key associated with the entity for authorization.

**Example:<!-- -->&#x20;**`sk_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6`

**user\_public\_key**string[](#schema-property-licenses-activate-response-schema-user-public-key-string "Direct link to user_public_key")

The public key associated with the entity for authorization.

**Example:<!-- -->&#x20;**`pk_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6`

**plugin\_id**string\<int64>[](#schema-property-licenses-activate-response-schema-plugin-id-string-int64 "Direct link to plugin_id")

The unique identifier of the entity.

**Possible values:** `>= 1`

**Example:<!-- -->&#x20;**`123456`

**license\_plan\_name**string\<slug>[](#schema-property-licenses-activate-response-schema-license-plan-name-string-slug "Direct link to license_plan_name")

The name of the plan. Only lowercase characters allowed.

**Example:<!-- -->&#x20;**`professional`

**license\_plan\_id**string\<int64>[](#schema-property-licenses-activate-response-schema-license-plan-id-string-int64 "Direct link to license_plan_id")

The ID of the plan associated with the entity.

**Possible values:** `>= 1`

**Example:<!-- -->&#x20;**`123456`

**license\_pricing\_id**string\<int64>[](#schema-property-licenses-activate-response-schema-license-pricing-id-string-int64 "Direct link to license_pricing_id")nullable

The ID of the pricing associated with the entity.

**Possible values:** `>= 1`

**Example:<!-- -->&#x20;**`123456`

**is\_marketing\_allowed**boolean[](#schema-property-licenses-activate-response-schema-is-marketing-allowed-boolean "Direct link to is_marketing_allowed")nullable

Whether or not the user has given their consent for marketing materials. A `null` value indicates that the user has not made a decision yet.

**install\_id**string\<int64>[](#schema-property-licenses-activate-response-schema-install-id-string-int64 "Direct link to install_id")

The unique identifier of the entity.

**Possible values:** `>= 1`

**Example:<!-- -->&#x20;**`123456`

**install\_secret\_key**string[](#schema-property-licenses-activate-response-schema-install-secret-key-string "Direct link to install_secret_key")

The secret key associated with the entity for authorization.

**Example:<!-- -->&#x20;**`sk_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6`

**install\_public\_key**string[](#schema-property-licenses-activate-response-schema-install-public-key-string "Direct link to install_public_key")

The public key associated with the entity for authorization.

**Example:<!-- -->&#x20;**`pk_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6`

**install\_api\_token**string[](#schema-property-licenses-activate-response-schema-install-api-token-string "Direct link to install_api_token")

The API access token with which authenticated requests can be made for this `install` entity. You need to set this token as the `Bearer` token in the `Authorization` header. For example:

Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9

**Example:<!-- -->&#x20;**`eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9`

Bad request. The request could not be understood by the server due to malformed syntax or arguments.

application/json

**Schema**

**path**string[](#schema-property-licenses-activate-response-schema-path-string "Direct link to path")

The API request path.

**Example:<!-- -->&#x20;**`:/products/product_id/users.json`

**error** <!-- -->object

This object contains the error details.

**type**string[](#schema-property-licenses-activate-response-schema-type-string "Direct link to type")

The type of the error encountered by the server.

**Example:<!-- -->&#x20;**`UnauthorizedAccess`

**message**string[](#schema-property-licenses-activate-response-schema-message-string "Direct link to message")

The descriptive error message.

**Example:<!-- -->&#x20;**`Some error has occured.`

**code**string[](#schema-property-licenses-activate-response-schema-code-string "Direct link to code")

The error code.

**Example:<!-- -->&#x20;**`unauthorized_access`

**http**integer[](#schema-property-licenses-activate-response-schema-http-integer "Direct link to http")

The HTTP status code returned by the server.

**Example:<!-- -->&#x20;**`401`

**timestamp**string[](#schema-property-licenses-activate-response-schema-timestamp-string "Direct link to timestamp")

Current timestamp.

**Example:<!-- -->&#x20;**`Thu, 11 May 2023 11:45:30 +0000`

**request** <!-- -->object

This object sends back the request payload as received by the server (both from path and from body or query).

**property name\***&#x61;ny[](#schema-property-licenses-activate-response-schema-property-name-any "Direct link to property name*")

This object sends back the request payload as received by the server (both from path and from body or query).

**Example:<!-- -->&#x20;**`{"beautify":true,"format":"json"}`

The request is missing the specified argument.

application/json

**Schema**

**path**string[](#schema-property-licenses-activate-response-schema-path-string "Direct link to path")

The API request path.

**Example:<!-- -->&#x20;**`:/products/product_id/users.json`

**error** <!-- -->object

This object contains the error details.

**type**string[](#schema-property-licenses-activate-response-schema-type-string "Direct link to type")

The type of the error encountered by the server.

**Example:<!-- -->&#x20;**`UnauthorizedAccess`

**message**string[](#schema-property-licenses-activate-response-schema-message-string "Direct link to message")

The descriptive error message.

**Example:<!-- -->&#x20;**`Some error has occured.`

**code**string[](#schema-property-licenses-activate-response-schema-code-string "Direct link to code")

The error code.

**Example:<!-- -->&#x20;**`unauthorized_access`

**http**integer[](#schema-property-licenses-activate-response-schema-http-integer "Direct link to http")

The HTTP status code returned by the server.

**Example:<!-- -->&#x20;**`401`

**timestamp**string[](#schema-property-licenses-activate-response-schema-timestamp-string "Direct link to timestamp")

Current timestamp.

**Example:<!-- -->&#x20;**`Thu, 11 May 2023 11:45:30 +0000`

**request** <!-- -->object

This object sends back the request payload as received by the server (both from path and from body or query).

**property name\***&#x61;ny[](#schema-property-licenses-activate-response-schema-property-name-any "Direct link to property name*")

This object sends back the request payload as received by the server (both from path and from body or query).

**Example:<!-- -->&#x20;**`{"beautify":true,"format":"json"}`

The requested resource was not found.

application/json

**Schema**

**path**string[](#schema-property-licenses-activate-response-schema-path-string "Direct link to path")

The API request path.

**Example:<!-- -->&#x20;**`:/products/product_id/users.json`

**error** <!-- -->object

This object contains the error details.

**type**string[](#schema-property-licenses-activate-response-schema-type-string "Direct link to type")

The type of the error encountered by the server.

**Example:<!-- -->&#x20;**`UnauthorizedAccess`

**message**string[](#schema-property-licenses-activate-response-schema-message-string "Direct link to message")

The descriptive error message.

**Example:<!-- -->&#x20;**`Some error has occured.`

**code**string[](#schema-property-licenses-activate-response-schema-code-string "Direct link to code")

The error code.

**Example:<!-- -->&#x20;**`unauthorized_access`

**http**integer[](#schema-property-licenses-activate-response-schema-http-integer "Direct link to http")

The HTTP status code returned by the server.

**Example:<!-- -->&#x20;**`401`

**timestamp**string[](#schema-property-licenses-activate-response-schema-timestamp-string "Direct link to timestamp")

Current timestamp.

**Example:<!-- -->&#x20;**`Thu, 11 May 2023 11:45:30 +0000`

**request** <!-- -->object

This object sends back the request payload as received by the server (both from path and from body or query).

**property name\***&#x61;ny[](#schema-property-licenses-activate-response-schema-property-name-any "Direct link to property name*")

This object sends back the request payload as received by the server (both from path and from body or query).

**Example:<!-- -->&#x20;**`{"beautify":true,"format":"json"}`
