> 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/readme-1/api-v2.md).

# API V2 🆕

## Concept

When using the GLPI API, communication occurs in a universal language called JSON (a very simple text format to read) and relies on the standard web network (HTTP), with 4 main actions:

* **GET (Read)**: Give me the list of computers at the Lyon site.
* **POST (Create)**: Create a new ticket with the title 'Internet outage'.
* **PUT/PATCH (Update)**: Change the status of computer #45 to 'Under repair'.
* **DELETE (Delete)**: Delete ticket #1234.

Each request is sent to a specific URL, called an Endpoint (e.g., `https://my-glpi.com/api.php/Ticket`).

***

## What is it for?

The API allows, among other things, to automate time-consuming tasks and simplify repetitive actions:

* **Supervision (Monitoring)**: Instead of sending a simple email, the API can automatically create a critical ticket and assign it to the network team in GLPI.
* **Human Resources**: When the HR department adds an employee to their software, it automatically transmits the data to GLPI via the API to create a user account, generate a PC preparation ticket, and assign a software license.
* **External Reporting**: A Python script that queries the API every evening to retrieve the number of open tickets and display it on a screen in the open-space.

***

## Creating an Oauth Client

To use the API, GLPI requires an OAuth client to be configured. This client will generate a **`Client ID`** and a **`Client secret`**, which are essential for authorizing API usage.

* From **`Configuration`** > **`OAuth clients,`** click on **`+ Add`**
* Enter:
  * **A name**
  * The relevant **`scopes`**: email, user, api, inventory, status, graphql
  * The **authorization type** (grants): Password, Clients credentials, Authorization code
* **Save** your OAuth client
* Click on your OAuth client, and note the 2 values:
  * **`Client ID`**
  * **`Client secret`**

<figure><img src="/files/0zFjBhmr3qi00Gp1YgwG" alt=""><figcaption><p><em>OAuth Client Creation</em></p></figcaption></figure>

***

## Method 1 - API Endpoints

The recommended method is to use the **`API Endpoints`** feature natively available in GLPI. You can find the URL at:

* **`Configuration`** > **`General`** > **`API`** > **`API Endpoints`**
* Or at the address <https://my_instance/api.php/v2.2/doc>

{% stepper %}
{% step %}

### Connect the OAuth Client

* From **`Configuration`** > **`General`** > **`API`** > **`API Endpoints`**, click on **`Authorize`**
* Enter the **`Client ID`** and **`Client secret`** noted in the previous step
* Select the desired scopes
* Click on **`Authorize`**
* Validate the consent screen

<figure><img src="/files/ko4kRIGM0mclkBhAGp5t" alt=""><figcaption><p>Available authorizations</p></figcaption></figure>
{% endstep %}

{% step %}

### Usage

* From **`Configuration`** > **`General`** > **`API`** > **`API Endpoints`** or <https://my_instance/api.php/v2.2/doc>, select the module you need

<figure><img src="/files/P8Y2iubW05qcC0BlzFE1" alt=""><figcaption><p>API's objects list </p></figcaption></figure>

* In our example, we will display ticket with **`id 60`**
* From **`Administration`**, select <mark style="background-color:$primary;">**GET**</mark>\*\* /Assistance/Ticket/{id}\*\*
* Click on **`Try it out`**
* Enter the **ticket number**
* Click on **`Execute`**

<figure><img src="/files/tAMmG7p51DsLNTlidnzH" alt=""><figcaption><p>Enter the API request parameters</p></figcaption></figure>

**Response**:

<figure><img src="/files/bdHXUcIkMO8VrPg8LlJa" alt=""><figcaption><p>Response to the request</p></figcaption></figure>

* In this first box, you will find:
  1. **Curl**: The request used
  2. **The Request URL**
  3. **The request response**: the content of our ticket
  4. **The header response**: a list of parameters in "Key: Value" format (request weight, timestamp, formatting, etc.).
* In another box, you will find the raw values of the request, i.e., the schema used.

<figure><img src="/files/tPZWVboYzNU4n6jTa2pm" alt=""><figcaption></figcaption></figure>

* It is also possible to view the schema and the expected value type in list mode by clicking on **`Schema`**

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

***

## Method 2 - Via curl requests

{% stepper %}
{% step %}

### Token Initialization

Enter this command in a terminal:

<pre class="language-viml"><code class="lang-viml">curl -X POST 'https://<a data-footnote-ref href="#user-content-fn-1">MY_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">MY_CLIENT_ID</a>'
--data 'client_secret=<a data-footnote-ref href="#user-content-fn-3">MY_CLIENT_SECRET</a>'
--data 'username=<a data-footnote-ref href="#user-content-fn-4">MY_USER</a>'
--data 'password=<a data-footnote-ref href="#user-content-fn-5">MY_PASSWORD</a>'
--data 'scope=api'
</code></pre>

A similar result will be returned:

{% 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" %}
The **`access token`** is the important information that will be requested for each command you type.
{% endhint %}
{% endstep %}
{% endstepper %}

***

## Example Commands

{% hint style="danger" %}
If you do not wish to fill in certain fields in your requests, you can either indicate the value **`"null"`** (e.g., **`"sla_ttr": null`**) or remove them from your request. The essential thing is that your `json` is correctly structured. All values containing an **`"id": 0`** must also be replaced by the value **`null`**
{% endhint %}

### Tickets

#### Create a ticket:

{% hint style="warning" %}
**Limitation**:

The expected format for dates is **`"YYYY-MM-DD HH:MM:SS"`**. The variable **`$date-time`** is not applicable at this time (currently being corrected by the technical teams).
{% endhint %}

<pre class="language-vim"><code class="lang-vim">curl -X 'POST' \
'https://<a data-footnote-ref href="#user-content-fn-1">MY_INSTANCE</a>/api.php/Assistance/Ticket' \
-H 'accept: application/json' \
-H 'Accept-Language: en_GB' \
-H 'Authorization: Bearer <a data-footnote-ref href="#user-content-fn-6">MY_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": "YYYY-MM-DD HH:MM:SS",
  "date_mod": "YYYY-MM-DD HH:MM:SS",
  "date": "YYYY-MM-DD HH:MM:SS",
  "date_solve": "YYYY-MM-DD HH:MM:SS",
  "date_close": "YYYY-MM-DD 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>

#### Retrieve the content of a ticket:

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

#### Retrieve the solution of a ticket:

<pre class="language-vim"><code class="lang-vim">curl -X 'GET' \
'http://<a data-footnote-ref href="#user-content-fn-1">MY_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: en_GB' \
-H 'Authorization: Bearer <a data-footnote-ref href="#user-content-fn-6">MY_TOKEN</a>'
</code></pre>

#### Retrieve the documents of a ticket:

<pre class="language-vim"><code class="lang-vim">curl -X 'GET' \
'http://<a data-footnote-ref href="#user-content-fn-1">MY_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: en_GB' \
-H 'Authorization: Bearer <a data-footnote-ref href="#user-content-fn-6">MY_TOKEN</a>'
</code></pre>

### User

#### Create a user:

<pre class="language-vim"><code class="lang-vim">curl -X 'POST' \'https://<a data-footnote-ref href="#user-content-fn-1">MY_INSTANCE</a>/api.php/Administration/User' \
-H 'accept: application/json' \
-H 'Accept-Language: en_GB' \
-H 'Authorization: Bearer <a data-footnote-ref href="#user-content-fn-6">MY_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": "YYYY-MM-DD HH:MM:SS",
"default_profile": {"id": 0},
"default_entity": {},
"date_creation": "YYYY-MM-DD HH:MM:SS",
"date_mod": "YYYY-MM-DD HH:MM:SS",
"title": {"id": 0},
"category": {"id": 0},
"registration_number": "string",
"begin_date": "YYYY-MM-DD HH:MM:SS",
"end_date": "YYYY-MM-DD HH:MM:SS",
"nickname": "string",
"substitution_start_date": "YYYY-MM-DD HH:MM:SS",
"substitution_end_date": "YYYY-MM-DD HH:MM:SS" }'
</code></pre>

#### Delete a user

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

### Profile

#### List profiles

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

### Entity

#### List entities

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

#### View entity details

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

### Status

#### View GLPI service status

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

[^1]: Replace with the name of your instance

[^2]: To be modified by the ID of your previously created client

[^3]: To be modified by the previously created customer secret

[^4]: To be modified by your user

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

[^6]: To be modified by the previously generated token

[^7]: Replace the ticket ID

[^8]: Replace the entity ID


---

# 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/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.
