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 2018-11-08 15:07:34

Pandita
Member
From: Poland
Registered: 2018-01-22
Posts: 21

REST API - simple question

Hi guys,

is it possible to access FusionInventory fields in computer via REST API? I cant find info anywhere.
To precise I need info about agent. So I would like to access this field directly.

sth like
/api/computer/123/FusionInventoryAgentID
to return: computer-2018-20-02-10-20

Offline

#2 2018-11-08 18:07:27

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

Re: REST API - simple question

try this :
 

…...API/search/PluginFusioninventoryAgent?criteria[0][field]=6&criteria[0][searchtype]=contains&criteria[0][value]=$myComputerId


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

#3 2018-11-09 12:03:59

Pandita
Member
From: Poland
Registered: 2018-01-22
Posts: 21

Re: REST API - simple question

Thanks for the reply, althought its not useful for me. The problem is on the server I dont have info about computers' ids in Glpi database. I just have agent id (such as computer-2018-20-02-10-20) which cannot be included in search AFAIK.

Offline

#4 2018-11-09 12:22:00

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

Re: REST API - simple question

and with thi url ?

$url=$api_url . "/search/PluginFusioninventoryAgent?criteria[0][field]=1&criteria[0][searchtype]=contains&criteria[0][value]=computername-2015-05-20-08-14-04";


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

#5 2018-11-09 13:55:35

Pandita
Member
From: Poland
Registered: 2018-01-22
Posts: 21

Re: REST API - simple question

Thanks man! It worked big_smile
Please take a look at the output:
'data': [{'1': 'hostname-2015-03-21-00-25-04', '2': 'entity', '4': '2018-11-09 02:53:04', '5': 0, '6': 'hostname-2015-03-21-00-25-04', '7': 'hostname', '8': '{"INVENTORY":"v2.4.1-dev"}', '9': 12345678}]
Do you have an idea how to access directly "hostname" object? I can't use searching based on hostname becouse of  duplicates. I need the object linked with this specific agent.

Offline

#6 2018-11-09 15:15:44

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

Re: REST API - simple question

I'm not sure i understand your need.

try this

$url=$api_url . "/search/PluginFusioninventoryAgent?criteria[0][field]=7&criteria[0][searchtype]=contains&criteria[0][value]=hostname";


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

#7 2018-11-09 15:47:22

Pandita
Member
From: Poland
Registered: 2018-01-22
Posts: 21

Re: REST API - simple question

This one also returned 'data': [{'1': 'hostname-2015-03-21-00-25-04', '2': 'entity', '4': '2018-11-09 02:53:04', '5': 0, '6': 'hostname-2015-03-21-00-25-04', '7': 'hostname', '8': '{"INVENTORY":"v2.4.1-dev"}', '9': 12345678}].

Explanation

Let's say I have a server named "hostname". In Glpi it is linked with FusionInv agent (say hostname-2015-03-21-00-25-04).
Now lets say I want to set serial number for this server, but I all can use is FusionInv agent (hostname-2015-03-21-00-25-04). I do not know ID of server linked with it, or anything else.

So now using your solution, I can search for hostname-2015-03-21-00-25-04. In return I got  [{'1': 'hostname-2015-03-21-00-25-04', '2': 'entity', '4': '2018-11-09 02:53:04', '5': 0, '6': 'hostname-2015-03-21-00-25-04', '7': 'hostname', '8': '{"INVENTORY":"v2.4.1-dev"}', '9': 12345678}].
"7" is a hostname of server connected with this agent. In Glpi gui I can click on it and see details of "hostname" object.
How to set serial number this way using API? I could search for returned "hostname", but what if i have 3 servers with same hostname? That's why I need to access exact "server object" in Glpi linked with FusInv agent.

Offline

#8 2018-11-09 16:43:43

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

Re: REST API - simple question

i think i got it but it needs some class modification :

i add a seach option in plugins/fusioninventory/inc/agent.class.php   function : rowSearchOptions()

      $tab[] = [
         'id'        => '15',
         'table'     => $this->getTable(),
         'field'     => 'id',
         'name'      =>__('ID'),
         'datatype'  => 'integer',
      ];

then i search agent by name forcing display of id  (index 15) :

$url=$api_url . "/search/PluginFusioninventoryAgent?criteria[0][field]=1&criteria[0][searchtype]=contains&criteria[0][value]=computername-2015-05-20-08-14-04&forcedisplay[0]=15";

then you  get agent id =>$agentid

and get aget : $url=$api_url . "/PluginFusioninventoryAgent/$agentid";


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

#9 2018-11-13 10:16:44

Pandita
Member
From: Poland
Registered: 2018-01-22
Posts: 21

Re: REST API - simple question

That's it! Thank you very much smile

Offline

#10 2018-11-13 10:29:52

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

Re: REST API - simple question

this will be lost on plugin upgrade.

I request this new search option  in GitHub
https://github.com/fusioninventory/fusi … ssues/2713


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

Board footer

Powered by FluxBB