> ## Documentation Index
> Fetch the complete documentation index at: https://docs.papslogistics.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentification

> Authentifiez vos appels à l'API Paps avec x-api-key

L'API Paps s'authentifie avec une clé API transmise dans l'en-tête `x-api-key`. C'est la méthode recommandée pour toute nouvelle intégration.

## Méthode recommandée : `x-api-key`

Chaque client dispose d'une clé API unique, disponible dans son espace personnel Paps. Transmettez-la sur chaque requête via l'en-tête `x-api-key` :

```http theme={null}
x-api-key: {{PAPS_API_KEY}}
```

<CodeGroup>
  ```bash cURL theme={null}
  curl https://{{BASE_URL}}/marketplace \
    -H "x-api-key: {{PAPS_API_KEY}}" \
    -H "Content-Type: application/json" \
    -d '{
      "origin": "Cité Keur Gorgui, Dakar",
      "destination": "Plateau, Dakar",
      "weight": 2
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch("https://{{BASE_URL}}/marketplace", {
    method: "POST",
    headers: {
      "x-api-key": "{{PAPS_API_KEY}}",
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      origin: "Cité Keur Gorgui, Dakar",
      destination: "Plateau, Dakar",
      weight: 2
    })
  });

  const data = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://{{BASE_URL}}/marketplace",
      headers={"x-api-key": "{{PAPS_API_KEY}}"},
      json={
          "origin": "Cité Keur Gorgui, Dakar",
          "destination": "Plateau, Dakar",
          "weight": 2
      }
  )

  data = response.json()
  ```

  ```php PHP theme={null}
  <?php

  $ch = curl_init("https://{{BASE_URL}}/marketplace");

  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
      "x-api-key: {{PAPS_API_KEY}}",
      "Content-Type: application/json"
  ]);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
      "origin" => "Cité Keur Gorgui, Dakar",
      "destination" => "Plateau, Dakar",
      "weight" => 2
  ]));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

  $response = curl_exec($ch);
  curl_close($ch);
  ```
</CodeGroup>

<Warning>
  Ne partagez jamais votre clé API publiquement (dépôt de code, application front-end, etc.). Effectuez vos appels depuis un serveur backend.
</Warning>

## Méthode dépréciée : Bearer token

<Warning>
  **Dépréciée depuis le 1er septembre 2025.** L'en-tête `Authorization: Bearer <token>` ne doit plus être utilisé pour les nouvelles intégrations. Contactez [Paps Support](mailto:souaibou@paps-app.com) avant d'envisager cette méthode.
</Warning>

L'API expose encore l'endpoint historique `POST /auth/login`, qui échange un `clientId` et un `clientSecret` contre un token JWT :

```http theme={null}
POST /auth/login
```

```json Body theme={null}
{
  "clientId": "{{CLIENT_ID}}",
  "clientSecret": "{{CLIENT_SECRET}}"
}
```

```json Réponse — 200 theme={null}
{
  "code": 200,
  "message": "Success",
  "error": null,
  "data": {
    "token": "{{ACCESS_TOKEN}}",
    "expiration": "1642805496000"
  }
}
```

Le token obtenu se transmet ensuite via l'en-tête `Authorization: Bearer {{ACCESS_TOKEN}}`. Cette méthode reste documentée à titre de référence pour les intégrations existantes, mais ne doit pas être utilisée pour de nouveaux projets.
