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 2020-06-29 11:01:26

mineli
Member
Registered: 2020-06-29
Posts: 2

Unable to get API token by user ID

Hello,

I am using the Rest API on version 9.4.6 and I need to get the user's API token by using its user ID.

I used the user's email and made a following query to find the user ID and it works fine:
 
  $ch = curl_init();
  $url = $api_url . "/search/User?start=0&criteria[0][link]=AND&criteria[0][field]=2&criteria[0][searchtype]=equals&criteria[0][value]=&criteria[1][link]=AND&criteria[1][field]=5&criteria[1][searchtype]=contains&criteria[1][value]=" . $email;
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  $json = curl_exec($ch);
  $obj = json_decode($json, true);
  $user_id = $obj['data'][0][2];
 

I then used the following query to retrieve the user's data:

  $ch = curl_init();
  $url = $api_url . "/User/" . $user_id;
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  $json = curl_exec($ch);
  $obj = json_decode($json, true);

However, in the resulting array there is no API token, just api_token_date, which is actually a date. There is no api_token value.

I received the following result:

array (size=80)
  'id' => int 8
  'name' => string 'user-ponc-rec' (length=13)
  'phone' => string '' (length=0)
  'phone2' => string '' (length=0)
  'mobile' => string '' (length=0)
  'realname' => string '' (length=0)
  'firstname' => string '' (length=0)
  'locations_id' => int 0
  'language' => null
  'use_mode' => int 0
  'list_limit' => null
  'is_active' => int 1
  'comment' => string '' (length=0)
  'auths_id' => int 0
  'authtype' => int 1
  'last_login' => string '2020-06-29 16:16:08' (length=19)
  'date_mod' => string '2020-06-30 09:04:34' (length=19)
  'date_sync' => null
  'is_deleted' => int 0
  'profiles_id' => int 1
  'entities_id' => int 1
  'usertitles_id' => int 0
  'usercategories_id' => int 0
  'date_format' => null
  'number_format' => null
  'names_format' => null
  'csv_delimiter' => null
  'is_ids_visible' => null
  'use_flat_dropdowntree' => null
  'show_jobs_at_login' => null
  'priority_1' => null
  'priority_2' => null
  'priority_3' => null
  'priority_4' => null
  'priority_5' => null
  'priority_6' => null
  'followup_private' => null
  'task_private' => null
  'default_requesttypes_id' => null
  'password_forget_token' => null
  'password_forget_token_date' => null
  'user_dn' => null
  'registration_number' => string '' (length=0)
  'show_count_on_tabs' => null
  'refresh_ticket_list' => null
  'set_default_tech' => null
  'personal_token_date' => null
  'api_token_date' => string '2020-06-05 08:48:05' (length=19)
  'cookie_token_date' => string '2020-06-05 09:20:03' (length=19)
  'display_count_on_home' => null
  . . . .

So, there are personal_token_date and api_token_date but no actual values of those.

Is there a way to get the API token by using the user's ID? Do I use a good query or am I missing something here?

Just to mention, in the post forum.glpi-project.org/viewtopic.php?id=162759, the user succeeded in retrieving the API token (api_token) by using the same query as above.

Any help is highly appreciated as I lost significant amount of time looking for the answer!!

Thanks,
Nebo

Last edited by mineli (2020-06-30 09:19:34)

Offline

#2 2021-04-22 09:27:08

7Upers
Member
Registered: 2021-04-22
Posts: 1

Re: Unable to get API token by user ID

Hello friend!
did you find out the answer on your question? i have the same trouble!

Offline

Board footer

Powered by FluxBB