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

# Key Lock

> This method will, given a license key, generate a new access token that is locked to that particular key and return the Id of that key. The scope of the access token is preserved...

This method will, given a license key, generate a new [access token](/api-reference/generated/Auth) that is locked to that particular key and return the Id of that key. The scope of the
[access token](/api-reference/generated/Auth) is preserved (i.e. all methods that were enabled in the access token used to access this method will be copied to the new access token)
except for the key lock, which is going to be changed to the id of the license key. Note, for this method to work, the access token used to access this method has to have key lock set to
**-1** or smaller. All of these details are described in [Remarks](/api-reference/generated/KeyLock#remarks).

This method is accessed by [https://api.cryptolens.io/api/auth/KeyLock](https://api.cryptolens.io/api/auth/KeyLock)

### Parameters

| **Parameter** | **Description** | **Remarks** |
| - | - | - |
| ProductId | the product id (=\*\*\[ProductId] \*\*) | required |
| Key | the serial key string | required |
| v | Method version. | optional. by default, it's 1. |

### Results

| **Parameter** | **Description** | **Remarks** |
| - | - | - |
| KeyId | The id of the license key (i.e. not the key string). | always returned |
| Token | The new [Access Token](/api-reference/generated/Auth). | always returned |
| Result | This is either **0**(=success) or **1**(=error). | always returned |
| Message | The message that provides additional information about the result. If it's a successful result, **null** will be returned. Otherwise, in case of an error, a short message will be returned describing the error. | always returned. |

### Example results

```text theme={null}
{"keyId":1005,"token":"WyIxOCIsIldGQlkyOHhXV2wrQkJaQVNaanJFV1pHdzZwVzZJQTVNK3M0UlphMFkiXQ==","result":0,"message":null}
```

### Remarks

* The [access token](/api-reference/generated/Auth) has to have the **Key Lock** set to **-1** or smaller for this method to work.
* This method does not require any explicit permission. If the **Key Lock** set to **-1** or smaller this method will be enabled.
* The new [access token](/api-reference/generated/Auth) will have the same permission on the methods. Only the **Key Lock** will be changed from being **-1** to the **KeyId** of the given key (in the input parameters).
* The [access token](/api-reference/generated/Auth) cannot be retrieved after generation. Please make sure to store it inside the app to avoid generating a new access token.
* The value of the KeyLock specifies the expiration date of the new access token, i.e. **-1** will set the expiration to **1 day** from the time the access token was generated. Similarly, setting it to **-2** will set the expiration date **2 days** from the time of the request.

### Errors

| **Error** |
| - |
| The Key Lock has to be set to '-1' for this method to work. |
| Could not find the product. |
| Could not find the key. |
