Here’s the whole script in case anything jumps out at you.
<# Use TLS 1.2 #>
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
<# account info #>
$accessId = 'xxxx'
$accessKey = 'xxxx'
$company = 'xxxx'
<# request details #>
$httpVerb = 'POST'
$resourcePath = '/website/websites'
$data = '{ "type": "webcheck", "domain": "google.com", "name": "Test from Powershell", "useDefaultLocationSetting": true, "useDefaultAlertSetting": true, "schema": "https", "disableAlerting": true, "groupId": "332","testLocation": { "smgIds": [ 2, 4, 3 ], "collectorIds": [], "all": false, "collectors": [] }, "steps": [ { "type": "config", "name": "__step0", "description": "", "enable": true, "label": "", "HTTPHeaders": "", "followRedirection": true, "HTTPBody": "", "HTTPMethod": "GET", "postDataEditType": null, "fullpageLoad": true, "requireAuth": false, "auth": null, "timeout": 30, "HTTPVersion": "1.1", "schema": "http", "url": "", "matchType": "plain", "keyword": "", "path": "", "invertMatch": false, "statusCode": "", "reqScript": "", "reqType": "config", "respType": "config", "respScript": "", "useDefaultRoot": true }] }'
<# Construct URL #>
$url = 'https://' + $company + '.logicmonitor.com/santaba/rest' + $resourcePath
<# Get current time in milliseconds #>
$epoch = [Math]::Round((New-TimeSpan -start (Get-Date -Date "1/1/1970") -end (Get-Date).ToUniversalTime()).TotalMilliseconds)
<# Concatenate Request Details #>
$requestVars = $httpVerb + $epoch + $data + $resourcePath
<# Construct Signature #>
$hmac = New-Object System.Security.Cryptography.HMACSHA256
$hmac.Key = [Text.Encoding]::UTF8.GetBytes($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()))
<# Construct Headers #>
$auth = 'LMv1 ' + $accessId + ':' + $signature + ':' + $epoch
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization",$auth)
$headers.Add("Content-Type",'application/json')
<# Make Request #>
$response = Invoke-RestMethod -Uri $url -Method $httpVerb -Body $data -Header $headers
<# Print status and body of response #>
$status = $response.status
$body = $response.data| ConvertTo-Json -Depth 5
Write-Host "Status:$status"
#Write-Host "Response:$body"