> For the complete documentation index, see [llms.txt](https://docs.trybit.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.trybit.com/ru/api-reference-v2/authorization.md).

# Авторизация запросов

### Заголовок Authorization

Для авторизации каждого запроса к API в заголовке `Authorization` необходимо передать ваш API KEY следующим образом:

```
Authorization: Token <API KEY>
```

<figure><img src="https://1986541005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5U1THZAib81UsHLz0L7L%2Fuploads%2FMyDxkp2iKoIRxrtkkLcp%2Fimage.png?alt=media&amp;token=16d32c74-026a-40e4-bcfe-fdf056411554" alt=""><figcaption></figcaption></figure>

### Пример запроса с токеном

Пример использования заголовка `Authorization` в запросе к API:

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

```bash
curl -X POST https://api.trybit.com/v2/invoice/create \
-header "Authorization: Token eyJ0eXAi1iJKV1QiLCJhbGci1iJIAcI1NiJ9.eyJpZCI6MTMsImV4cCI6MTYzMTc4NjQyNn0.HQavV3z8dFnk56bX3MSY5X9lR6qVa9YhAoeTEH"
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.trybit.com/v2/invoice/create"
headers = {
    "Authorization": "Token eyJ0eXAi1iJKV1QiLCJhbGciOiJIAcI1NiJ9.eyJpZCI6MTMsImV4cCI6MTYzMTc4NjQyNn0.HQavV3z8dFnk56bX3MSY5X9lR6qVa9YhAoeTEH"
}

response = requests.post(url, headers=headers)

if response.status_code == 200:
    print("Success:", response.json())
else:
    print("Fail:", response.status_code, response.text)
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const url = 'https://api.trybit.com/v2/invoice/create';
const headers = new Headers({
    'Authorization': 'Token eyJ0eXAi1iJKV1QiLCJhbGciOiJIAcI1NiJ9.eyJpZCI6MTMsImV4cCI6MTYzMTc4NjQyNn0.HQavV3z8dFnk56bX3MSY5X9lR6qVa9YhAoeTEH'
});

fetch(url, { method: 'POST', headers })
    .then(response => {
        if (response.ok) {
            return response.json();
        } else {
            return Promise.reject('Auth error');
        }
    })
    .then(data => {
        console.log('Success:', data);
    })
    .catch(error => {
        console.error('Fail:', error);
    });
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.trybit.com/v2/invoice/create");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array(
    "Authorization: Token eyJ0eXAi1iJKV1QiLCJhbGciOiJIAcI1NiJ9.eyJpZCI6MTMsImV4cCI6MTYzMTc4NjQyNn0.HQavV3z8dFnk56bX3MSY5X9lR6qVa9YhAoeTEH"
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Error cURL: ' . curl_error($ch);
} else {
    $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    if ($statusCode == 200) {
        echo "Success: " . $response;
    } else {
        echo "Fail: " . $statusCode . " " . $response;
    }
}

curl_close($ch);
?>
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Отправлять отдельный запрос на авторизацию не надо. API KEY необходимо передавать в заголовке Authorization.
{% endhint %}

### Возможные ошибки

| Код ответа | Ключ ошибки  | Описание ошибки    |
| ---------- | ------------ | ------------------ |
| 400        | Bad request  | Неверный запрос    |
| 401        | Unauthorized | Некорректный токен |

### Пример ответа с ошибкой

```json
{
    "status": "error",
    "result": {
        "authorization": "Unauthorized request."
    }
}
```

> Мы регулярно работаем над улучшением документации сервиса для разработчиков. Пожалуйста, оцените качество и полезность материалов [по ссылке](https://survey.zohopublic.eu/zs/G6TdRh).


---

# 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.trybit.com/ru/api-reference-v2/authorization.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.
