Open API Get Device History Data

Post Reply
gcmvanloon
Posts: 6
Joined: Wed Apr 10, 2024 5:57 pm

Hi,

I'm using the Open API to access information about the power generated by my inverter.
The documentation found on https://www.foxesscloud.com/public/i18n ... ument.html helped me on my way with most API calls.
I'm able to get the devicelist and realtime data from the API with no problems.

However, there is one method call that I can't get to return any results other than errorno 40257. The "Get device history data" call (path = /op/v0/device/history/query).
The response is always the same, whatever I do:

Code: Select all

{
    "errno": 40257,
    "msg": "Parameter does not meet expectations",
    "result": null
}
It doesn't tell me which parameter does not meet the expecations. Nor what the expectations are.

This is one of my many requests I've tried:

Code: Select all

{
  "sn": "***************",
  "variables": ["pvPower"],
  "begin": 1712354400,
  "end": 1712440800
}
(I have replaced my real serial number for security reasons)
I've tried this with different variables, with and without "begin" and "end" timestamps. Different timestamps and periods, from a few hours to a few days ect. Nothing seems to work.

I'm hoping someone can point me in the right direction here because I would really love to use the history endpoint too.
Thanks in advance!
Dave Foster
Posts: 1311
Joined: Thu Oct 13, 2022 7:21 pm

Your body data appears to be correctly formatted, I haven’t checked your timestamps but they look correct - what are you using for the ‘headers’ ?

From memory the openapi document missed the content-type parameter which should be set to 'Content-Type': 'application/json' can you paste your headers (obvs *** out your token)
gcmvanloon
Posts: 6
Joined: Wed Apr 10, 2024 5:57 pm

I'm setting all the appropriate headers:
* Token
* Timestamp
* Signature
* Lang

I've created a little postman collection to try things out.
This is my collection "Pre Request Script" that will add the headers before every request:

Code: Select all

const timestamp = Date.now();
const token = pm.environment.get("token");
const path = pm.request.url.getPath();

const signature = `${path}\\r\\n${token}\\r\\n${timestamp}`;

const md5Signature = CryptoJS.MD5(signature).toString();

pm.request.addHeader({key:'Token', value: token});
pm.request.addHeader({key:'Timestamp', value: timestamp.toString()});
pm.request.addHeader({key:'Signature', value: md5Signature});
pm.request.addHeader({key:'Lang', value: 'en'})

Code: Select all

Token: ********-****-****-****-************
Timestamp: 1712772801292
Signature: ae6f1565b05de7df57f3584f63037c3b
Lang: en
Content-Type: application/json
Remember: all the other request e.g. the real time data do work as expected.
Dave Foster
Posts: 1311
Joined: Thu Oct 13, 2022 7:21 pm

Actually just double checking the timestamps.

Your signature timestamp is correct (milli seconds), but the begin:, end: timestamps are not they should be much bigger

(I think your missing a * 1000 multiplier to get to milliseconds)

for example -

"begin:": 1708308000000,
"end": 1708380000000,

Not as you have it -

"begin": 1712354400,
"end": 1712440800
gcmvanloon
Posts: 6
Joined: Wed Apr 10, 2024 5:57 pm

Appreciate the quick responses here.
Thanks a lot Dave.

You have a sharp eye. The timestamps where indeed too short!.

I've tried the following request:

Code: Select all

{
    "sn":"***************",
    "variables":["pvPower"],
    "begin":1712534400000,
    "end":1712620800000}
}
begin = 2024-04-08
end = 2024-04-09

And I still get the same response with the errorno.

Looking at the documentation the "begin" and "end" properties are optional. Even when I leave them out of the request body. The response is still the same.
gcmvanloon
Posts: 6
Joined: Wed Apr 10, 2024 5:57 pm

I finally figured it out! It's something realy stupid, as it usually is...

All this time I assumed I posted my requests to "/op/v0/device/history/query" when in fact I was posting to "/op/v0/device/report/query".

My best guess is that I messed up using postman, copying one request to create another and forgetting to adjust the url.
Schermafbeelding 2024-04-10 212956.png
Got it working now. Thanks for the help!

Best regards
Dave Foster
Posts: 1311
Joined: Thu Oct 13, 2022 7:21 pm

Nicely spotted, glad you got it sorted :)
Post Reply