> For the complete documentation index, see [llms.txt](https://docs.violet.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.violet.io/concepts/overview/obtaining-api-token.md).

# Initial Authentication

| Field    | Description                                                                                           |
| -------- | ----------------------------------------------------------------------------------------------------- |
| username | Username for your Violet account created on channel.violet.io (this is your email you signed up with) |
| password | Password for your Violet account you created on channel.violet.io                                     |

#### Making the Login Request

The first call to Violet that needs to be made is the /login call, to authenticate your Violet Account and credentials and retrieve an authentication token.

**Endpoint**: `POST /login`

**Required Headers**:

```http
X-Violet-App-Id: your-app-id-here
X-Violet-App-Secret: your-app-secret-here
Content-Type: application/json
```

**Request Body**

```json
{
  "username": "your-email@example.com",  
  "password": "your-password"
}
```

#### Sample Code

{% tabs %}
{% tab title="Bash" %}

```bash
curl -X POST https://sandbox-api.violet.io/v1/login \
  -H "X-Violet-App-Id: your-app-id-here" \
  -H "X-Violet-App-Secret: your-app-secret-here" \
  -H "Content-Type: application/json" \
  -d '{
    "username": "your-email@example.com",
    "password": "your-password"
  }'
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
async function authenticateWithViolet() {
  try {
    const response = await fetch('https://sandbox-api.violet.io/v1/login', {
      method: 'POST',
      headers: {
        'X-Violet-App-Id': process.env.VIOLET_APP_ID,
        'X-Violet-App-Secret': process.env.VIOLET_APP_SECRET,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        username: process.env.VIOLET_USERNAME,
        password: process.env.VIOLET_PASSWORD
      })
    });

    if (!response.ok) {
      const errorData = await response.json();
      throw new Error(errorData.message || 'Authentication failed');
    }

    const data = await response.json();

    return {
      authToken: data.token,
      refreshToken: data.refresh_token,
      expiresAt: new Date(data.expires_at)
    };
  } catch (error) {
    console.error('Authentication failed:', error.message);
    throw error;
  }
}
```

{% endtab %}
{% endtabs %}

### Expected Response

```json
{
    "id": 10084,
    "first_name": "First",
    "last_name": "Name",
    "email": "user@violet.io",
    "type": "DEVELOPER",
    "verified": true,
    "date_created": "2022-04-11T21:03:04+0000",
    "date_last_modified": "2024-10-23T21:52:56+0000",
    "roles": [
        {
            "name": "ROLE_DEVELOPER",
            "permissions": [
                {
                    "name": "MANAGE_APPS"
                },
                {
                    "name": "MANAGE_USER"
                }
            ]
        }
    ],
    "tos_accepted": false,
    "token": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ1c2VyQGV4YW1wbGUuY29tIiwic2NvcGVzIjpbIlJPTEVfREVWRUxPUEVSIl0sInVzZXJfaWQiOjEwMzk3LCJ1c2VyX3R5cGUiOiJERVZFTE9QRVIiLCJtZXJjaGFudF9pZHMiOltdLCJkZXZlbG9wZXJfaWQiOjEwMjkyLCJhcHBfaWQiOiIxMDM4MiIsImlzcyI6Imh0dHBzOi8vdmlvbGV0LmlvIiwiaWF0IjoxNjUyMzc3ODc0LCJleHAiOjE2NTI0NjQyNzR9.BW1HDpe1Gm2wA-esP8NWEtn9thEsfeKsIGEicAoMgDPEOyO6VdNP71ajqnPrMqITGadHApH-b6LewiBFAcobw",
    "refresh_token": "rt_1234567890abcdef"
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.violet.io/concepts/overview/obtaining-api-token.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
