09.06.2023, 07:54
I'm trying to send energy data through an API by using http.request:
log(res,code,headers, status) returns:
* arg: 1 * nil * arg: 2 * string: Try again * arg: 3 * nil * arg: 4 * nil
response_body is empty.
Headers are as specified by the API-provider.
Any ideas what might be wrong? Hiow should I understand the "Try again" from log(code)?
Code:
local dateTime=os.date("%Y-%m-%dT%H:%M")
local http = require("socket.http")
local ltn12 = require("ltn12")
local data = grp.getvalue('360_001_OE001 - Heat energy E1')
body = [[{
"meterID": "0501e479-2a12-45b4-8cb6-505ced85428f",
"values": ["]]..dateTime..[[,]]..data..[[]
}]]
local response_body = {}
res, code, headers, status = http.request{
url = "https://www.energinet.net/apiImport/data",
method = "POST",
headers ={
["Authorization"] = "Bearer xxxxx",
["Content-Type"] = "application/json",
["Accept"] = "application/json"
},
source = ltn12.source.string(body),
sink = ltn12.sink.table(response_body)
}
log(response_body)
log(body)
log(res,code,headers,status)
log(res,code,headers, status) returns:
* arg: 1 * nil * arg: 2 * string: Try again * arg: 3 * nil * arg: 4 * nil
response_body is empty.
Headers are as specified by the API-provider.
Any ideas what might be wrong? Hiow should I understand the "Try again" from log(code)?