21.10.2020, 17:53 (This post was last modified: 21.10.2020, 18:29 by gjniewenhuijse.)
Ok, i give it a try
my code:
Code:
local usr = "my@email.com"
local pwd = "mypwd"
local uri = "https%3A%2F%2Fyour.app.url%2Fauthorize" -- there's no url redirect, so how to handle this
local state = "c7d37ee542c7'" -- random
---------------------------- change nothing after this line -------------------------------
local apiHost = "https://interop.ondilo.com"
local apiUrl = apiHost .. "/api/customer/v1"
local endpointToken = "/oauth2/token"
local endpointAuth = "/oauth2/authorize"
-- init
if not init then
require('socket.http')
require('ltn12')
require('json')
socket.http.TIMEOUT = 5
init = true
end
function getAuth()
url = apiHost..endpointAuth..'?client_id=customer_api&response_type=code&redirect_uri='..uri..'&scope=api&state='..state
method = "POST"
local response_body = { }
local payload = '{"login":"'..usr..'","password":"'..pwd..'","locale":"nl","proceed":"Authorize"}'
(22.10.2020, 06:30)admin Wrote: What do you get in response body? You should also remove Accept-Encoding header otherwise body will be compressed with gzip instead of plain text.
For this request Accept/Content-Type headers are not needed. Add redirect = false to the request table to catch the redirect URL instead of following it.
(22.10.2020, 07:14)admin Wrote: For auth you need to use standard POST, not JSON:
For this request Accept/Content-Type headers are not needed. Add redirect = false to the request table to catch the redirect URL instead of following it.
mmm same result with changed code
Code:
function getAuth()
function encodepost(t)
local res = {}
local esc = require('socket.url').escape
for k, v in pairs(t) do
res[ #res + 1 ] = esc(k) .. '=' .. esc(v)
end
return table.concat(res, '&')
end
url = apiHost..endpointAuth..'?client_id=customer_api&response_type=code&redirect_uri='..uri..'&scope=api&state='..state
method = "POST"
local response_body = {}
local payload = encodepost({
login = usr,
password = pwd,
locale = "nl",
proceed = "Authorize",
})
local res, code, response_headers, status = socket.http.request
{
url = url,
method = method,
redirect = false,
headers =
{
["Content-Length"] = #payload
},
source = ltn12.source.string(payload),
sink = ltn12.sink.table(response_body)
}
if res and code == 200 then
log(response_body)
log(res, code, response_headers, status)
else
log(res, code, response_headers, status)
end
end
22.10.2020, 16:43 (This post was last modified: 23.10.2020, 06:39 by gjniewenhuijse.)
many thanks to admin for the support.
here my first version to get the latest sensor readings for one pool/spa.
We remind that ICO takes measures every hour.
In order to avoid excessive load of our servers, the requests to the Ondilo Customer API
are limited to the following per user quotas :
5 requests per second
30 requests per hour
Access tokens have a lifetime of one hour, while refresh tokens are non-expiring.
One small improvement, you should use the whole table instead of only the first element. If the JSON response is large enough then the response table will have more than 1 element. Use this instead:
Could you give some instructions with examples how to get sensors data please
I am not familiar with scripting, but can multiply solution from example.