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 2022-10-24 23:02:09

michaelholtz
Member
Registered: 2022-10-24
Posts: 1

API - search userid by username

Hello !

I need to find the user id via API by username.
I already got it by email.

Thanks in advance!

Offline

#2 2022-10-27 00:17:31

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,813
Website

Re: API - search userid by username

It will be easier with the new API that is coming:
https://github.com/glpi-project/glpi/pull/12221

Until then, a tip with using the search in the current API, you can make the search you want in the web interface and then copy the "?" and everything after it and use that in your API request.

For example, if I search "Login contains 'test'" in my users I get:
?is_deleted=0&as_map=0&browse=0&criteria%5B0%5D%5Blink%5D=AND&criteria%5B0%5D%5Bfield%5D=1&criteria%5B0%5D%5Bsearchtype%5D=contains&criteria%5B0%5D%5Bvalue%5D=test&itemtype=User&start=0&_glpi_csrf_token=3a42e026c0f81301da8df439bea3f9f7d5bea5d5a48b1973ad26fb5b0afcfc1a&sort%5B%5D=1&order%5B%5D=ASC

You can remove the "_glpi_csrf_token" parameter since it isn't needed in the API call.

Then, the API search call would be:
/apirest.php/search/User?is_deleted=0&as_map=0&browse=0&criteria%5B0%5D%5Blink%5D=AND&criteria%5B0%5D%5Bfield%5D=1&criteria%5B0%5D%5Bsearchtype%5D=contains&criteria%5B0%5D%5Bvalue%5D=test&itemtype=User&start=0&&sort%5B%5D=1&order%5B%5D=ASC

You can replace the "test" text in the search parameters to whichever username you are searching for, but at least this way you don't need to try and find the internal search ID for the login field or need to manually build the search criteria parameters.


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