10.01.2020, 09:21
Try this:
Code:
function WriteToTesla(request, request_body)
request_url = 'https://owner-api.teslamotors.com/api/1/' .. 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"] = content_length;
};
source = ltn12.source.string(request_body);
sink = ltn12.sink.table(response_body);
}
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
result = WriteToTesla('vehicles/' .. CarID .. '/command/actuate_trunk', '{"which_trunk":"rear"}')