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.

Bond Bridge API to LUA
#1
Hi All, 

Probably a simple one for most but could I get some assistance converting this curl function to Lua

Code:
curl -H "BOND-Token: f074b61f628018fd" -i http://192.100.0.61/v2/devices/79135791/actions/SetSpeed -X PUT -d "{\"argument\": 3}"
[url=http://docs-local.appbond.com/#section/API-Concepts][/url]
Typically I am seeing the http request defaulting back to the GET function and not pushing the PUT.

Thanks in advance
Reply
#2
http = require("socket.http")
ltn12 = require 'ltn12'
json = require('json')


http = require('socket.http')

url = 'http://192.168.0.xxx/v2/devices/--Devide ID--/actions/Close'


body = json.encode({
  Close = {
    {
      argument = 'null',
    }
  }
})


resp_Values = {}

res, code, headers = http.request({
  url = url,
  method = 'PUT',
  sink = ltn12.sink.table(resp_Values),
  source = ltn12.source.string(body),
headers = {
  ['BOND-Token'] = 'b084cc33192220e',
  ['content-length'] = #body,
  ["Content-Type"] = "application/json";
  }
   
})


Code above works for the Bond Bridge for anyone interested.
Reply


Forum Jump: