You are not logged in.
hello,
I use the following powershell code:
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Content-Type','Application/Json')
$headers.Add('Session-Token', $GLPI_Session)
$headers.Add('App-Token', $GLPI_Apikey)
$json = '{"input": { "id":71 , "comment": "test"}}'
$result = Invoke-WebRequest -Uri ($GLPI_ApiUrl+'/Computer') -Body $json -ContentType "application/json" -Headers $headers -Method POST
What I will do is trying to update the comment field, and after if this is working the purch date, warranty expiration.
But it's now not updating the computer with id 71, it is adding a new compiter with an other id.....
Can someone help me how to update otherfiels then comment and on the right computer.
Kind regards Erwin
Offline
to update use PUT method, ( not POST)
PS : i move to APIREST Section
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
Many Thanks, you're my hero it works indeed.
One question more, how to findthe field name's? for example i will put some text in the 'Warranty information' but how is the field called?
so i can update it with the api.
Last edited by ernieek (2018-12-11 12:40:25)
Offline
there are diffrent ways :
1) with API :
/listSearchOptions/Infocom/
returns fields with indexes
…
[7] => Array (
[name] => Informations sur la garantie
[table] => glpi_infocoms [field] => warranty_info
[datatype] => string
[nosearch] =>
[nodisplay] =>
[available_searchtypes] => Array ( [0] => contains )
[uid] => Infocom.warranty_info )
...
2)look for searchOptions in inc/infocoms.class.php
$tab[] = [
'id' => '7',
'table' => $this->getTable(),
'field' => 'warranty_info',
'name' => __('Warranty information'),
'datatype' => 'string'
];
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
you can also search option from computer :
/listSearchOptions/Computer/
...
[52] => Array ( [name] => Informations sur la garantie
[table] => glpi_infocoms
[field] => warranty_info
[datatype] => string
[nosearch] =>
[nodisplay] =>
[available_searchtypes] => Array ( [0] => contains )
[uid] => Computer.Infocom.warranty_info )
or with GLPI Graphic interface look for warranty information and you'll get URL :
glpi/front/computer.php?is_deleted=0&criteria[0][field]=52&criteria[0][searchtype]=contains&criteria[0][value]=dummy
then for computer field id is 52
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
many thanks
$json = '{"input": { "id":71 , "comment": "test comment" , "warranty_info": "test info", "buy_date": "2015-01-01", "end_warranty": "2019-01-01", "warranty_duration": "12"}}'
should work then, but isn't
Comment is working but the other fields are not changed....
Offline
are you updating computer or infocom ? ( please give URL)
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
http://hostname/glpi/apirest.php/Computer
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Content-Type','Application/Json')
$headers.Add('Session-Token', $GLPI_Session)
$headers.Add('App-Token', $GLPI_Apikey)
$json = '{"input": { "id":71 , "comment": "test comment" }}'
$result = Invoke-WebRequest -Uri ($GLPI_ApiUrl+'/Computer') -Body $json -ContentType "application/json" -Headers $headers -Method PUT
$json = '{"input": { "id":71 , "warranty_info": "test info", "buy_date": "2015-01-01", "end_warranty": "2019-01-01", "warranty_duration": "12"}}'
$result = Invoke-WebRequest -Uri ($GLPI_ApiUrl+'/infocom') -Body $json -ContentType "application/json" -Headers $headers -Method PUT
Last edited by ernieek (2018-12-11 16:14:45)
Offline
1) you should GET /Computer/71/Infocom/
2) from response extract $InfocomID ( witch should be different from 71)
3)
$json = '{"input": { "id": $InfocomID , "warranty_info": "test info", "buy_date": "2015-01-01", "end_warranty": "2019-01-01", "warranty_duration": "12"}}'
PUT /infocom/$infocomID/
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
many many many thanks.
it's works
Offline