Cannot set zone to inactive via API
I cannot for the life of me figure this out. I have been playing with the API modifying zone parameters. I can pretty much change what I want to change.... EXCEPT.... I cannot seem to change the "active" parameter to 'false'. When I try, I get { "statusCode": 0, "message": "OK" }, but the zone remains active.
The reverse works fine. I can change an inactive zone to active. I just cannot change an active zone to inactive.
Am I missing something? Or is this a known bug?
-
Seems to work fine on my side:
curl -k -X POST https://192.168.12.174:8080/api/4/zone/2/properties?access_token=a225d56fff8afc44d6a87c4934ec96cde86bbee23f173b81491bdddb -d '{"active": false}'
curl -k -X GET https://192.168.12.174:8080/api/4/zone/2/properties?access_token=a225d56fff8afc44d6a87c4934ec96cde86bbee23f173b81491bdddb{"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} -
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 https://192.168.43.149:8080/api/4/zone/16/properties?access_token=4a00ab4edf27dbf269bae0fbdd61a6f2ee72b8f32b434ac57ddcc2ef -d '{"active": false}'
This does not work:
curl -k -X POST https://192.168.43.149:8080/api/4/zone/16/properties?access_token=4a00ab4edf27dbf269bae0fbdd61a6f2ee72b8f32b434ac57ddcc2ef -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.
-
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.
#!/usr/bin/perl
use Cpanel::JSON::XS qw(encode_json decode_json);
my $json = encode_json {active=>false};
print "$json\n";This outputs:
{"active":"false"}
The only way I can make this work is with:
my $json = encode_json {active=>0};
Please sign in to leave a comment.
Comments
5 comments