You are not logged in.
Pages: 1
Hi,
When I try to update an item like for example the comment or any other item for a computer, the command creates a new computer instead of updating the original one.
I'm sure of the computer ID.
Do you have any ideas?
By the way, do you know how to update the “tag” plugin field for a computer?
Here is my PowerShell command:
$json =
{
"input": [
{
"id": 16941,
"comment": "test"
}
]
}
$URLSESSION =
https://xxxxxxxxxxxxxxxxxxxxxxxxxxxx/apirest.php/Computer/16941?session_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&app_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Invoke-WebRequest -Method PATCH -Uri $URLSESSION -Body $json -ContentType 'application/json' -UseDefaultCredentials
Return:
StatusCode : 200
StatusDescription : OK
Content :
RawContent : HTTP/1.1 200 OK
Pragma: no-cache
Content-Length: 0
Cache-Control: no-store, no-cache, must-revalidate
Content-Type: text/html; charset=UTF-8
Date: Wed, 11 Sep 2024 15:11:20 GMT
Expires: Thu, 19 ...
Forms : {}
Headers : {[Pragma, no-cache], [Content-Length, 0], [Cache-Control, no-store, no-cache, must-revalidate], [Content-Type, text/html; charset=UTF-8]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : mshtml.HTMLDocumentClass
RawContentLength : 0
Thanks in advance for your time and your help !
Offline
If your computer is duplicated when you modify it, it's because you used the “POST” method and not PUT.
Personally, to edit a field after retrieving it via :
Invoke-RestMethod "$AppURL/listSearchOptions/Computer" -Method Get -Headers @{"session-token"=$SessionToken.session_token; "App-Token" = "$AppToken"} -ContentType 'application/json'
I use this command:
$ItemID = 929 # Computer ID
$Field_Name="customeridfield" # Custom Field Name
$Field_NewValue = "Nouvelle Valeur 2" # Value for that Custom Field Name
$body = @{
input = @{
id= $ItemID #Computer ID
$Field_Name = $Field_NewValue
}
} | ConvertTo-Json
Invoke-RestMethod -Uri "$($AppURL)/Computer" -Headers @{"session-token"=$SessionToken.session_token; "App-Token" = "$AppToken"} -ContentType 'application/json' -Method PUT -Body $body
Offline
Pages: 1