# Token de Acesso (3.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                   |
| -------- | ------ | ----------------------------- |
| 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="USERNAME ou PASSWORD inválido" %}

```csharp
{
  "mensagem": "Credenciais inválidas.",
  "token": null
}
```

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

{% hint style="info" %}

#### Swagger

[Você pode acessar nossa API e realizar testes diretamente na nossa plataforma Swagger!](https://sandbox-api.invoisys.io/swagger/index.html)
{% 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: 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-1.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.
