Hello everyone
I'm trying to integrate ttlock locks, but I get a little lost with the POST, GET issue
I found a similar script from Husqvarna that I tried to adapt, but I get the nil message.
https://forum.logicmachine.net/showthread.php?tid=4824
Has anyone managed to integrate ttlock locks?
Thank you very much in advance.
I'm trying to integrate ttlock locks, but I get a little lost with the POST, GET issue
I found a similar script from Husqvarna that I tried to adapt, but I get the nil message.
https://forum.logicmachine.net/showthread.php?tid=4824
Code:
http = require('socket.http')
ltn12 = require('ltn12')
local authEndpoint = 'https://euapi.ttlock.com/oauth2/token'
local clientId = 'd4e938ac8bedxxxxxxxxxxx'
local clientSecret = 'f646xxxxxxxxxxxxxxxxxxxc19'
local username = 'xxxxxx'
local password = 'xxxxxx'
local AccessToken
function getAccessToken()
local requestBody = 'grant_type=client_credentials'
.. '&client_id=' .. clientId
.. '&client_secret=' .. clientSecret
.. '&username=' .. username
.. '&password=' .. password
local response_body = {}
local _, code, _, _ = https.request{
url = authEndpoint,
method = 'POST',
headers = {
['Content-Type'] = 'application/x-www-form-urlencoded',
['Content-Length'] = #requestBody
},
source = ltn12.source.string(requestBody),
sink = ltn12.sink.table(response_body)
}
end
log(response_body, code, AccessToken, source, sink))
Has anyone managed to integrate ttlock locks?
Thank you very much in advance.