You are not logged in.
Pages: 1
Topic closed
Hello, Im trying to create an automation that retrieves all entries of all kind of assets.
When I make a GET request for a specific asset type, for example computers,
I get a json containing all the information regarding computer but for instance in the "Manufacturer" field I get a link to the other table in the db through API.
Is there a way to receive the data back with the actual values, instead of links?
Offline
you could add
expand_dropdowns =1
and
add_keys_names=1
this might give you names instead of IDs
Trouver la panne avant de réparer...
GLPI10.0.16 (ubuntu 22.04 PHP8.1 Mariadb10.6 ) plugins : comportements 2.7.3 reports 1.16.0 formcreator 2.13.9, datainjection 2.13.5 fields 1.21.9
Offline
when using add_keys_names=1 I get empty response.
Offline
The "add_keys_names" parameter expects an array of field names. Its usage is frankly confusing, but the pull request that added may shed some light on it:
https://github.com/glpi-project/glpi/pull/6858
For the original question, expand_dropdowns=1 should be enough I think.
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
I could not quite understand how to make it work. maybe you can shed some light on where I'm doing it wrong:
self.get(type, expand_dropdowns=1, range='0-150', add_keys_names=['ComputerModel', 'ComputerType', 'Manufacturer', 'User']).json()
assuming self.get receieves 'type' === endpoint, and keyworded arguments as parameters.
I've tried
add_keys_names=['ComputerModel', 'ComputerType', 'Manufacturer', 'User'])
and also
add_keys_names="['ComputerModel', 'ComputerType', 'Manufacturer', 'User']")
but none seems to work.
Offline
also, I'm getting back username, and I'd like to have User full name instead, is that possible?
Offline
Probably not. You need to make multiple API requests if you want more information. One request for the asset itself and then separate requests to each associated item you want more info for.
This will be improved with GLPI 11 and the new REST API which has a GraphQL wrapper which lets you ask for data across different "schemas".
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
I'm trying to fill the relations manually with additional API calls but it seems the href's supplied in the LINKS columns are broken.
for instance:
{'rel': 'MonitorType', 'href': 'https://localhost/apirest.php/MonitorType/1'}
// but when making request to
https://<actual-ip>/apirest.php/MonitorType/1
// I get back this error:
"ERROR_RESOURCE_NOT_FOUND_NOR_COMMONDBTM","resource not found or not an instance of CommonDBTM; view documentation in your browser at https://localhost/apirest.php/#ERROR_RESOURCE_NOT_FOUND_NOR_COMMONDBTM"
// I've looked into the error docs @ <relevant-ip>/glpi/apirest.php but it seems ERROR_RESOURCE_NOT_FOUND_NOR_COMMONDBTM is not documented.
any inputs from you on this one?
Last edited by galctco (2024-04-10 14:03:02)
Offline
glpi 10.0.14 :
On my instance this url
https://Myglpiserver/apirest.php/MonitorType/13/
returns
{"date_creation":null,"date_mod":null,"id":13,"name":"LCD 20\"","comment":""}
also
https://myglpiserver/apirest.php/Monitor/8725/?expand_dropdowns=1
returns
{"is_recursive":0,
"date_creation":null,
"id":8725,
...
,"monitortypes_id":"LCD 20",
...
,"links":[ ...{"rel":"MonitorType","href":"https://Myglpiserver/apirest.php/MonitorType/13"}...}
Trouver la panne avant de réparer...
GLPI10.0.16 (ubuntu 22.04 PHP8.1 Mariadb10.6 ) plugins : comportements 2.7.3 reports 1.16.0 formcreator 2.13.9, datainjection 2.13.5 fields 1.21.9
Offline
Bug found in my code. thank you for your support gentlemen. carry on and lock this thread (writes with shame...)
Offline
Pages: 1
Topic closed