> For the complete documentation index, see [llms.txt](https://help.glpi-project.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.glpi-project.org/tutorials/fr/readme-1/api-v2.md).

# API V2 🆕

Concept

Quand on utilise l'API de GLPI, la conversation se fait dans une langue universelle appelée le JSON (un format de texte très simple à lire) et s'appuie sur le réseau web classique (HTTP), avec 4 grandes actions principales :

* **GET (Lire)** : Donne-moi la liste des ordinateurs du site de Lyon.
* **POST (Créer)** : Crée un nouveau ticket avec le titre 'Panne internet'.
* **PUT/PATCH (Mettre à jour)** : Change le statut de l'ordinateur #45 en 'En réparation'.
* **DELETE (Supprimer)** : Supprime le ticket #1234.

Chaque demande est envoyée à une adresse URL spécifique, appelée un Endpoint (par exemple : `https://mon-glpi.com/api.php/Ticket`).

***

## À quoi ça sert ?

L'API permet, entre autres, d'automatiser des tâches chronophages et de simplifier certaines actions répétitives :

* **Supervision (Monitoring)** : Au lieu d'envoyer un simple email, l'API pour créer automatiquement un ticket critique et l'assigner à l'équipe réseau dans GLPI.
* **Ressources Humaines** : Quand le service RH ajoute un employé dans son logiciel, celui-ci transmet automatiquement les données à GLPI via l’API pour créer un compte utilisateur, générer un ticket de préparation de PC, et attribuer une licence logicielle.&#x20;
* **Reporting externe** : Un script Python qui interroge l'API tous les soirs pour récupérer le nombre de tickets ouverts et l'afficher sur un écran dans l'open-space.

***

## Création d'un client Oauth

Pour utiliser l'API, GLPI a besoin qu'un client OAuth soit configuré. Celui-ci va  permettre de générer un **`ID client`** et un **`Client secret`** indispensable pour autoriser l'utilisation de l'API.

* Depuis **`Configuration`** > **`OAuth clients,`** cliquez sur **`+ Ajouter`**
* Indiquez&#x20;
  * **Un nom**
  * Le ou les **`scopes`** concernés : email, user, api, inventory, status, graphql
  * Le **type d'autorisation** (grants) : Password, Clients credentials, Authorization code
* **Sauvegarder** votre client OAuth
* Cliquez sur votre client Oauth, et relevez les 2 valeurs :&#x20;
  * **`Client ID`**
  * **`Client secret`**

<figure><img src="/files/cwRSCZg35MLJYqaSEhjl" alt=""><figcaption><p>Création Client OAuth</p></figcaption></figure>

***

## Méthode 1 - API Endpoints

La méthode recommandée est de passer par **`API Endpoints`** présent nativement dans GLPI.  Vous retrouverez l'URL depuis :

* **`Configuration`** > **`Générale`** > **`API`** > **`API Endpoints`**&#x20;
* Ou à l'adresse <https://mon_instance/api.php/v2.2/doc>

{% stepper %}
{% step %}

### Connectez le client OAuth

* Depuis **`Configuration`** > **`Générale`** > **`API`** > **`API Endpoints`**, cliquez sur **`Autoriser`**
* Entrez l'**`ID client`** et le **`client secret`** relevé à l'étape précédente
* Sélectionnez les scopes souhaités
* cliquez sur **`Authoriser`**
* Valider l'écran de consentement

<div align="left"><figure><img src="/files/JJpmZIOQdyofej2sxhxv" alt="" width="475"><figcaption><p>Autorisations disponibles</p></figcaption></figure></div>
{% endstep %}

{% step %}

### Utilisation

* Depuis **`Configuration`** > **`Générale`** > **`API`** > **`API Endpoints`** ou <https://mon_instance/api.php/v2.2/doc>, sélectionnez le module qui vous convient&#x20;

<figure><img src="/files/XrqUOLRTb0NCF3i9yqfK" alt=""><figcaption><p>Liste objets API</p></figcaption></figure>

* Dans notre exemple, nous afficherons le ticket avec l'**`id 60`**
* Depuis **`Administration`**, sélectionnez <mark style="background-color:$primary;">**GET**</mark>**&#x20; /Assistance/Ticket/{id}**
* Cliquez sur **`Try it out`**
* Indiquez le **numéro du ticket**
* Cliquez sur **`Execute`**

<figure><img src="/files/oLRwoZUnRXTL4ozOH6ER" alt=""><figcaption><p>Entrer les paramètres de la requête API</p></figcaption></figure>

**Réponse** :&#x20;

<figure><img src="/files/8jbezdMmfdl9FGh0cxmI" alt=""><figcaption><p>Réponse de la requête</p></figcaption></figure>

* Dans ce 1er encart apparait :&#x20;

1. **Curl** : La requête utilisée
2. **La requête URL**
3. **la réponse de la requête :** le contenu de notre ticket
4. **la réponse du hearder** : liste de paramètres sous la forme "Clé: Valeur" (le poids de la requête, l'horodatage, le formatage, etc.).

* Dans un autre encart se trouve les valeurs brutes de la requête, c'est a dire le schéma utilisé.&#x20;

<figure><img src="/files/CBoyhQbtXfAEjKR5soTP" alt=""><figcaption><p>Exemple de valeur</p></figcaption></figure>

* Il est d'ailleurs possible de voir le schéma et le type de valeur attendue en mode liste en cliquant sur **`Schema`**

<figure><img src="/files/GzBoAxunnj3adglmg5Uj" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

***

## Méthode 2 - Via requêtes curl

{% stepper %}
{% step %}

### Initialisation d'un token

Entrez cette commande dans un terminal :

<pre class="language-viml" data-overflow="wrap"><code class="lang-viml">curl -X POST 'https://<a data-footnote-ref href="#user-content-fn-1">MON_INSTANCE</a>/api.php/token'
--header 'Content-Type: application/x-www-form-urlencoded'
--data 'grant_type=password'
--data 'client_id=<a data-footnote-ref href="#user-content-fn-2">MON_ID_CLIENT</a>'
--data 'client_secret=<a data-footnote-ref href="#user-content-fn-3">MON_SECRET_ID</a>'
--data 'username=<a data-footnote-ref href="#user-content-fn-4">MON_UTILISATEUR</a>'
--data 'password=<a data-footnote-ref href="#user-content-fn-5">MON_MOT_DE_PASSE</a>'
--data 'scope=api'
</code></pre>

Un résultat similaire vous sera renvoyé :

{% code overflow="wrap" %}

```json
{"token_type":"Bearer","expires_in":3600,"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI3NDhhMjZmMDYzOTE5NWRlNmE0ZWY3OTRmMzJjZWFjYmFiYWIyOGM2MmI5NDU5YTM5NDMxOWVhNzgxZTY2ZTgyIiwianRpIjoiZmZjMDY2MmU1ZDIwYWQyMTI5NTc2NGFjNTk5NmMzOGM1YmJmYThiYzM3YTE5MTI5MGM2YWFkYzg1YWZmMmY3YTQyYmY1NWJkNzc2NDI4NjAiLCJpYXQiOjE3NzcwMjU4MzUuNDE4NzQ4LCJuYmYiOjE3NzcwMjU4MzUuNDE4NzUxLCJleHAiOjE3NzcwMjk0MzUuNDEyNTQ2LCJzdWIiOiIzMyIsInNjb3BlcyI6WyJhcGkiXX0.KGwELLimKR8Eh6WzDk0BHlQWBDLwHTh2Weg8g2um71CxdgfeRReJRH4gcCqlDmdACZmf6ENoOwAarjZItlBaR7FECgllCDW1w792VvD6SbK8CKD316k2To3mp7bVh9qdPO28IL5W0fdnReEeA7JHyZfQyjxmOqVeejXf5YPOXuDcHmYbbR3bITQT8FlQCJEvYRctAgM59XLocTCySelaO-D_YXOYG0zGi5svb3X-bZjOdsiRnp3L3lqbB-DIhCSknLo63on7HK8Y2HGcCdU5HJbp4BOEiYj9YaBrFUzyetgAYPuuca4ZHsnjsJOAJOu0-iieIQq_iDAx1zSvgBGPng","refresh_token":"def50200449acd66b193093a5a9f8f392366ef97624b4760f5601ea177c202dcaa984b3415c5e6c7f79ec84d8ba5ce27b96880bd2c1eb1db2cb34776473b2ef54e5040b9f7e64d601f8f5f5f628c4b39e63354b07568fa9337cb915cc41b98b02277ea1f9915b7326a44449b46adc8970206dcda7ab2058bc81584884d777ec7f7c5071f1b41f8d003854ca128f38c9546a9c61d8a151bf7b36b4217010afc70cb24147c0c3a508d3f7df598d04b1e1d6a97aa8ce01874122f83befaa28d0816910ae610e448d111abe94f7ea42c31cabd5b3c6d9c9b2125e81b0c8c556172fb25511c97db66d16f0244614e99a4a934f1cdd695e6a48b5f0de396a70189ff79b7d3f9d3e52694c343f1de04238b5b77616e3e786c52b1cc38ba928a37f9e21baafde64088111d02990876b927cdf93976774164a94a2e3b8e706bdae64df4795727204035548cf79b5aac54ebbd497e762cfe7b47bbc4aa6c65f66379d52f6bd3ef33b35b8af3d2789141fa9a58cb767aab31197219a676b6522d1ca1dbd081a84fef91788572118cdd4df7f0e8180720ddcebd8c23857581f33677630523fe94412e841d57d2a8"}
```

{% endcode %}

{% hint style="info" %}
l'**`access token`** est l'information importante qui vous sera demandé à chaque commande que vous taperez
{% endhint %}
{% endstep %}
{% endstepper %}

***

## Exemples de commandes&#x20;

{% hint style="danger" %}
Si vous ne souhaitez pas remplir certains champs de vos requêtes, vous pouvez soit indiquer la valeur **`"null"`** (par exemple **`"sla_ttr": null`**) soit les supprimer de votre requête. L'essentiel est que votre `json` soit correctement structuré. Toutes valeurs contenant un **`"id": 0`** doivent également être remplacées par la valeur **`null`**
{% endhint %}

### Tickets

#### Créer un ticket :&#x20;

{% hint style="warning" %}
**Limitation** :&#x20;

Le format attendu pour les dates est **`"AAAA-MM-JJ HH:MM:SS"`**. La variable **`$date-time`** n'est pas applicable à ce jour (en cours de correction par les équipes techniques)
{% endhint %}

<pre class="language-cmd"><code class="lang-cmd">  curl -X 'POST' \
  'https://<a data-footnote-ref href="#user-content-fn-1">MON_INSTANCE</a>/api.php/Assistance/Ticket' \
  -H 'accept: application/json' \
  -H 'Accept-Language: fr_FR' \
  -H 'Authorization: Bearer <a data-footnote-ref href="#user-content-fn-6">MON_TOKEN</a>' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "string",
  "content": "string",
  "user_recipient": {
    "id": 0
  },
  "user_editor": {
    "id": 0
  },
  "is_deleted": false,
  "category": {
    "id": 0
  },
  "location": {
    "id": 0
  },
  "urgency": 1,
  "impact": 1,
  "priority": 1,
  "date_creation": "AAAA-MM-JJ HH:MM:SS",
  "date_mod": "AAAA-MM-JJ HH:MM:SS",
  "date": "AAAA-MM-JJ HH:MM:SS",
  "date_solve": "AAAA-MM-JJ HH:MM:SS",
  "date_close": "AAAA-MM-JJ HH:MM:SS",
  "type": 1,
  "external_id": "string",
  "request_type": {
    "id": 0
  },
  "sla_ttr": {
    "id": 0
  },
  "sla_tto": {
    "id": 0
  },
  "ola_ttr": {
    "id": 0
  },
  "ola_tto": {
    "id": 0
  },
  "sla_level_ttr": {
    "id": 0
  },
  "ola_level_ttr": {
    "id": 0
  },
  "global_validation": 1,
  "status": {},
  "entity": {
    "completename": "string"
  },
  "team": [
    {
      "name": "string",
      "type": "string",
      "role": "string"
    }
  ]
}
</code></pre>

#### Récupérer le contenu d'un ticket :&#x20;

<pre class="language-vim" data-overflow="wrap"><code class="lang-vim">curl -X 'GET' \
'http://<a data-footnote-ref href="#user-content-fn-1">MON_INSTANCE</a>/api.php/Assistance/Ticket/<a data-footnote-ref href="#user-content-fn-7">ID</a>' \
-H 'accept: application/json' \
-H 'Accept-Language: fr_FR'' \
-H 'Authorization: Bearer <a data-footnote-ref href="#user-content-fn-6">MON_TOKEN</a>'
</code></pre>

#### Récupérer la solution d’un ticket :

<pre class="language-vim" data-overflow="wrap"><code class="lang-vim">curl -X 'GET' \
'http://<a data-footnote-ref href="#user-content-fn-1">MON_INSTANCE</a>/api.php/Assistance/Ticket/<a data-footnote-ref href="#user-content-fn-7">ID</a>/Timeline/Solution' \
-H 'accept: application/json' \
-H 'Accept-Language: fr_FR'' \
-H 'Authorization: Bearer <a data-footnote-ref href="#user-content-fn-6">MON_TOKEN</a>'
</code></pre>

#### Récupérer les documents d’un ticket :

<pre class="language-vim" data-overflow="wrap"><code class="lang-vim">curl -X 'GET' \
'http://<a data-footnote-ref href="#user-content-fn-1">MON_INSTANCE</a>/api.php/Assistance/Ticket/<a data-footnote-ref href="#user-content-fn-7">ID</a>/Timeline/Document' \
-H 'accept: application/json' \
-H 'Accept-Language: fr_FR' \
-H 'Authorization: Bearer <a data-footnote-ref href="#user-content-fn-6">MON_TOKEN</a>'
</code></pre>

### Utilisateur

#### Créer un utilisateur :

<pre class="language-vim" data-overflow="wrap"><code class="lang-vim">curl -X 'POST' \'https://<a data-footnote-ref href="#user-content-fn-1">MON_INSTANCE</a>/api.php/Administration/User' \
-H 'accept: application/json' \
-H 'Accept-Language: fr_FR' \
-H 'Authorization: Bearer <a data-footnote-ref href="#user-content-fn-6">MON_TOKEN</a>' \
-H 'Content-Type: application/json' \
-d '{
"username": "string",
"realname": "string",
"firstname": "string",
"phone": "string",
"phone2": "string",
"mobile": "string",
"emails": [
{
  "id": 0,
  "email": "string",
  "is_default": true,
  "is_dynamic": true
  }
],
"comment": "string",
"is_active": true,
"is_deleted": false,
"password": "string",
"password2": "string",
"location": {"id": 0},
"authtype": 1,
"last_login": "AAAA-MM-JJ HH:MM:SS",
"default_profile": {"id": 0},
"default_entity": {},
"date_creation": "AAAA-MM-JJ HH:MM:SS",
"date_mod": "AAAA-MM-JJ HH:MM:SS",
"title": {"id": 0},
"category": {"id": 0},
"registration_number": "string",
"begin_date": "AAAA-MM-JJ HH:MM:SS",
"end_date": "AAAA-MM-JJ HH:MM:SS",
"nickname": "string",
"substitution_start_date": "AAAA-MM-JJ HH:MM:SS",
"substitution_end_date": "AAAA-MM-JJ HH:MM:SS" }'
</code></pre>

