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-23 20:46:32

andrusaren
Member
Registered: 2020-02-13
Posts: 6

API usage

I'm trying to use API to add some servers (approx 700 or so) automatically with curl -X POST.
One example: Let's say i need to add Operating system kernel version. Directly from database (select * from glpi_operatingsystemkernelversions;), i can see that ID is 1 and name is "4.19.0-8-amd64". - just for testing i inserted over UI that kernel version.
So, if i understand correctly, i can only use ID value IF it already is in database?
Or is there a way to post with curl JSON payload and GLPI makes new ID or something like that
Just a none working sample what i already tried:
curl -X POST \
-H 'Content-Type: application/json' \
-H "Session-Token: sdorbe11uvuaerhme402ptodh0" \
-H "App-Token: xaUpsYh2wd7mTMlEo9KabFHybQXAKrADMXGGiYWp" \
-d '{"input": [ {"name": "testing", "operatingsystemarchitectures": "x86_64", "operatingsystemkernelversions": "4.19.0-8-amd64", "dropdown_operatingsystemeditions_id": "bullseye"}]}' \
'http://localhost/apirest.php/Computer/'

This payload just makes new "computer" named Testing without no additional data.

Offline

#2 2021-04-25 11:07:00

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

Re: API usage

you should first Get Id in  using search endpoint:
/search/Operatingsystemarchitecture/?is_deleted=0&criteria[0][link]=AND&criteria[0][field]=1&criteria[0][searchtype]=contains&criteria[0][value]=^x86_64$&forcedisplay[0]=2

if not exists then create it using POST METHOD

*** url***
[...]/glpi955/apirest.php/Operatingsystemarchitecture/
***********payload*********
{"input" : {"name" :"MyOSArchitectureName", "comment" : "My Comment"}}


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