07.08.2022, 15:19
Hi.
I ran this in Postman where I got the accessToken with success.
But in my script I don´t get the response of the connected devices, in fact I dopnt get much at all in response, what is wrong here?
Ebecos API documentation here
https://www.ebeco.se/radgivning/guider/ebeco-oppet-api
I ran this in Postman where I got the accessToken with success.
Code:
curl --location --request POST 'https://ebecoconnect.com/api/TokenAuth/Authenticate' \
--header 'Content-Type: application/json' \
--header 'Abp.TenantId: 1' \
--data-raw ' {
"userNameOrEmailAddress": "xxxxx@xxxxx.com",
"password": "xxxxx"
}'
But in my script I don´t get the response of the connected devices, in fact I dopnt get much at all in response, what is wrong here?
Code:
-- Load modules
require('json')
require('ssl.https')
require('ltn12')
-- Set credentials for Ebecoconnect API
userNameOrEmailAddress = "xxxxx@xxxxx.com" -- your email for Ebecoconnect account
password = "xxxxx" -- your password for Ebecoconnect account
function GetToken()
request_token_url = 'https://ebecoconnect.com/api/TokenAuth/Authenticate'
local response_body = {}
local request_body = "grant_type=password&username=" .. userNameOrEmailAddress .. "&password=" .. password
local body, code, hdrs, stat = ssl.https.request{
url = request_token_url;
method = "POST";
headers =
{
["Content-Type"] = "application/x-www-form-urlencoded";
["Content-Length"] = #request_body;
["Abp.TenantId"] = 1;
};
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)
log(ret)
return ret.access_token -- could be some other field, try to log ret to be sure
end
end
-- Request token
if not API_Token then
API_Token = GetToken()
end
function RequestFromEbeco(request)
request_url = 'https://api/services/app/Devices/GetUserDevices' .. request
local response_body = {}
local request_body = ""
local body, code, hdrs, stat = ssl.https.request{
url = request_url;
method = "GET";
headers =
{
["Content-Type"] = "application/json";
["Authorization"] = "Bearer " .. API_Token;
};
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
-- Get products
products = RequestFromEbeco('products')
log(products) -- Checks your Ebeco thermostats
Ebecos API documentation here
https://www.ebeco.se/radgivning/guider/ebeco-oppet-api