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

Re: API with Powershell

Posted: Fri Mar 13, 2026 10:23 pm
by tony.matthews1
Still not right by the look of it. \\ not \

Re: API with Powershell

Posted: Sat Mar 14, 2026 12:42 am
by advertisingfree
$dataToSign = "$path\\r\\n$token\\r\\n$timestamp"
/op/v1/device/real/query\\r\\n4364a14f-6b84-4b8b-aee8-7002970fd5b2\\r\\n1773448842692

Same error.

Re: API with Powershell

Posted: Sat Mar 14, 2026 5:25 pm
by tony.matthews1
Here's an example of a signature that I just tested and works for your data:

getting real-time data
body = {"sns": ["60KB10305BLB028"]}
path = /op/v1/device/real/query
headers = {'Token': '4364a14f-6b84-4b8b-aee8-7002970fd5b2', 'Lang': 'en', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', 'Timezone': 'Australia/Sydney', 'Timestamp': '1773509198752', 'Content-Type': 'application/json', 'Signature': '73d98dfa6f4a80d075078eadc9e9ae17'}

Copy the parameters from this and check you are generating the correct signature.

Once this is working, you may want to generate a new API key as anyone could copy and use the key you published here.

Re: API with Powershell

Posted: Sun Mar 15, 2026 4:09 am
by advertisingfree
Using your timestamp, I can generate the same signature but the error for the script is the same.

Re: API with Powershell

Posted: Sun Mar 15, 2026 6:20 am
by tony.matthews1
Check and compare the header info, encoding etc in my comment and make sure this also matches if you are generating the correct signature encoding.

This is from a tested working call to the API.