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 2021-04-13 21:47:22

djwhite
Member
Registered: 2015-10-25
Posts: 29

Getting a users ID when searching email address via API

Hi All

I'm trying to get a users ID when searching the API for an email address, but it doesn't return the ID.

The search I am using is:
https://myserver/apirest.php/search/User?criteria[0][field]=5&criteria[0][searchtype]=contains&criteria[0][value]=" + requester +"&forcedisplay=[1,2,5,9,13,14,80]"

However with or without forced display it won't return field 2, the ID.

Is there another way to get the users ID by querying the email address?

GLPI V9.2.1

Many thanks

David

Offline

#2 2021-04-13 22:07:16

mecmav
Member
From: Brasil
Registered: 2019-03-22
Posts: 326

Re: Getting a users ID when searching email address via API

Maybe this is a issue of this version.

I already used the 9.2.1, but it's have many bugs.

Offline

#3 2021-04-13 23:20:03

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 6,167

Re: Getting a users ID when searching email address via API

try this url : (it works with glpi  9.5.4)

$url="/search/User?criteria[0][field]=5&criteria[0][searchtype]=contains&criteria[0][value]=".myemail."&forcedisplay[0]=1&forcedisplay[1]=2&forcedisplay[2]=5&forcedisplay[3]=9&forcedisplay[4]=14&forcedisplay[5]=80";

edit : moved to API section


Trouver la panne avant de réparer...
GLPI10.0.10 (ubuntu 22.04 PHP8.1  Mariadb10.6 ) plugins : comportements 2.7.2 reports 1.16.0 formcreator 2.13.8, datainjection 2.13.4 fields 1.21.6

Offline

#4 2021-04-13 23:22:37

djwhite
Member
Registered: 2015-10-25
Posts: 29

Re: Getting a users ID when searching email address via API

LaDenrée wrote:

try this url : (it works with glpi  9.5.4)

$url="/search/User?criteria[0][field]=5&criteria[0][searchtype]=contains&criteria[0][value]=".myemail."&forcedisplay[0]=1&forcedisplay[1]=2&forcedisplay[2]=5&forcedisplay[3]=9&forcedisplay[4]=14&forcedisplay[5]=80";

edit : moved to API section

Fantastic, that worked perfectly. Many thanks for your help.

Offline

#5 2022-08-31 22:17:47

androB
Member
Registered: 2022-08-31
Posts: 2

Re: Getting a users ID when searching email address via API

This code is perfect, however when I am trying to search the user based on name example user login is 3000022 but it doesn't work, if I replace 3000022 with email address then it works,

any idea how to get the user ID # by searching the name/login_name ?

I am trying to get

// GET USER ID

$name = "3000022";

        $api_url="http://192.168.252.102/apirest.php";
        $url = $api_url . "/search/User?criteria[0][field]=1&criteria[0][searchtype]=contains&criteria[0][value]=^". $name. "$&forcedisplay[0]=2";
        //$url=$api_url . "/listSearchOptions/User";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');


        //curl_setopt($ch, CURLOPT_POSTFIELDS,$input);
        $json = curl_exec($ch);
        curl_close($ch);

        $obj = json_decode($json, true);
        $agentbadge = $obj['data']['0']['2'];
        echo "AgentBadge: $agentbadge";

Online

Offline

Board footer

Powered by FluxBB