2 years ago
API Patch for CustomProperties
Hi Guys
I'm trying to write in customproperties to a device as follows:
I can correctly patch the displayname, but the customproperties hastable is not being written. I get a success 200 response back from my invoke-restmethod however.
Ive tried with the customproperties hash table seperate to displayname but i cant get this working.
Does anyone have any ideas on this?
NOTE: xxx is the correct ID
Thanks
$company = 'xxx'
$accessId = 'xxx'
$accessKey = 'xxx
$computername = "$env:COMPUTERNAME"
$httpVerb_04 = 'PATCH'
$resourcePath_04 = "/device/devices/xxx"
$patchfields = '?patchFields=displayName,customproperties&opType=add'
$body = @{
'displayName' = "$computername"
customproperties = @{
name='srv.location'
value='test'
}
}
$body = $body | convertto-json
<# Construct URL #>
$url_04 = 'https://' + $company + '.logicmonitor.com/santaba/rest' + $resourcePath_04 + $patchfields
<# Get current time in milliseconds #>
$epoch_04 = [Math]::Round((New-TimeSpan -start (Get-Date -Date "1/1/1970") -end (Get-Date).ToUniversalTime()).TotalMilliseconds)
<# Concatenate Request Details #>
$requestVars_04 = $httpVerb_04 + $epoch_04 + $body + $resourcePath_04
<# Construct Signature #>
$hmac_04 = New-Object System.Security.Cryptography.HMACSHA256
$hmac_04.Key = [Text.Encoding]::UTF8.GetBytes($accessKey)
$signatureBytes_04 = $hmac_04.ComputeHash([Text.Encoding]::UTF8.GetBytes($requestVars_04))
$signatureHex_04 = [System.BitConverter]::ToString($signatureBytes_04) -replace '-'
$signature_04 = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($signatureHex_04.ToLower()))
<# Construct Headers #>
$auth_04 = 'LMv1 ' + $accessId + ':' + $signature_04 + ':' + $epoch_04
$headers_04 = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers_04.Add("Authorization",$auth_04)
$headers_04.Add("Content-Type",'application/json')
<# Make Request #>
$response_04 = Invoke-RestMethod -Uri $url_04 -Method patch -body $body -Header $headers_04