This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

http post request issues
#1
I'm trying to send energy data through an API by using http.request:

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)?
Reply


Messages In This Thread
http post request issues - by stork - 09.06.2023, 07:54
RE: http post request issues - by admin - 09.06.2023, 08:06
RE: http post request issues - by stork - 09.06.2023, 08:17
RE: http post request issues - by stork - 09.06.2023, 10:53

Forum Jump: