Page 1 of 1

API with Powershell

Posted: Fri Mar 13, 2026 11:59 am
by advertisingfree
Could someone help me out?

Code: Select all

$deviceSN = "60KBxxxxxxx"
$token = "xxxxx-6b84-4b8b-xxxx-xxxxxxxx"
$timestamp = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()
$path = "/op/v1/device/real/query"
$dataToSign = "$path`r`n$token`r`n$timestamp"
$signature = [BitConverter]::ToString([System.Security.Cryptography.MD5]::Create().ComputeHash([System.Text.Encoding]::UTF8.GetBytes($dataToSign))).Replace("-", "").ToLower()
$headers = @{
    'Token' = $token
    'Lang' = 'en'
    'Timezone' = 'Australia/Sydney'
    'Timestamp' = $timestamp
    'Content-Type' = 'application/json'
    'Signature' = $signature
}
$body = @{
    deviceSN = $deviceSN
} | ConvertTo-Json -Compress
try {
    $response = Invoke-RestMethod -Uri "https://www.foxesscloud.com/op/v0/device/real/query" -Method Post -Headers $headers -Body $body -ContentType "application/json"
    Write-Output "$($response | ConvertTo-Json)"
} catch {
    Write-Output "$($_.Exception.Message)"
    
    if ($_.Exception.Response) {
        $responseStream = $_.Exception.Response.GetResponseStream()
        $reader = New-Object System.IO.StreamReader($responseStream)
        $responseText = $reader.ReadToEnd()
        Write-Output "$responseText"
    } else {
        Write-Output ""
    }
} 
and this is what I receive,

{
"errno": 40256,
"msg": "Please close and reopen this page illegal signature"
}

Any idea? Thanks

Re: API with Powershell

Posted: Fri Mar 13, 2026 5:55 pm
by tony.matthews1
\\r\\n in the signature is a literal. Its not CR LF.

Re: API with Powershell

Posted: Fri Mar 13, 2026 8:24 pm
by advertisingfree
I have updated to

$dataToSign = "$path\r\n$token\r\n$timestamp"

and result of the variable is

/op/v1/device/real/query\r\n4364a14f-6b84-4b8b-aee8-7002970fd5b2\r\n1773432718686

but the script still returns the same error