# Créer un Token

Pour créer un jeton d'authentification en utilisant une méthode d'authentification basique (Basic Authentication) avec votre **`api_key`** et **`api_secret`**, vous pouvez suivre les étapes suivantes. Assurez-vous d'avoir accès à votre API et d'avoir les informations d'authentification nécessaires (clé API et secret).

{% hint style="info" %}
**Encodage des identifiants** : Tout d'abord, vous devez encoder votre clé API (**`api_key`**) et votre Api secret (**`api_secret`**) dans un format approprié pour l'authentification basique. Pour cela, combinez vos identifiants sous la forme **`api_key:api_secret`** et encodez-les en base64.
{% endhint %}

## Authentification

<mark style="color:green;">`POST`</mark> <https://api.digitalpaye.com/v1/auth>

**Headers**

| Name          | Value                                                                                    |
| ------------- | ---------------------------------------------------------------------------------------- |
| X-Environment | `Production`                                                                             |
| Authorization | `Basic bGl2ZV9kaWdpdGFscGF5ZTY3OTg3Njo1OWJlYzU4Ni0yOWYwLTRjMWMtOGE2ZC0wY2MyMDk0ZjZhMzQ=` |

**Response**

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

```json
{
    "statusCode": 200,
    "message": "Successful",
    "data": {
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb21wYW55SWQiOiI4NDM3ZGQxMy04OWFjLTQ1ZTEtYTdhYS1jOGJhMDk1ZDFiMjciLCJpYXQiOjE3Mjg2MzQyMDMsImV4cCI6MTcyODYzNDgwM30.A3-AD5mGawbhv9nUmio0k7c-hhx5K7lqnuPFCziJJqE",
        "exp": 1728634803
    }
}
```

{% endtab %}

{% tab title="400: Bad Request" %}

```json
{
    "statusCode": 400,
    "message": "BadRequestError",
    "reason": "Les identifiants API (apikey et apisecret) sont requis."
}
```

{% endtab %}

{% tab title="401: Unauthorized" %}

```json
{
    "statusCode": 401,
    "message": "UnauthorizedError",
    "reason": "Identifiants API incorrects. Veuillez vérifier votre clé API et votre secret."
}
```

{% endtab %}

{% tab title="500:  Internal Server Error" %}

```json
{
    "statusCode": 500,
    "message": "InternalServerError",
    "reason": "Une erreur est survenue. Veuillez réessayer"
}
```

{% endtab %}
{% endtabs %}

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

```url
curl --location --request POST 'https://api.digitalpaye.com/v1/auth' \
--header 'X-Environment: Production' \
--header 'Authorization: Basic i0yOWYwLTRjMWMtOGE2ZC0bGl2ZV9JlYzU4NiwY2MyMDk0ZjZhMzQkaWdpdGFscGF5ZTY3OTg3Njo1OW=' \
--data ''
```

{% endtab %}

{% tab title="Curl PHP" %}

```php
<?php

$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.digitalpaye.com/v1/auth',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => array(
    'X-Environment: Production',
    'Authorization: Basic i0yOWYwLTRjMWMtOGE2ZC0bGl2ZV9JlYzU4NiwY2MyMDk0ZjZhMzQkaWdpdGFscGF5ZTY3OTg3Njo1OW='
  ),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;

```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$client = new Client();
$headers = [
  'X-Environment' => 'Production',
  'Authorization' => 'Basic i0yOWYwLTRjMWMtOGE2ZC0bGl2ZV9JlYzU4NiwY2MyMDk0ZjZhMzQkaWdpdGFscGF5ZTY3OTg3Njo1OW='
];
$body = '';
$request = new Request('POST', 'https://api.digitalpaye.com/v1/auth', $headers, $body);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
```

{% endtab %}

{% tab title="Node JS" %}

```javascript
const axios = require('axios');
let data = '';

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://api.digitalpaye.com/v1/auth',
  headers: { 
    'X-Environment': 'Production', 
    'Authorization': 'Basic i0yOWYwLTRjMWMtOGE2ZC0bGl2ZV9JlYzU4NiwY2MyMDk0ZjZhMzQkaWdpdGFscGF5ZTY3OTg3Njo1OW='
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});
```

{% endtab %}

{% tab title="Java" %}

```java
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = RequestBody.create(mediaType, "");
Request request = new Request.Builder()
  .url("https://api.digitalpaye.com/v1/auth")
  .method("POST", body)
  .addHeader("X-Environment", "Production")
  .addHeader("Authorization", "Basic i0yOWYwLTRjMWMtOGE2ZC0bGl2ZV9JlYzU4NiwY2MyMDk0ZjZhMzQkaWdpdGFscGF5ZTY3OTg3Njo1OW=")
  .build();
Response response = client.newCall(request).execute();
```

{% 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.digitalpaye.com/api-references/v1/creer-un-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.
