> ## 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 Account (Self-Hosted)

> Create the first admin account for your self-hosted Databrain instance. Returns an access token for the new admin. Self-hosted only.

Create the initial admin user and company for a self-hosted deployment. On success, the API returns an access token that can be used for subsequent admin operations (e.g. creating a service token, managing Data Apps). Only one company can exist on a self-hosted instance; if an account already exists, sign in via [Create Admin JWT](/developer-docs/helpers/api-reference/create-admin-jwt) instead.

<Warning>
  **Self-Hosted Only:** This endpoint is available only on **self-hosted** Databrain instances. Calling it on cloud will return an error.
</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="firstName" type="string" required>
  Admin user's first name. Must be between **3 and 30 characters**.
</ParamField>

<ParamField body="email" type="string" required>
  Admin user's email address. Must be a valid email with at least two domain segments (e.g. `user@example.com`). Some common consumer email domains may be blocked (e.g. gmail, yahoo, outlook).
</ParamField>

<ParamField body="password" type="string" required>
  Password for the admin account. Must meet:

  * Minimum **8 characters**
  * At least **1 uppercase** letter
  * At least **1 lowercase** letter
  * At least **1 digit**
  * At least **1 special character**
  * **No spaces**
</ParamField>

<ParamField body="companyName" type="string" required>
  Name of the company/organization to create for this admin.
</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 for the newly created admin. Use this in the `Authorization: Bearer <accessToken>` header for admin APIs (e.g. [Create Service Token](/developer-docs/helpers/api-reference/create-service-token), [Reset Admin Password](/developer-docs/helpers/api-reference/reset-admin-password)).
</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 \
      --header 'Content-Type: application/json' \
      --data '{
        "firstName": "Admin",
        "email": "admin@company.com",
        "password": "SecureP@ss1",
        "companyName": "My Company"
      }'
    ```

    ```javascript Node.js icon="fa-brands fa-node-js" theme={"dark"}
    const response = await fetch('https://api.usedatabrain.com/api/v2/admin-account', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        firstName: 'Admin',
        email: 'admin@company.com',
        password: 'SecureP@ss1',
        companyName: 'My Company'
      })
    });
    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"
    headers = {"Content-Type": "application/json"}
    payload = {
        "firstName": "Admin",
        "email": "admin@company.com",
        "password": "SecureP@ss1",
        "companyName": "My Company"
    }

    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) - Validation (Joi) theme={"dark"}
    {
      "error": {
        "code": "INVALID REQUEST BODY",
        "message": "\"firstName\" is required"
      }
    }
    ```

    ```json Error (400) - Company already exists (self-hosted) theme={"dark"}
    {
      "error": {
        "code": "INVALID_REQUEST",
        "message": "Your company account is already created, please sign in"
      }
    }
    ```

    ```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** – Admin account created; `data.accessToken` returned                                                 |
| `400`       | **Bad Request** – Validation error (invalid email, weak password, missing fields) or company already exists |
| `500`       | **Internal Server Error** – Server error or self-hosted-only error                                          |

## Possible Errors

| Code                    | Message                                                                                                             | HTTP Status |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------- | ----------- |
| `INVALID REQUEST BODY`  | Joi validation message (e.g. `"firstName" is required`, `"password" should contain at least 1 uppercase character`) | 400         |
| `INVALID_REQUEST`       | Your company account is already created, please sign in                                                             | 400         |
| `SELFHOSTED_APP_ERROR`  | This feature is only available for self-hosted instances                                                            | 500         |
| `INTERNAL_SERVER_ERROR` | INTERNAL\_SERVER\_ERROR                                                                                             | 500         |

## Related

* [Create Admin JWT](/developer-docs/helpers/api-reference/create-admin-jwt) – Sign in and get an access token for an existing admin
* [Create Service Token](/developer-docs/helpers/api-reference/create-service-token) – Create a service token using the admin access token
* [Reset Admin Password](/developer-docs/helpers/api-reference/reset-admin-password) – Change password for the authenticated admin
