API / setstate / Missing home_id

mailpublic35

Hi Leslie,
Sorry to disturb again, hope it is the last one.

I tried to use the setstate function in differents manners but the result is always the same :-(
["error"]=>
 array(2) {
   ["code"]=>
   int(10)
   ["message"]=>
   string(15) "Missing home_id"
 }

I also tried using your way as: 
curl_setopt($handle, CURLOPT_POSTFIELDS,json_encode(array(
       'home' => array(
                       'id' =>  '5xxxxxxxxxxxxxxxxxxc',
                       'modules' => array (
                                           'id' => '70:xxxxxxxx:34',
                                           'floodlight' => 'on'
                                          ),
                     ),
             ) ));
however the result is identical. 
Yes, I use the POST schema.

Yes, I also tried using the display here: https://dev.netatmo.com/apidocumentation/security#setstate
and with the right parameters as it is not possible to fill with home_id and modules id using the website.
 
curl -X POST "https://api.netatmo.com/api/setstate" -H "accept: application/json" -H "Authorization: Bearer 5xxxxxxxxxxxxxxx3|axxxxxxxxxxxxxxxd" -
H  "Content-Type: application/json" -d "{\"home\":{\"id\":\"5xxxxxxxxxxxxxxxxc\",\"modules\":[{\"id\":\"70:xxxxxxxxxxxx:34\",\"floodlight\":\"auto\"}]}}"
Of course it works :-( 

What I am doing wrong?

Thank you for your patience
Best regards
Phil

0

Comments

4 comments

  • Comment author
    Leslie Community moderator

    Hi again Phil,

    First, you can change values in the Try-it tool of https://dev.netatmo.com/apidocumentation/security#setstate request (it's not evident as there is no visible underline of values, but you can try) 

    Here is a working code on my side, I invite you to test and check what happens (for me it's once more an encoding issue) : 

    <?php

    $curl = curl_init();

    curl_setopt_array($curl, array(
    CURLOPT_URL => 'https://api.netatmo.com/api/setstate',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS =>'{
      "home": {
          "id": "5c6axxxxxxxxxx",
          "modules": [
              {
                  "id": "70:ee:xxxxxxx",
                  "floodlight": "on"
              }
          ]
      }
    }
    ',
    CURLOPT_HTTPHEADER => array(
      'Content-Type: application/json',
      'Authorization: Bearer 5e37fxxxxxx'
    ),
    ));
    $response = curl_exec($curl);
    curl_close($curl);
    echo $response;
    0
  • Comment author
    mailpublic35

    Hi Leslie,

    Thank you!
    I will try-out and test on wednesday

    Phil

    0
  • Comment author
    mailpublic35

    Hello Leslie,

    Thanks for sharing the code.
    I didn't success with " Try-it tool of https://dev.netatmo.com/apidocumentation/security#setstate request (it's not evident as there is no visible underline of values, but you can try) ". Theses webpages need a refresh from my point of view :-)

    I found why the message "Missing home_id" is there. So the code I shared on github (user Phil353556) is working.
    The reason is tiny just a new line caracter. Let me explain:
    I wrote a script that manage tokens, initialy with the "code"  and then to refresh the tokens. It means that access_token and refresh_token are store in a file.
    When the refresh token is re read from the file a caracter nl or new line is there at the end of the string.
    This is this caracter that make the message "Missing home_id" happens.
    If needed I can share a small script for the dev. tell me.
    Once the nl caracter is removed, everything works as expected.
    May be another solution is to remove the new line caracter before writing in the file, however the nl caracter must be removed before writing or after reading.
    Thanks for your help , patience and time
    Phli


    0
  • Comment author
    Leslie Community moderator

    Hi Phil,

    "Theses webpages need a refresh from my point of view :-)" <= Oooh we agree :D

    Your code will be useful for sure for many users, thanks for it !

    Have a good day,

    Leslie - Community Manager 

    0

Please sign in to leave a comment.