#### Supprimer un utilisateur

<pre class="language-vim" data-overflow="wrap"><code class="lang-vim">curl -X 'DELETE' \
'https://<a data-footnote-ref href="#user-content-fn-1">MON_INSTANCE</a>/api.php/Administration/User/<a data-footnote-ref href="#user-content-fn-8">ID</a>?force=true' \
-H 'accept: */*' \
-H 'Accept-Language:  fr_FR' \
-H 'Authorization: Bearer <a data-footnote-ref href="#user-content-fn-6">MON_TOKEN</a>'
</code></pre>

### Profil

#### Lister les profils

<pre class="language-vim" data-overflow="wrap"><code class="lang-vim">curl -X 'GET' \
'https://<a data-footnote-ref href="#user-content-fn-1">MON_INSTANCE</a>/api.php/Administration/Profile' \
-H 'accept: application/json' \
-H 'Accept-Language: fr_FR \
-H 'Authorization: Bearer <a data-footnote-ref href="#user-content-fn-6">MON_TOKEN</a>'
</code></pre>

### Entité

#### Lister les entités

<pre class="language-vim" data-overflow="wrap"><code class="lang-vim">curl -X 'GET' \
'https://<a data-footnote-ref href="#user-content-fn-1">MON_INSTANCE</a>/api.php/Administration/Entity' \
-H 'accept: application/json' \
-H 'Accept-Language: fr_FR' \
-H 'Authorization: Bearer <a data-footnote-ref href="#user-content-fn-6">MON_TOKEN</a>'  
</code></pre>

