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
Re: API with Powershell
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
Still not right by the look of it. \\ not \
H1-6.0-E hybrid inverter
6 x HV2600 v2 batteries
16 x JA Solar 405w panels
7 x Tigo TS4-A-O optimisers
Re: API with Powershell
$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
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.
H1-6.0-E hybrid inverter
6 x HV2600 v2 batteries
16 x JA Solar 405w panels
7 x Tigo TS4-A-O optimisers
Re: API with Powershell
Using your timestamp, I can generate the same signature but the error for the script is the same.
Re: API with Powershell
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.
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