> For the complete documentation index, see [llms.txt](https://docs.payvalida.com/payin-metodos-digitales/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.payvalida.com/payin-metodos-digitales/medio-de-pago-digital/oauth2-token.md).

# Oauth2 token

## Constituye la obtención de un token.

<mark style="color:green;">`POST`</mark> `/oauth2/token`

Endpoint de obtención de JSON web tokens. El client\_id y client\_secret es compartido previamente por el medio de pago digital. El endpoint debe ser expuesto por el medio de pago digital y será invocado por payválida.

#### Headers

| Name                                            | Type   | Description                                                                                                                       |
| ----------------------------------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------- |
| Accept<mark style="color:red;">\*</mark>        | String | Utilizado para definir que tipo de contenido puede procesar el cliente. El valor siempre debe ser application/json.               |
| Content-Type<mark style="color:red;">\*</mark>  | String | Utilizado para identificar el media-type del cuerpo de la solicitud. El valor siempre debe ser application/x-www-form-urlencoded. |
| Authorization<mark style="color:red;">\*</mark> | String | Credenciales para obtención de token. Deben seguir el formato 'Basic Base64(client\_id:client\_secret)'.                          |

#### Request Body

| Name                                          | Type   | Description                                                                                                                       |
| --------------------------------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------- |
| grant\_type<mark style="color:red;">\*</mark> | String | Tipo de subvención de token. El valor siempre debe ser client\_credentials.                                                       |
| client\_id<mark style="color:red;">\*</mark>  | String | Identificador de cliente asignado a Payválida.                                                                                    |
| scope                                         | String | Alcance del token. En cas de ser necesaria se usará un token distinto para cada operación (transaction, confirmation, annulment). |

{% tabs %}
{% tab title="200: OK Solicitud procesada correctamente" %}
**expires\_in**<mark style="color:red;">\*</mark> (<mark style="color:blue;">number</mark>): Segundos de duración de token. En sandbox no hay duración máxima, en producción debe ser de 1200 (20 min).

**token\_type**<mark style="color:red;">\*</mark> (<mark style="color:blue;">string</mark>): Tipo de token. Siembre debe ser Bearer.

**access\_token**<mark style="color:red;">\*</mark> (<mark style="color:blue;">string</mark>): Token
{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Request ejemplo" %}
{% code overflow="wrap" %}

```bash
curl --location 'https://tu-host.com/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: Basic cGF5dmFsaWRhOmNsaWVudF9zZWNyZXQ=' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=payvalida' \
--data-urlencode 'scope=TuScope'
```

{% endcode %}
{% endtab %}

{% tab title="Response ejemplo" %}
{% code overflow="wrap" %}

```json
{
  "expires_in": 1200,
  "token_type": "Bearer",
  "access_token": "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJlZGZmNGZkYzYyMDk0ODQ4ODE4NzQ3MWY4YWMwZDljNCIsImV4cCI6MTUxNjIzOTEyMiwiaWF0IjoxNTE2MjM5MDIyfQ.x07DYK5aoJIl_KbbnjOhpteKC_kkYoQrXueO1kf6TSgjwZu6c3Olt627kYbJatD0YEnPvTm8dTssNCk4CLlUjw"
}

```

{% endcode %}
{% 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://docs.payvalida.com/payin-metodos-digitales/medio-de-pago-digital/oauth2-token.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.
