How to Initialize the GLPI API Connection

Command line template

curl -X GET \
-H 'Content-Type: application/json' \
-H "Authorization: user_token [USER_TOKEN]" \
-H "App-Token: [APP_TOKEN]" \
'[GLPI_URI]/apirest.php/initSession'

Parameters to fill in

  • USER_TOKEN : token generated in GLPI
    1. My Settings (at the URI [GLPI_URI]/front/preference.php)
    2. Tab “Main”
    3. Field “API token”
  • APP_TOKEN : token generated in GLPI (prerequisite : an API should have been configured before)
    1. Setup>General>Api Clients (at the URI [GLPI_URI]/front/preference.php)
    2. Select the API Client to use
    3. Tab “Api Client”
    4. Field “Application Token (app_token)”
  • GLPI_URI : the location of GLPI

Commande line response

The response is a JSON :

Case 1 (the good one)

{"session_token":"[THE_SESSION_TOKEN_TO_USE]"}

Congratulation! The connection is succefuly initialized!

Memorize the token provided for the next calls.

Case 2

{"ERROR_WRONG_APP_TOKEN_PARAMETER","[ERROR_DESCRIPTION]"}

Verify the token entered for “App-Token“.

In case of doubt, regenerate the token (check the box “Regenerate” and Save in GLPI) and use the new one.

Case 3

{"ERROR_GLPI_LOGIN_USER_TOKEN","[ERROR_DESCRIPTION]"}

Verify the token entered for “user_token“.

In case of doubt, regenerate the token (check the box “Regenerate” and Save in GLPI) and use the new one.

Other Cases ?

Maybe a call from un unauthorized IP… So verify your Client API configuration on IPs section.

Maybe… sorry! I haven’t caused any other cases.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *