(01.11.2022, 07:19)admin Wrote: Request is missing Content-Length header:
Code:1["Content-Length"] = #request_body,
Still 400:
Code:
123456789101112131415161718192021222324252627282930313233343536
function WriteToEasee(request, request_body)
request_url = 'https://api.easee.cloud/api/' .. request
local response_body = {}
local content_length
if type(request_body) == "string" then
content_length = #request_body
else
request_body = ""
end
local body, code, hdrs, stat = ssl.https.request{
url = request_url;
method = "POST";
headers =
{
["Content-Type"] = "application/json";
["Authorization"] = "Bearer " .. API_Token;
["Content-Length"] = #request_body,
};
source = ltn12.source.string(request_body);
sink = ltn12.sink.table(response_body);
}
log(code)
if code == 200 then
ret = table.concat(response_body)
ret = json.pdecode(ret)
return ret
else
--API_Token = GetToken() -- request a new token
end
end
dynCurr = 10
-- Dynamic current setting.
WriteToEasee('chargers/' .. ChargerID .. '/settings', "dynamicChargerCurrent" .. dynCurr)(01.11.2022, 07:23)tomnord Wrote:(01.11.2022, 07:19)admin Wrote: Request is missing Content-Length header:
Code:1["Content-Length"] = #request_body,
Still 400:
Code:123456789101112131415161718192021222324252627282930313233343536function WriteToEasee(request, request_body) request_url = 'https://api.easee.cloud/api/' .. request local response_body = {} local content_length if type(request_body) == "string" then content_length = #request_body else request_body = "" end local body, code, hdrs, stat = ssl.https.request{ url = request_url; method = "POST"; headers = { ["Content-Type"] = "application/json"; ["Authorization"] = "Bearer " .. API_Token; ["Content-Length"] = #request_body, }; source = ltn12.source.string(request_body); sink = ltn12.sink.table(response_body); } log(code) if code == 200 then ret = table.concat(response_body) ret = json.pdecode(ret) return ret else --API_Token = GetToken() -- request a new token end end dynCurr = 10 -- Dynamic current setting. WriteToEasee('chargers/' .. ChargerID .. '/settings', "dynamicChargerCurrent" .. dynCurr)
Could it be a mismatch with this?
WriteToEasee('chargers/' .. ChargerID .. '/settings', "dynamicChargerCurrent" .. dynCurr)
In the docs it says this: "{\"dynamicChargerCurrent\":16}"