Hi,
I’m working on a binding for the Tesla Powerwall that uses the Tesla Cloud API.
I’m struggling the build the JSON to send a command in the right format.
A curl command like:
curl -H 'Authorization: Bearer token' --location --request POST 'https://owner-api.teslamotors.com/api/1/energy_sites/140608504xxx/backup' -H "Content-Type: application/json" -d '{"backup_reserve_percent":'10'}'
will work to set the backup_reserve_percent to 10%
My current code is:
String payload = "{\"backup_reserve_percent\":'" + newreserve + "'}";
logger.debug("payload = {}", payload);
ByteArrayInputStream input = new ByteArrayInputStream(payload.getBytes());
String response = invoke("POST", "https://owner-api.teslamotors.com/api/1/energy_sites/" + siteID + "/backup",
accessToken, input, "application/json");
logger.debug("response to reserve change = {}", response);
and the output I get is:
2022-02-04 19:12:07.520 [DEBUG] [rnal.TeslaPowerwallControlWebTargets] - payload = {"backup_reserve_percent":'12'}
2022-02-04 19:12:07.521 [DEBUG] [rnal.TeslaPowerwallControlWebTargets] - Calling url: https://owner-api.teslamotors.com/api/1/energy_sites/140608504302/backup
2022-02-04 19:12:07.707 [DEBUG] [rnal.TeslaPowerwallControlWebTargets] - response to reserve change = {"error":"invalid JSON: unexpected character (after backup_reserve_percent) at line 1, column 27 [parse.c:769] in '{\"backup_reserve_percent\":'12'}"}
Note the \ characters that are making it thru to Tesla’s server, and the extra "}
Any ideas?