# Autenticación

## Obtener token de acceso

<mark style="color:green;">`POST`</mark> `https://{clave}.admintotal.com/api/v2/usuarios/login_usuario/`

Este endpoint se encarga de autenticar a los usuarios y retornar el api key que debe ser utilizado en todas las peticiones a la api.

Ya que obtenemos el api\_*key debemos de enviar ese valor en TODAS las peticiones el header Api-key de la siguiente forma: "Api-key*: {api\_key}"

#### Request Body

| Name     | Type   | Description                    |
| -------- | ------ | ------------------------------ |
| username | string | Nombre de usuario a autenticar |
| password | string | Contraseña del usuario         |

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

```
{
    "ok": true,
    "usuario": {
        "id": 104,
        "api_key": "...",
        "username": "johndoe",
        "nombre": "John Doe",
        ...
    }
}
```

{% endtab %}
{% endtabs %}

### Autenticación basada en JWT (Recomendado)

Al utilizar este método de autenticación, TODAS las peticiones realizadas a la API deberán incluir el header Authorization de la siguiente forma: "Authorization: Bearer {access\_token}"

## Obtener token JWT

<mark style="color:green;">`POST`</mark> `https://{clave}.admintotal.com/api/v2/token/`

Endpoint para obtener access token y refresh token

#### Request Body

| Name     | Type   | Description                    |
| -------- | ------ | ------------------------------ |
| username | string | Nombre de usuario a autenticar |
| password | string | Contraseña del usuario         |

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

```
{
    "refresh": "eyJ0XAiO...",
    "access": "eyJ0eXAiO..."
}
```

{% endtab %}
{% endtabs %}

## Refrescar token JWT

<mark style="color:green;">`POST`</mark> `https://{clave}.admintotal.com/api/v2/refresh/`

Endpoint para obtener un nuevo access token una vez que éste expira.

#### Request Body

| Name    | Type   | Description   |
| ------- | ------ | ------------- |
| refresh | string | Refresh token |

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

```
{
    "access": "eyJ0eX..."
}
```

{% 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://developers.admintotal.com/api/autenticacion.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.
