security API documentation, please fix

The Netatmo API is a set of webservices allowing developers and third parties to access Netatmo device's data.
jcovett
Posts: 4
Joined: 25 Dec 2019, 18:56

security API documentation, please fix

Post by jcovett »

Dear Netatmo

I have two Netatmo Presence and am implementing their API. It works, but their documentation is broken at https://dev.netatmo.com/apidocumentatio ... y#setstate
This page will not load the parameters for the setstate endpoint; and the Try-it-out functionality does not work; I tried multiple browsers.
If anyone can tell me the details of how to turn monitoring on I'd be grateful.
I have sent a support request about this more than a week ago, but the documentation isn't fixed yet. Netatmo, please correct the documentation so I can fully use your product.
Céline
Posts: 58
Joined: 20 Nov 2017, 18:17

Re: security API documentation, please fix

Post by Céline »

Hi jcovett,

We have a small problem with the documentation of this particular endpoint. We'll remove it while we fix it properly.

To help you in the meantime, here are some info on the request.

The SetState enpoint allows to:
• Set outdoor camera floodlight mode to Auto/On.
• Set indoor and outdoor camera monitoring to On/Off.

To use it, you will need write scopes, either write_camera or write_presence

The endpoint is : https://api.netatmo.com/api/setstate

This method expects parameters to be passed as a JSON string in the POST request body contrary to the other methods. That means that all the info should in the body.

You can control the outdoor camera floodlight from ON to AUTO and the monitoring from ON to OFF.

If the security code option in Netatmo Security app is enabled, a security code will be requested to suspend the monitoring (use pincode field). The boolean use_pin_code returned by the gethomedata call can be used to know if a pincode is required to turn On a given camera.

Request example:

Code: Select all

{
    "home": {
        "id": "xxxxxxxxxxxxx",
        "modules": [
            {
                "id": "70:xx:xx:xx:xx:xx",
                "floodlight": "auto"
            }
        ]
    }
}
BR,
Céline
Céline - Netatmo Team :D
jcovett
Posts: 4
Joined: 25 Dec 2019, 18:56

Re: security API documentation, please fix

Post by jcovett »

Céline thanks for your reply. However, I'm not there yet:

Are you sure about the 'write_presence' scope? This page (https://dev.netatmo.com/apidocumentation/oauth) does not mention it, but it does mention access_presence (I used 'read_presence access_presence write_presence' and did get a token, so it seems okay...)
And I assume the key value pair for monitoring is "monitoring": "on/off", am I right?

But the more difficult problem for me is when I try to POST your request example, obviously with my own id's, it returns error code 10 'missing home id'. In fact I tried a URL parameter ?home_id=5c4b744ab0xxxxxx together with that post and it return error code 11 '"Cannot read property 'modules' of undefined".

I know that my id's are correct since other api-call succeed, and I'm not using the pin code option. Can I ask you to double check the example code in your own environment and let me know if I'm doing anything wrong? (I could send you a Postman snippet but not via this public forum).

Thanks!
Céline
Posts: 58
Joined: 20 Nov 2017, 18:17

Re: security API documentation, please fix

Post by Céline »

Hi jcovett,

You should not use a url parameter to send the home_id, it won't work. You need to put everything directly in the body of the request.
Check out the JSON in my last answer and replace "id": "xxxxxxxxxxxxx", with the right id of the home and it should be working.

Cheers,
Céline - Netatmo Team :D
jcovett
Posts: 4
Joined: 25 Dec 2019, 18:56

Re: security API documentation, please fix

Post by jcovett »

Céline sorry I wasn't so clear but I *did* what you suggested first. When I got the error 10: missing home_id, I tried the URL parameter, just because, well, sometimes one might get lucky.
To be clear now, using my valid home and camera id and a valid access token, it does not work... :(

Included a Postman screenshot of request and response. I used your supplied code and tried this about 15 minutes before making this forum post, so kindly check your server logs to see if you can find the cause.
I have written great python program for automating my home security using my 3 Netatmo cams, but having to turn them on manually makes it much less useful.
Attachments
error 10.jpg
error 10.jpg (89.17 KiB) Viewed 3736 times
Céline
Posts: 58
Joined: 20 Nov 2017, 18:17

Re: security API documentation, please fix

Post by Céline »

Hi,

Just tried my postman also, here is the cURL generated by Postman. Try comparing it with yours to find issues.
Access_token should be in the Header along with Content-Type application/json

Code: Select all

curl -X POST \
  https://api.netatmo.com/api/setstate \
  -H 'Authorization: Bearer 59xxxxxxxxxxxxxxxxxxxxxxxxxxxbae' \
  -H 'Content-Type: application/json' \
  -H 'Postman-Token: e00000be-c578-4c76-a990-6c9999999994' \
  -H 'cache-control: no-cache' \
  -d '{
    "home": {
        "id": "5xxxxxxxxxxxxx",
        "modules": [
            {
                "id": "70:ee:xx:xx:xx:xx",
                "floodlight": "auto"
            }
        ]
    }
}'
Céline - Netatmo Team :D
jcovett
Posts: 4
Joined: 25 Dec 2019, 18:56

Re: security API documentation, please fix

Post by jcovett »

Success at last! The provided CURL command worked, so all the info was now available to me and after some more fiddling I was able to use Postman as well.
I will now finish my python home alarm script and probably purchase a third Presence as well, one of these days.
Thank you for your help.
Céline
Posts: 58
Joined: 20 Nov 2017, 18:17

Re: security API documentation, please fix

Post by Céline »

Glad I could help !
Céline - Netatmo Team :D
humpty83
Posts: 8
Joined: 10 May 2017, 21:13

Re: security API documentation, please fix

Post by humpty83 »

Hi,

sorry for hijacking this thread but it fits the topic.

I tried what has been described above but I only get

Code: Select all

{
  "error": {
    "code": 21,
    "message": "Invalid device_id, 70:xx:xx:xx:xx:12"
  }
}
when calling

Code: Select all

POST https://api.netatmo.com/api/setstate HTTP/1.1
Content-Type: application/json
Authorization: Bearer 12345678abc45678|09876bca76543

{
    "home": {
        "id": "132435465768798abcd",
        "modules": [
            {
                "id": "70:xx:xx:xx:xx:12",
                "monitoring": "on"
            }
        ]
    }
}
What am I doing wrong? The values come from

Code: Select all

https://api.netatmo.com/api/gethomedata
.
Leslie
Posts: 111
Joined: 12 Feb 2020, 11:07

Re: security API documentation, please fix

Post by Leslie »

Hello,

Maybe you have an issue in your header's request
This following HTTP request works for me :

Code: Select all

POST /api/setstate HTTP/1.1
Host: api.netatmo.com
Content-Type: application/json
Authorization: Bearer 5e37f3eaa77487000c40267c|201f1ac326ec43742edbeXXXXXXXXX

{
    "home": {
        "id": "5e285d8f400903XXXXXXXX",
        "modules": [
            {
                "id": "70:ee:50:2e:XX:XX",
                "monitoring": "off"
            }
        ]
    }
}
Another hypothesis (but I think you checked it) : a bad copy/paste of the camera ID or a disconnected camera

Hoping it will resolve your issue
Have a good day,
Leslie - Community Manager
Post Reply

Return to “Netatmo API”