12.08.2019, 07:39
Change token and data query as needed:
Code:
https = require('ssl.https')
json = require('json')
ltn12 = require('ltn12')
token = 'd1007ead2dc84a2b82f0de19451c5fb22112f7ae11d19bf2bedb224a003ff74a'
data = json.encode({
query = '{viewer {homes {currentSubscription {priceInfo {current {total energy tax startsAt }}}}}}'
})
tbl = {}
res, code = https.request({
url = 'https://api.tibber.com/v1-beta/gql',
method = 'POST',
headers = {
['authorization'] = 'Bearer ' .. token,
['content-type'] = 'application/json',
['content-length'] = #data,
},
source = ltn12.source.string(data),
sink = ltn12.sink.table(tbl),
})
if res and code == 200 then
resp = table.concat(tbl)
resp = json.pdecode(resp)
log(resp)
else
log(res, code)
end