API with Powershell
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
\\r\\n in the signature is a literal. Its not CR LF.
H1-6.0-E hybrid inverter
6 x HV2600 v2 batteries
16 x JA Solar 405w panels
7 x Tigo TS4-A-O optimisers
Post Reply