#### Voir les détails d’une entités

<pre class="language-vim" data-overflow="wrap"><code class="lang-vim">curl -X 'GET' \
https://<a data-footnote-ref href="#user-content-fn-1">MON_INSTANCE</a>/api.php/Administration/Entity/<a data-footnote-ref href="#user-content-fn-9">ID</a>' \
-H 'accept: application/json' \
-H 'Accept-Language: fr_FR' \
-H 'Authorization: Bearer <a data-footnote-ref href="#user-content-fn-6">MON_TOKEN</a>'
</code></pre>

### Status

#### Voir le statut des services GLPI

<pre class="language-vim" data-overflow="wrap"><code class="lang-vim">curl -X 'GET' \
'https://<a data-footnote-ref href="#user-content-fn-1">MON_INSTANCE</a>/api.php/status' \
-H 'accept: */*' \
-H 'Accept-Language: fr_FR' \
-H 'Authorization: Bearer <a data-footnote-ref href="#user-content-fn-6">MON_TOKEN</a>'
</code></pre>

[^1]: A modifier par le nom de votre instance

[^2]: A modifier par l'ID de votre client précédemment créé

[^3]: A modifier par le secret client  précédemment créé

[^4]: A modifier par votre utilisateur

[^5]: A modifier par le mot de passe utilisateur

[^6]: A modifier par le token généré précédemment

[^7]: A remplacer par l'ID du ticket

[^8]: A remplacer par l'ID de l'utilisateur

[^9]: A remplacer par l'ID de l'entité


---

# 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, and the optional `goal` query parameter:

```
GET https://help.glpi-project.org/tutorials/fr/readme-1/api-v2.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
