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.

curl to post value to TRMNL api
#1
Hello,

I want to send data to TRMNL server

this curl command is ok : 

curl "https://trmnl.com/api/custom_plugins/xxxxxxxxxxxxxxxxxxxxxxxxxxx\
  -H "Content-Type: application/json" \
  -d '{"merge_variables": {"text":"Test", "author": "Pierre"}}' \
  -X POST

but my lua code don't work:
Code:
-- Load modules https = require('ssl.https') ltn12 = require('ltn12') json = require('json') body ='{"merge_variables": {"text":"Test", "author": "Pierre"}}' resp = {}   body = json.encode(Body)   res, code, headers = https.request({     url = 'https://trmnl.com/api/custom_plugins/xxxxxxxxxxxxxxxxxxxxxxxxxxx',     method = 'POST',     source = ltn12.source.string(body),     sink = ltn12.sink.table(resp),     headers = {                 ['Content-Type'] = 'application/json',                 ['Content-Length'] = #body                }   })   -- handle feedback       resp = table.concat(resp)     resp = json.pdecode(resp)   log(resp

i have this error: Must be nested inside a merge_variables payload object
could you can help me please.
Reply
#2
Try this:
Code:
http = require('socket.http') json = require('json') url = 'https://trmnl.com/api/custom_plugins/xxxxxxxxxxxxxxxxxxxxxxxxxxx' body = json.encode({   merge_variables = {     text = 'Test',     author = 'Pierre',   } }) resp, code, headers = http.request({   url = url,   method = 'POST',   body = body,   headers = {     ['Content-Type'] = 'application/json',   } }) resp = json.pdecode(resp) log(resp)
Reply
#3
perfect thanks a lot
Reply


Forum Jump: