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

OAuth Client Creation

Method 1 - API Endpoints

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

1

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

Available authorizations
2

Usage

API's objects list
  • In our example, we will display ticket with id 60

  • From Administration, select GET** /Assistance/Ticket/{id}**

  • Click on Try it out

  • Enter the ticket number

  • Click on Execute

Enter the API request parameters

Response:

Response to the request
  • 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.

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


Method 2 - Via curl requests

1

Token Initialization

Enter this command in a terminal:

A similar result will be returned:

The access token is the important information that will be requested for each command you type.


Example Commands

Tickets

Create a ticket:

Retrieve the content of a ticket:

Retrieve the solution of a ticket:

Retrieve the documents of a ticket:

User

Create a user:

Delete a user

Profile

List profiles

Entity

List entities

View entity details

Status

View GLPI service status

Last updated