# Authenticate with API Key

## Step by step

1. Create your user API Key and add permissions
   1. [#create-api-key](#create-api-key "mention")
2. Create a Signature
   1. [#create-a-signature](#create-a-signature "mention")
3. Authenticate via API&#x20;
   1. [#authenticate-via-api](#authenticate-via-api "mention")

## Create API KEY

Navigate through the admin UI to your user profile.

<figure><img src="/files/S9RKoNg8JFZMyrG6OIaA" alt=""><figcaption></figcaption></figure>

Click on the API KEYS option.

<figure><img src="/files/8THM9WwQIErIjNiKo39R" alt=""><figcaption></figcaption></figure>

Click on 'Create your API KEY'. You will see the following:

Depending on how you plan to use your API KEY, please choose from the available options. If you want to restrict usage by IP address, you can add the allowed IP in the designated field. Remember, you can always modify this later.

<figure><img src="/files/moMo5eSsgyRPQeQBcLLk" alt=""><figcaption></figcaption></figure>

When you click on 'Create API Key', you will see your API KEY, API SECRET, and NONCE displayed on screen only once. You can download them using the 'Export to JSON' button. It's very important to store them in a safe place, as you will need them later.

<figure><img src="/files/9bCyNOSEw3iYAsJeEcqi" alt=""><figcaption></figcaption></figure>

To save, click the button confirming that you've securely stored your credentials, then close the modal. Your new API KEY will now appear in the list, and you can edit or delete it as needed.

<figure><img src="/files/4CW8kpps2tyGwxt7z4Gx" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/mJn2JjI7dCYcoECCBIMT" alt=""><figcaption></figcaption></figure>

## Create a Signature

To generate a signature, you will need the API Secret, Nonce, User ID, and API Key, which are all generated, You can generate a signature by using a tool such as <https://codebeautify.org/hmac-generator> The algorithm will be SHA256, the Key will be the API Secret, and the plain text message will be composed of a combination the Nonce, User ID, and API key, in that exact order with no spaces. An example is listed below.

<figure><img src="/files/PIDkb5Tkc7sanijGOUsW" alt=""><figcaption></figcaption></figure>

## Authenticate via API

Follow the example in the image, add the APIKEY, Signature, UserId, and Nonce to the request headers, and call the `AuthenticateUser` endpoint. This will successfully authenticate you.

<figure><img src="/files/nYO0RWgOPrBkj1XQhc0H" alt=""><figcaption></figcaption></figure>

## POST /AuthenticateUser

> Authenticate user session

```json
{"openapi":"3.0.3","info":{"title":"Trading API","version":"1.0.0"},"servers":[{"url":"https://apstage.proxy.kiiex.io/ap","description":"Staging Environment"},{"url":"https://alphaprod.proxy.kiiex.io/ap","description":"Production Environment"}],"paths":{"/AuthenticateUser":{"post":{"summary":"Authenticate user session","operationId":"authenticateUser","requestBody":{"required":true,"content":{"application/json":{"schema":{"oneOf":[{"type":"object","properties":{"APIKey":{"type":"string"},"Signature":{"type":"string"},"UserId":{"type":"string"},"UserName":{"type":"string"},"Nonce":{"type":"string"}}}]}}}},"responses":{"200":{"description":"Authentication result","content":{"application/json":{"schema":{"type":"object","properties":{"authenticated":{"type":"boolean"},"user":{"type":"object","properties":{"userId":{"type":"integer"},"userName":{"type":"string"},"email":{"type":"string"},"emailVerified":{"type":"boolean"},"accountId":{"type":"integer"},"omsId":{"type":"integer"},"use2FA":{"type":"boolean"}}}}}}}}}}}}}
```

In the response, you will receive a session token. Use it in all subsequent requests by including it in the headers as the value of `aptoken`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.kiiglobal.io/docs/connect-to-kiiex/authenticate-with-api-key.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
