# Autorização de requisição

### Cabeçalho de autorização

Para autorizar cada solicitação da API, passe sua API KEY no `Autorização` cabeçalho da seguinte forma:

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

### Exemplo de uma solicitação com um token

Um exemplo de uso do `Autorização` cabeçalho em uma solicitação da API:

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

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

{% endtab %}

{% tab title="Python" %}

```python
import requests

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

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

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

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const url = 'https://api.cryptocloud.plus/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('Erro de autenticação');
        }
    })
    .then(data => {
        console.log('Sucesso:', data);
    })
    .catch(error => {
        console.error('Falha:', error);
    });
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.cryptocloud.plus/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 'Erro do cURL: ' . curl_error($ch);
} else {
    $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

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

curl_close($ch);
?>
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Você não precisa enviar uma solicitação de autorização separada. A API KEY deve ser transferida no cabeçalho Authorization.
{% endhint %}

### Possíveis erros

| Código de resposta | Chave do erro       | Descrição do erro    |
| ------------------ | ------------------- | -------------------- |
| 400                | Requisição inválida | Solicitação inválida |
| Token inválido     | Não autorizado      | Token inválido       |

### Exemplo de uma resposta com erro

```json
{
    "status": "error",
    "result": {
        "authorization": "Solicitação não autorizada."
    }
}
```


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cryptocloud.plus/pt/referencia-da-api-v2/authorization.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
