> For the complete documentation index, see [llms.txt](https://integracao.gitbook.io/invoisys/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://integracao.gitbook.io/invoisys/endpoints/autorizacao/autenticacao.md).

# Token de Acesso (2.0)

<mark style="color:green;">`POST`</mark> `https://sandbox-api.invoisys.com.br/api/token`

#### Headers

| Name         | Type   | Description                          |
| ------------ | ------ | ------------------------------------ |
| Content-type | string | `application/x-www-form-urlencoded`​ |
| Accept       | string | `application/json​`                  |

#### Request Body

| Name        | Type   | Description                   |
| ----------- | ------ | ----------------------------- |
| grant\_type | string | Informar o literal `password` |
| username    | string | Endereço de e-mail do usuário |
| password    | string | A senha do usuário            |

#### Response

{% tabs %}
{% tab title="200 - Sucesso" %}

```csharp
{
  "access_token": "pehddf4BLGV8UZ4ZbUIZ81BO6BG6Fzpmrd1RZMSTiZeESZulk48EU7FSq33G1JhgxjNd1PPbm51zl_oik2JZJIghn53F13h1izGZshFwJgY40MAW68Bx3AMLPkaf7THTi9QfIfO19WRiAZnJNIok-oIC3jpbdmoiFeMS_bDD2C2bBXaZjAVtufONBc6yuliSnzkGd-TSjZZxE3jH2WFWnhDMpTMNHMQgVI3oobWiZwal-4j7ZtAioAwerOlR1ZNBRi5GL4zmQO050bsXAwhYRQAgxlLZtzJxuTIjztYaZYU",
  "token_type": "bearer",
  "expires_in": 92843
}
```

{% endtab %}

{% tab title="400 - Erro" %}
{% tabs %}
{% tab title="GRANT\_TYPE Incorreto" %}

```csharp
{
  "error": "unsupported_grant_type"
}
```

{% endtab %}

{% tab title="USERNAME ou PASSWORD inválido" %}

```csharp
{
  "error": "credenciais_invalidas",
  "error_description": "Credenciais inválidas."
}
```

{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}

{% hint style="success" %}
**Recomendações**

* Criar uma rotina de atualização do token 2x ao dia (a cada 12 horas).&#x20;
* Em todas as chamadas de endpoints deve ser incluído um tratamento para renovar o Token caso seja recebido retorno de response code 401.
  {% endhint %}

{% hint style="info" %}

#### Swagger

[Você pode acessar nossa API e realizar testes diretamente na nossa plataforma Swagger!](https://sandbox-api.invoisys.com.br/swagger/ui/index#/)
{% endhint %}

## Referências à API 📌

* [Passo-a-Passo da NF-e](/invoisys/getting-started/documentos-fiscais/emissao/nf-e/integracao-passo-a-passo.md#conhecendo-as-apis)
* [Passo-a-Passo da NFC-e](/invoisys/getting-started/documentos-fiscais/emissao/nfc-e/passo-a-passo.md#conhecendo-as-apis)

## Exemplo de Uso 💡

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

```php
//Informando os parâmetros
$grant_type =   'password';
$username   =   'email@email.com.br';
$password   =   'senha do usuário';

//Informando a URL e os parâmetros a serem passados
$url = 'https://sandbox-api.invoisys.com.br/api/token';
$dados = array('grant_type' => $grant_type, 'username' => $username, 'password' => $password);

//Configurando dados para a requisição
$opcoes = array(
        'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($dados)
    )
);

//Pegando e arrumando o retorno da API
$contexto  = stream_context_create($opcoes);
$retorno = file_get_contents($url, false, $contexto);
$autorizacao= json_decode($retorno, true);

//Armazendo o Token de Acesso em uma variável
$token = $autorizacao["access_token"];
```

{% endtab %}
{% endtabs %}


---

# 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 dynamically by asking a question.

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

```
GET https://integracao.gitbook.io/invoisys/endpoints/autorizacao/autenticacao.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.
