GLPI/Configuration/Générale/API/Exemple 2
Exemple de script PowerShell d'utilisation de l'API GLPI.
Source :
- Jean-Christophe Pirmolin, sur Linkedin :
- https://www.linkedin.com/in/jean-christophe-pirmolin/
Autre source identique :
Exemple
# Paramètres de connexion à GLPI
$AppURL = "http://php100/glpi/apirest.php" # adresse principale
$AppToken = "Zqi1p7YrUF5Sj0SxmGCCFYekznO3Bvqz76SNU66m" # app_Token, du menu config > général : client d'API
$UserToken = "ZwHRn0wg9HvphYFEKY01sStlNIsBd7hkuaDK6bnv" # se trouve sur la fiche de l'utilisateur
$demandeurName = "phil" # Remplacez par le nom du demandeur que vous souhaitez rechercher
# création d'une session
$SessionToken = Invoke-RestMethod "$AppURL/initSession" -Method Get -Headers @{"Content-Type" = "application/json";"Authorization" = "user_token $UserToken";"App-Token"=$AppToken}
# recherche
$SearchResult = Invoke-RestMethod "$AppURL/Computer/" -Headers @{"session-token"=$SessionToken.session_token; "App-Token" = "$AppToken"}
$SearchResult | Format-Table -AutoSize