# Autenticación

{% hint style="info" %}
POST <https://id.wompi.sv/connect/token>
{% endhint %}

La autenticación del API de Wompi se realiza utilizando [OAuth 2.0 con Client Credential Flow](https://tools.ietf.org/html/rfc6749#section-4.4).&#x20;

Este es un standard ampliamente documentado para cualquier lenguaje de programación y la mayor parte de lenguajes  ya cuentan con librerías que facilitan la implementación del OAuth 2.0. Algunos ejemplos:

{% tabs %}
{% tab title="C#" %}

```
var client = new RestClient("https://id.wompi.sv/connect/token");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("application/x-www-form-urlencoded", "grant_type=client_credentials&client_id=%24%7Baccount.clientId%7D&client_secret=YOUR_CLIENT_SECRET&audience=YOUR_API_IDENTIFIER", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

{% endtab %}

{% tab title="PHP" %}

```
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://id.wompi.sv/connect/token",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "grant_type=client_credentials&client_id=%24%7Baccount.clientId%7D&client_secret=YOUR_CLIENT_SECRET&audience=YOUR_API_IDENTIFIER",
  CURLOPT_HTTPHEADER => array(
    "content-type: application/x-www-form-urlencoded"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

{% endtab %}

{% tab title="JAVA" %}

```
HttpResponse<String> response = Unirest.post("https://id.wompi.sv/connect/token")
  .header("content-type", "application/x-www-form-urlencoded")
  .body("grant_type=client_credentials&client_id=%24%7Baccount.clientId%7D&client_secret=YOUR_CLIENT_SECRET&audience=YOUR_API_IDENTIFIER")
  .asString();
```

{% endtab %}

{% tab title="cURL" %}

```
curl --request POST \
  --url 'https://YOUR_DOMAIN/oauth/token' \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data grant_type=client_credentials \
  --data 'client_id=YOUR_CLIENT_ID' \
  --data client_secret=YOUR_CLIENT_SECRET \
  --data audience=YOUR_API_IDENTIFIER
```

{% endtab %}
{% endtabs %}

## Parametros a Utilizar

**Url para extraer token:** <https://id.wompi.sv/connect/token>

### Parametros del POST

* **grant\_type:** Dejar siempre client\_credentials.&#x20;
* **audience:** Dejar siempre "wompi\_api"
* **client\_id:** El client id del negocio de wompi bajo el cual desea ejecutar la acción en el api
* **client\_secret:** Es la llave secreta del negocio de wompi bajo el cual desea ejecutar la acción en el api

### Objeto JSON Retornado

```
{
  "access_token":"eyJz93a...k4laUWw",
  "expires_in": 3600,
  "token_type": "Bearer",
  "scope": "wompi_api"
}
```

Donde:

* **access\_token:** contiene el token de autenticación
* **expires\_in:** la duración del token en segundos (no es necesario obtener un token para cada petición)

## Obtener las Credenciales de Autenticación

Como se menciono anteriormente los únicos dos parámetros que no son fijos necesarios para hacer la petición son:

* **client\_id:** El client id del negocio de wompi bajo el cual desea ejecutar la acción en el api
* **client\_secret:** Es la llave secreta del negocio de wompi bajo el cual desea ejecutar la acción en el api

Estos parámetros se obtiene desde el [Panel de Control](https://panel.wompi.sv) de Wompi.&#x20;

<figure><img src="/files/aj99fYTSDeN5fqyrKKn1" alt="Ingresar al listado de aplicativos y editar el aplicativo deseado"><figcaption><p>Ingresar al listado de negocios y editar el negocio deseado</p></figcaption></figure>

<figure><img src="/files/ChmA6mJODMoSPWmJFE7m" alt=""><figcaption><p>Detalle negocio</p></figcaption></figure>

Una vez en el detalle del negocio el **App ID** corresponde a **client\_id** y **API Secret** a **client\_secret** de la petición OAuth

## Utilización de Token

Para utilizar el token solo hay que agregar un header HTTP en todas las peticiones al API:

* **Nombre header:** authorization
* **Valor Header:** Bearer ACCESS\_TOKEN

Donde "ACCESS\_TOKEN" es la token regresada en el proceso de autenticación mencionado previamente

{% tabs %}
{% tab title="C#" %}

```
var client = new RestClient("https://api.wompi.sv/EnlacePago");
var request = new RestRequest(Method.GET);
request.AddHeader("content-type", "application/json");
request.AddHeader("authorization", "Bearer ACCESS_TOKEN");
IRestResponse response = client.Execute(request);
```

{% endtab %}

{% tab title="PHP" %}

```
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.wompi.sv/EnlacePago",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "authorization: Bearer ACCESS_TOKEN",
    "content-type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

{% endtab %}

{% tab title="Java" %}

```
HttpResponse<String> response = Unirest.get("https://api.wompi.sv/EnlacePago")
  .header("content-type", "application/json")
  .header("authorization", "Bearer ACCESS_TOKEN")
  .asString();
```

{% endtab %}

{% tab title="cURL" %}

```
curl --request GET \
  --url https://api.wompi.sv/EnlacePago \
  --header 'authorization: Bearer ACCESS_TOKEN' \
  --header 'content-type: application/json'
```

{% 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://docs.wompi.sv/autenticacion/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.
