# Managing API Key Management

This page explains in detail the process for generating a token using the API key management feature. The resulting token can then be used to execute various API calls across the SSD platform.

#### API Overview

The API requirements for this process are given below:

* Endpoint: https\://\<SSD-TENANT-URL>/gate/tokens/usertokenkens/usertoken
* Method: GET
* Authentication: API Key (To be generated from SSD UI)
* Output: User Token (JWT)

### Prerequisites

To generate a token, ensure the following requirements are met:

* A valid **OpsMx API key** (generated from the SSD UI)
* Network access to **OpsMx services**
* **curl** installed on the system

### To Generate the API Key from SSD

The API key essentially overloads the existing role concept within their RBAC system. Creating an API key generates a unique role associated with the selected teams and permissions. This role is then used in the token generation process, ensuring the token inherits the appropriate access permissions defined by the associated teams and roles.

* Navigate to **Setup** > **API Key Management**. The API Key Management page appears.

<figure><img src="https://2047464521-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MBEa1hoX6SqpDj-ymNs%2Fuploads%2FcQtrYoSx50swWfOATOz0%2FAPI%201.png?alt=media&#x26;token=fb467a6e-51f1-4c46-bd3a-3d8ebcb25e86" alt=""><figcaption></figcaption></figure>

1. Click **Add API Key**.

<figure><img src="https://2047464521-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MBEa1hoX6SqpDj-ymNs%2Fuploads%2F0Gjn5CZHIinEnjNC7Hnc%2FAPI%202.png?alt=media&#x26;token=d47e5242-3887-4411-9e32-a50d216aa17b" alt=""><figcaption></figcaption></figure>

2. In the expanded section, enter the values for the following fields:
3. **Name** - Enter a name for the API key.&#x20;
4. **Team** - Select the team to which you want this API key to be created for.&#x20;
5. **Permission** - Select the permission type (Read, Write, Admin) for the API key.&#x20;
6. **Expires In** - Select the time limit till which you want the API key to be valid.&#x20;
7. Click **Create**.

The API key is generate in the form page, and a confirmation message is displayed as given: **API Key Created successfully!**

<figure><img src="https://2047464521-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MBEa1hoX6SqpDj-ymNs%2Fuploads%2FpBWyrTiXTHWWq0C0VzvU%2FAPI%203.png?alt=media&#x26;token=f9646677-c300-47a8-987f-c9bbcd51f0ec" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Save this API key securely for subsequent use in the curl command to generate the access token.
{% endhint %}

### To Edit the API Key

&#x20;The API key details can be updated. To edit the details of the API key,&#x20;

* Click **three dots** in the **Actions** column corresponding to the required API key.&#x20;
* Click **Edit**.

<figure><img src="https://2047464521-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MBEa1hoX6SqpDj-ymNs%2Fuploads%2FVComqM3Ap3FW6lALgcA5%2FAPI%20actions.png?alt=media&#x26;token=6dea43f9-210e-4d79-bce8-e586e2076a4f" alt=""><figcaption></figcaption></figure>

* Update the API key's Name, associated Teams, and Permission levels (read, write, or admin) as needed.
* Click **Update**.&#x20;

### To Regenerate the API Key

&#x20;The API key details can be regenerated. To regenerate the details of the API key,&#x20;

* Click **three dots** in the **Actions** column corresponding to the required API key.&#x20;

<figure><img src="https://2047464521-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MBEa1hoX6SqpDj-ymNs%2Fuploads%2Fjmpa9LtVP8DQeyUXdTzy%2Fimage.png?alt=media&#x26;token=d4e0a9e2-214e-4a44-be20-fd7c707e45bc" alt=""><figcaption></figcaption></figure>

* Click **Regenerate**. This option enables the user to create a new API key instantly, typically used when the existing key is lost.

### To Delete the API Key

&#x20;The API key details can be deleted. To delete the API key,&#x20;

* Click **three dots** in the **Actions** column corresponding to the required API key.&#x20;

<figure><img src="https://2047464521-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MBEa1hoX6SqpDj-ymNs%2Fuploads%2FwyDPAN92JGEJt4mPOyn8%2Fimage.png?alt=media&#x26;token=6620ab03-dcfa-4c13-a11d-dfbbf2c12a88" alt=""><figcaption></figcaption></figure>

* Click **Delete**. The created API key is removed.

### To Obtain API Token using Curl Command

1. Obtain API key from SSD (Steps are mentioned above).
2. Store API key securely.
3. Execute the following curl command.

{% code overflow="wrap" %}

```
curl --location 'https://<SSD-TENANT-URL>/gate/tokens/usertokenkens/usertoken' --header 'X-OpsMx-ApiKey: <API_KEY>'
```

{% endcode %}

4. Save the returned token.

{% code overflow="wrap" %}

```
"eyJhbGciOiJSUzI1NiIsImtpZCI6IjAwMjRkOTRlLTRmZjgtNDgxOC1iM2UyLTUwODNiMTQ5MGFlNiIsInR5cCI6IkpXVCJ9.eyJpc3iOiJPcHNNeCIsImF1ZCI6WyJzc2Qub3BzbXguaW8iXSwiZXhwIjoxNzY2MTMzMjYxLCJuYmYiOjE3NjYw.."
```

{% endcode %}

<br>

<br>

\ <br>
