You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2025-02-26 10:56:29

muzzol
Member
Registered: 2009-05-18
Posts: 15

New API examples

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

#2 2025-02-26 12:29:10

cconard96
Moderator
Registered: 2018-07-31
Posts: 3,226
Website

Re: New API examples

It would be better to create a separate GLPI instance with the latest nightly "main" release and test it for yourself wink.
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

#3 2025-03-04 13:04:04

muzzol
Member
Registered: 2009-05-18
Posts: 15

Re: New API examples

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


cC1EiOK.jpeg

Last edited by muzzol (2025-03-04 13:09:35)

Offline

#4 2025-03-06 23:47:19

cconard96
Moderator
Registered: 2018-07-31
Posts: 3,226
Website

Re: New API examples

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

Board footer

Powered by FluxBB