3 years ago
PATCH website custom property via API
Anyone have some PowerShell that will update the custom properties of a Website (ping check)?
I have been fiddling around and the following code will update properties like name or host (for example), but will not add a custom property. The code runs without error and returns the website as expected, but the change is not reflected in the portal.
[string]$AccessId = '' [securestring]$AccessKey = ('' | ConvertTo-SecureString -AsPlainText -Force) [string]$AccountName = '' [int]$Id = '' #website id [hashtable]$PropertyTable = @{ 'propertyName' = 'test' } [string]$httpVerb = 'PATCH' [string]$resourcePath = "/website/websites" $AllProtocols = [System.Net.SecurityProtocolType]'Tls11,Tls12' [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols $resourcePath += "/$Id" $data = $PropertyTable | ConvertTo-Json -Depth 6 $enc = [System.Text.Encoding]::UTF8 $encdata = $enc.GetBytes($data) $url = "https://$AccountName.logicmonitor.com/santaba/rest$resourcePath" $epoch = [Math]::Round((New-TimeSpan -start (Get-Date -Date "1/1/1970") -end (Get-Date).ToUniversalTime()).TotalMilliseconds) $requestVars = $httpVerb + $epoch + $data + $resourcePath $hmac = New-Object System.Security.Cryptography.HMACSHA256 $hmac.Key = [Text.Encoding]::UTF8.GetBytes([System.Runtime.InteropServices.Marshal]::PtrToStringAuto(([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($AccessKey)))) $signatureBytes = $hmac.ComputeHash([Text.Encoding]::UTF8.GetBytes($requestVars)) $signatureHex = [System.BitConverter]::ToString($signatureBytes) -replace '-' $signature = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($signatureHex.ToLower())) $headers = @{ "Authorization" = "LMv1 $accessId`:$signature`:$epoch" "Content-Type" = "application/json" "X-Version" = 3 } $response = Invoke-RestMethod -Uri $url -Method $httpVerb -Header $headers -Body $encdata -ErrorAction Stop $response