# API Key Management

The API-Key Management APIs provide interface to manage API Keys. This is helpful if you need to maintain different sets of API Keys for different users/accounts on your platform.

## Create new API Key

<mark style="color:green;">`POST`</mark> `https://api.clik.ai/smart-extract-api/api/account/v1/api-keys`

This API lets you create a new API Key.&#x20;

#### Headers

| Name          | Type   | Description                           |
| ------------- | ------ | ------------------------------------- |
| Authorization | String | Basic <*base 64 encoded credentials*> |

#### Request Body

| Name                                      | Type      | Description                                                                                                                                                                                                         |
| ----------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name<mark style="color:red;">\*</mark>    | string    | Name of the API Key                                                                                                                                                                                                 |
| enabled<mark style="color:red;">\*</mark> | boolean   | Create the API Key in enabled/disabled state                                                                                                                                                                        |
| roles<mark style="color:red;">\*</mark>   | string\[] | <p>List of roles to attach to the API Key. </p><p>DATA\_EXTRACTION - Allows the API Key access to data extraction APIs</p><p>ADMIN\_ROLE - Allows the API Key access to admin APIs e.g. API Keys Management API</p> |

{% tabs %}
{% tab title="401: Unauthorized When API Key credentials used don't have Admin role assigned" %}

```javascript
{
    "status": "error",
    "type": "unauthorizedApiKeyError",
    "error": {
        "message": "The API Key used does not have privilege to perform the intended action"
    }
}
```

{% endtab %}

{% tab title="201: Created API Key created successfully" %}

```javascript
{
    "apiKey": {
        "enabled": true,
        "key": "52ee4d982ee6b2e0432f10c4d03a1b8a",
        "name": "xyz",
        "roles": [
            "DATA_EXTRACTION"
        ],
        "id": "84af7719-202f-430f-8d33-fdf0a7220b14",
        "createdAt": "2021-11-25T06:20:16.829Z",
        "updatedAt": "2021-11-25T06:20:16.829Z",
        "secret": "9156a891d9d21fa98e9c54cf62815d46"
    }
}
```

{% endtab %}
{% endtabs %}

## List API Keys

<mark style="color:blue;">`GET`</mark> `https://api.clik.ai/smart-extract-api/api/account/v1/api-keys`

This API returns a list of API Keys in the system

#### Query Parameters

| Name     | Type   | Description                                             |
| -------- | ------ | ------------------------------------------------------- |
| page     | number | API Keys list response page. Defaults to 1              |
| pageSize | number | Number of records to return for a page. Defaults to 100 |

{% tabs %}
{% tab title="401: Unauthorized When API Key credentials used don't have Admin role assigned" %}

```javascript
{
    "status": "error",
    "type": "unauthorizedApiKeyError",
    "error": {
        "message": "The API Key used does not have privilege to perform the intended action"
    }
}
```

{% endtab %}

{% tab title="200: OK Returns list of API Keys" %}

```javascript
{
    "apiKeys": [
        {
            "id": "0300d235-87cb-4563-acb3-1825dbe34069",
            "enabled": true,
            "name": "Test Key 1",
            "key": "7d0878b65ff21abb875a64586ea9366e",
            "createdAt": "2021-11-16T09:32:07.456Z",
            "updatedAt": "2021-11-16T09:32:07.456Z",
            "roles": [
                "ADMIN_ROLE"
            ]
        },
        {
            "id": "13d2e1b5-45ff-436d-ac98-3a94670b3cf2",
            "enabled": true,
            "name": "Test Key 2",
            "key": "fc9fb2c051f2be65c6faef47f3758148",
            "createdAt": "2021-11-16T08:52:30.260Z",
            "updatedAt": "2021-11-16T08:52:30.260Z",
            "roles": [
                "DATA_EXTRACTION",
            ]
        }
    ],
    "page": 1,
    "pageSize": 100
}
```

{% endtab %}
{% endtabs %}

## Update an API Key

<mark style="color:purple;">`PATCH`</mark> `https://api.clik.ai/smart-extract-api/api/account/v1/api-keys/{apiKeyId}`

This API updates an API Key's name, enabled status and roles

#### Path Parameters

| Name                                       | Type   | Description           |
| ------------------------------------------ | ------ | --------------------- |
| apiKeyId<mark style="color:red;">\*</mark> | string | The id of the API Key |

#### Request Body

| Name    | Type      | Description                                                                        |
| ------- | --------- | ---------------------------------------------------------------------------------- |
| name    | string    | The name of the API Key                                                            |
| enabled | string    | The enabled status of the API Key                                                  |
| roles   | string\[] | Roles to assign to the API Key. Valid roles are `ADMIN_ROLE` and `DATA_EXTRACTION` |

{% tabs %}
{% tab title="200: OK Returns the updated API Key details" %}

```javascript
{
    "apiKey": {
        "id": "0300d235-87cb-4563-acb3-1825dbe34069",
        "enabled": true,
        "name": "Test API Key",
        "key": "7d0878b65ff21abb875a64586ea9366e",
        "createdAt": "2021-11-16T09:32:07.456Z",
        "updatedAt": "2021-11-25T06:34:31.000Z",
        "roles": [
            "DATA_EXTRACTION",
            "ADMIN_ROLE"
        ]
    }
}
```

{% endtab %}
{% endtabs %}

## Delete an API Key

<mark style="color:red;">`DELETE`</mark> `https://api.clik.ai/smart-extract-api/api/account/v1/api-keys/{apiKeyId}`

Deletes an API Key from the account

#### Path Parameters

| Name     | Type   | Description                         |
| -------- | ------ | ----------------------------------- |
| apiKeyId | string | The id of the API Key to be deleted |

{% tabs %}
{% tab title="200: OK Has empty response body" %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}

## Gets API Key details

<mark style="color:blue;">`GET`</mark> `https://api.clik.ai/smart-extract-api/api/account/v1/api-keys/{apiKeyId}`

Returns details for an API Key

#### Path Parameters

| Name     | Type   | Description    |
| -------- | ------ | -------------- |
| apiKeyId | string | The API Key id |

{% tabs %}
{% tab title="200: OK The API Key details" %}

```javascript
{
    "apiKey": {
        "id": "13d2e1b5-45ff-436d-ac98-3a94670b3cf2",
        "enabled": true,
        "name": "Test API Key",
        "key": "fc9fb2c051f2be65c6faef47f3758148",
        "createdAt": "2021-11-16T08:52:30.260Z",
        "updatedAt": "2021-11-16T08:52:30.260Z",
        "roles": [
            "DATA_EXTRACTION",
            "ADMIN_ROLE"
        ]
    }
}
```

{% endtab %}
{% endtabs %}
