You are not logged in.
Pages: 1
hi,
anyone tried the new API 2.0 for version 11?
I would like to see some working examples.
Thanks for your time,
muzzol
Offline
It would be better to create a separate GLPI instance with the latest nightly "main" release and test it for yourself .
We added support for Swagger UI which lets you run API calls directly from the browser and see the equivalent Curl calls, see all available endpoints, and see the format for all parameters and outputs.
You can find links to both the Getting Started documentation and the Swagger UI from Setup > General > API tab.
If you need help with the new API after looking at the documentation, feel free to ask and I will try to help.
GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.
Offline
yeah, I already have a new instance (main-bc82717) and I'm testing a lot of new features. it's great!
but I can't find a working example for authentication with new API, all examples are from old API.
besides that, when I click on Authorize I get a 404 and I think that's because API urls are not honoring context /glpi11/api.php/authorize and they assume they're at top level /api.php/authorize
Last edited by muzzol (2025-03-04 13:09:35)
Offline
Indeed, there was probably an issue here. I created a pull request and the fix should be in the latest nightly "main" release now.
https://github.com/glpi-project/glpi/pull/19128
For authentication examples, it is standard OAuth stuff and explained in the new API's Getting Started documentation as I mentioned before. Although, I see that it needs updated to reflect that scopes are now required. For general API access, the scope required is "api".
In most cases when interacting with the API, you would probably use the password grant type:
curl --request POST \
--url YOUR_GLPI/api.php/token \
--header 'Content-Type: application/json' \
--data '{
"grant_type": "password",
"client_id": "YOUR OAUTH CLIENT ID",
"client_secret": "YOUR OAUTH CLIENT SECRET",
"scope": "api",
"username": "glpi",
"password": "glpi"
}'
You will get an access token in the response which will need to be used for other API requests in the Authorization header (Bearer type).
The other supported OAuth grant type is Authorization Code which requires user interaction at "/api.php/authorize". It gives the user a GLPI login page to enter their credentials, returns a "code" to be used on "/api.php/token" to finally get an access token.
GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.
Offline
Pages: 1