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 body
#1
Hi @ all,
I need a little help for send a body in a script. I don't know way, if i send it via Postman it works and if I try via script, the answer it is 422 (error in body compose).
This is my script:
Code:
https = require('ssl.https')
json = require('json')
ltn12 = require('ltn12')
--local body = {}
test = '{"commands":{["component":"main","capability":"switch","command":"on"]}}' --body json
--log(test)
token = 'xxxxxxxxxxxxxxxxxxxxxx' --token auth
tbl = {}

res, code,headers, status = https.request({
  url = 'https://api.smartthings.com/v1/devices/--devices ID--/commands',
  method = 'POST',
  headers = {
    ['authorization'] = 'Bearer ' ..token,
    ['content-type']  = 'application/json',
    ['content-length'] = #test,
  },
  sink = ltn12.sink.table(tbl),
    log(sink),
  source = ltn12.source.string(test),
    log(source)
})

if res and code == 200 then
  resp = table.concat(tbl)
  resp = json.pdecode(resp)

  -- This lists a Table with all your information: 
  log(resp)
else
  log(res, code)
end
Reply


Messages In This Thread
Http POST body - by CristianAgata - 01.02.2023, 17:11
RE: Http POST body - by admin - 02.02.2023, 08:29
RE: Http POST body - by CristianAgata - 02.02.2023, 08:38
RE: Http POST body - by CristianAgata - 02.02.2023, 12:43

Forum Jump: