01.02.2023, 17:11
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:
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