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

# Get Token by Customer ID

> Generate an API token for an onboarded customer using their customer_salt (Customer ID).

Use this endpoint to **generate an API token** for an onboarded customer using their `customer_salt` (Customer ID).

## Endpoint

**POST** `/users/gettokenbycustomerid`

**Content-Type:** `application/json`
**Authentication:** Required (API token)

## Request Body

```json theme={null}
{
  "customer_id": "048372910564",
  "name": "My API Token",
  "expiration_days": 30
}
```

### Parameters

| Parameter         | Type   | Required | Description                                                                                                                                                  |
| ----------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `customer_id`     | string | Yes      | The 12-digit customer identifier returned from the [Onboard User](/api-reference/users/onboard-user) endpoint. Also accepts `customerid` or `customer_salt`. |
| `name`            | string | No       | A friendly name for the token.                                                                                                                               |
| `expiration_days` | number | No       | Number of days until the token expires. If omitted, the token does not expire.                                                                               |

### Notes

* The `customer_id` must belong to an **active, non-blocked** user.
* The user must have at least one **active workspace**.
* If `expiration_days` is provided, it must be a **positive integer**.
* Each call generates a **new token** — previous tokens are not revoked.

## Success Response

```json theme={null}
{
  "message": "API token generated successfully",
  "customerid": "048372910564",
  "customer_api_key": "a1b2c3d4e5f6...generated_token_hex",
  "name": "My API Token",
  "expires": 1743033600
}
```

### Response Fields

| Field              | Type        | Description                                                        |
| ------------------ | ----------- | ------------------------------------------------------------------ |
| `customerid`       | string      | The customer identifier used in the request.                       |
| `customer_api_key` | string      | The newly generated API token.                                     |
| `name`             | string/null | The token name, if provided.                                       |
| `expires`          | number/null | Unix timestamp when the token expires, or `null` if no expiration. |

## Error Responses

| Error                     | Description                                                 |
| ------------------------- | ----------------------------------------------------------- |
| `CUSTOMER_ID_NOT_FOUND`   | No active user found with the given customer ID.            |
| `WORKSPACE_NOT_FOUND`     | The user does not have an active workspace.                 |
| `INVALID_EXPIRATION_DAYS` | The `expiration_days` value is not a valid positive number. |

## Example cURL

```bash theme={null}
curl -X POST https://www.tryunleashx.com/api/v1/global/users/gettokenbycustomerid \
  -H "Content-Type: application/json" \
  -H "Authorization: <api_key>" \
  -d '{
    "customer_id": "048372910564",
    "name": "My API Token",
    "expiration_days": 30
  }'
```


## OpenAPI

````yaml api-reference/openapi.json POST /users/gettokenbycustomerid
openapi: 3.1.0
info:
  title: >-
    UnleashX - Build human like conversations | Voice Agents | Automations | AI
    Workforce
  version: 1.0.0
  description: UnleashX - Your home for human like conversations
servers:
  - url: https://www.tryunleashx.com/api/v1/global/
security:
  - bearerAuth: []
paths:
  /users/gettokenbycustomerid:
    post:
      tags:
        - Users
      summary: Get token by customer ID
      description: >-
        Generate an API token for an onboarded customer using their
        customer_salt (Customer ID).
      parameters:
        - name: token
          in: header
          required: true
          description: API token for authentication
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - customer_id
              properties:
                customer_id:
                  type: string
                  description: >-
                    The 12-digit customer identifier returned from the
                    /users/onboard endpoint. Also accepts 'customerid' or
                    'customer_salt'.
                name:
                  type: string
                  description: A friendly name for the token
                expiration_days:
                  type: integer
                  minimum: 1
                  description: >-
                    Number of days until the token expires. If omitted, the
                    token does not expire.
      responses:
        '200':
          description: API token generated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  customerid:
                    type: string
                    description: The customer identifier used in the request
                  customer_api_key:
                    type: string
                    description: The newly generated API token
                  name:
                    type: string
                    nullable: true
                    description: The token name, if provided
                  expires:
                    type: integer
                    nullable: true
                    description: >-
                      Unix timestamp when the token expires, or null if no
                      expiration
        '400':
          description: >-
            Bad Request - CUSTOMER_ID_NOT_FOUND, WORKSPACE_NOT_FOUND, or
            INVALID_EXPIRATION_DAYS
        '401':
          description: Unauthorized
        '422':
          description: Validation error - customerid is required
      security: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````