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

# Create Admin JWT (Self-Hosted)

> Sign in as an admin and receive a JWT access token for self-hosted Databrain. Use this token for service token and admin APIs. Self-hosted only.

Sign in with an existing admin email and password to receive a JWT access token. Use this token in the `Authorization` header when calling admin-only endpoints such as [Create Service Token](/developer-docs/helpers/api-reference/create-service-token), [Rotate Service Token](/developer-docs/helpers/api-reference/rotate-service-token), and [Reset Admin Password](/developer-docs/helpers/api-reference/reset-admin-password).

<Warning>
  **Self-Hosted Only:** This endpoint is available only on **self-hosted** Databrain instances.
</Warning>

## Headers

<ParamField header="Content-Type" type="string" required>
  Must be `application/json` when sending a JSON body.

  ```
  Content-Type: application/json
  ```
</ParamField>

## Request Body

<ParamField body="email" type="string" required>
  Admin user's email address. Must be a valid email with at least two domain segments.
</ParamField>

<ParamField body="password" type="string" required>
  Admin user's password.
</ParamField>

## Response

On success, the API returns **200** with a JSON object:

<ResponseField name="data" type="object">
  Wrapper object for the response payload.
</ResponseField>

<ResponseField name="data.accessToken" type="string">
  JWT access token. Use as `Authorization: Bearer <accessToken>` for admin and service-token APIs.
</ResponseField>

On error, the API returns a JSON object with `error.code` and `error.message` and an appropriate HTTP status (400 or 500).

## Examples

<Panel>
  <RequestExample>
    ```bash cURL theme={"dark"}
    curl --request POST \
      --url https://api.usedatabrain.com/api/v2/admin-account/jwt \
      --header 'Content-Type: application/json' \
      --data '{"email":"admin@company.com","password":"SecureP@ss1"}'
    ```

    ```javascript Node.js icon="fa-brands fa-node-js" theme={"dark"}
    const response = await fetch('https://api.usedatabrain.com/api/v2/admin-account/jwt', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        email: 'admin@company.com',
        password: 'SecureP@ss1'
      })
    });
    const data = await response.json();
    if (data.error) throw new Error(data.error.message);
    const accessToken = data.data.accessToken;
    ```

    ```python Python icon="fa-brands fa-python" theme={"dark"}
    import requests

    url = "https://api.usedatabrain.com/api/v2/admin-account/jwt"
    headers = {"Content-Type": "application/json"}
    payload = {
        "email": "admin@company.com",
        "password": "SecureP@ss1"
    }

    response = requests.post(url, headers=headers, json=payload)
    data = response.json()
    if data.get("error"):
        raise Exception(data["error"].get("message", "Request failed"))
    access_token = data["data"]["accessToken"]
    ```
  </RequestExample>

  <ResponseExample>
    ```json Success (200) theme={"dark"}
    {
      "data": {
        "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
      }
    }
    ```

    ```json Error (400) - Wrong password theme={"dark"}
    {
      "error": {
        "code": "Invalid credentials",
        "message": "Invalid credentials"
      }
    }
    ```

    ```json Error (400) - User not found theme={"dark"}
    {
      "error": {
        "code": "USER_NOT_FOUND",
        "message": "No User found with the given email"
      }
    }
    ```

    ```json Error (500) theme={"dark"}
    {
      "error": {
        "code": "SELFHOSTED_APP_ERROR",
        "message": "This feature is only available for self-hosted instances"
      }
    }
    ```
  </ResponseExample>
</Panel>

## HTTP Status Code Summary

| Status Code | Description                                                        |
| ----------- | ------------------------------------------------------------------ |
| `200`       | **OK** – Access token returned in `data.accessToken`               |
| `400`       | **Bad Request** – Invalid credentials or validation error          |
| `500`       | **Internal Server Error** – Server error or self-hosted-only error |

## Possible Errors

| Code                    | Message                                                         | HTTP Status |
| ----------------------- | --------------------------------------------------------------- | ----------- |
| `USER_NOT_FOUND`        | No User found with the given email                              | 400         |
| `Invalid credentials`   | Invalid credentials (when password is incorrect or login fails) | 400         |
| `SELFHOSTED_APP_ERROR`  | This feature is only available for self-hosted instances        | 500         |
| `INTERNAL SERVER ERROR` | Connection Failure                                              | 500         |

## Related

* [Create Admin Account](/developer-docs/helpers/api-reference/create-admin-account) – Create the first admin account
* [Create Service Token](/developer-docs/helpers/api-reference/create-service-token) – Create a service token (requires this JWT)
* [Reset Admin Password](/developer-docs/helpers/api-reference/reset-admin-password) – Change admin password (requires this JWT)
