How can we help?

Cannot set zone to inactive via API



  • Avatar
    RainMachine Nicholas

    Seems to work fine on my side: 

    curl -k -X POST -d '{"active": false}'

    curl -k -X GET
    {"uid": 2, "name": "Front Left", "valveid": 2, "ETcoef": 0.7, "active": false, "type": 2, "internet": true, "savings": 130, "slope": 99, "sun": 1, "soil": 99, "group_id": 99, "history": true, "master": false, "before": 0, "after": 0, "waterSense": {"fieldCapacity": 0.24, "rootDepth": 203, "minRuntime": 20, "appEfficiency": 0.7, "isTallPlant": false, "permWilting": 0.03, "allowedSurfaceAcc": 6.6, "maxAllowedDepletion": 0.4, "precipitationRate": 35.56, "currentFieldCapacity": 17.05, "area": 92.9, "referenceTime": 661, "detailedMonthsKc": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "flowrate": -1, "soilIntakeRate": 5.08}, "customSoilPreset": null, "customVegetationPreset": null, "customSprinklerPreset": null}
  • Avatar
    Shrinks (Edited )

    Okay, I sorted it out...  I am not sure if this is a user error on my part or a problem with the API, but I can code around it.

    This works (as your example shows):

    curl -k -X POST -d '{"active": false}'

    This does not work:

    curl -k -X POST -d '{"active": "false"}'

    The difference being that the word false is quoted.  I was using perl and the encode_json routine from the JSON CPAN library.  encode_json seems to quote strings (which seems reasonable).  I can change it from 'false' to the integer 0 and it stops quoting and works.  I'm not sure if the API has a max length of 5 here or what.  It seems like it should either fail or work.  The result I was getting was that it did not work, but returned "success".  I could even put multiple parameters in there like {"name":"New Name", "active":"false"}.  This would apply the new name and leave the zone active.


  • Avatar
    RainMachine Nicholas

    Yes, it's normal the "false" between quotes is actually evaluated to true inside the API. 

  • Avatar

    Thanks, that's good to know, though it sounds like sort of bizarre behavior to treat false and "false" differently.

    Incidentally, your perl examples in the apiary won't work with this model.

    use Cpanel::JSON::XS qw(encode_json decode_json);
    my $json = encode_json {active=>false};
    print "$json\n";

    This outputs:


    The only way I can make this work is with:

    my $json = encode_json {active=>0};

  • Avatar
    RainMachine Nicholas

    Yes that's correct, 0/1 will work as perl doesn't have true/false bools. If you really want to send true/false you need to use JSON::true or JSON::false on encode_json.

Please sign in to leave a comment.