Skip to content

Lua Api Calls

Name Input Params Return Data Description
resiot_getapicall String, String String Performs an API GET call with the ResIOT™ APIs
resiot_postapicall String, String String Performs an API POST call with the ResIOT™ APIs
resiot_putapicall String, String String Performs an API PUT call with the ResIOT™ APIs
resiot_deleteapicall String, String String Performs an API DELETE call with the ResIOT™ APIs
Example Example of extraction of all nodes with call of the "Reset/Resend Channels of Node" API

resiot_getapicall(String, String)

Performs an API GET call with the ResIOT™ APIs.
Example
Body = ''
Url = '/api/applications/2423423423234329'
Call, Err = resiot_getapicall(Body, Url)
Input Parameters
 - Body: (String) The Body of the API call, in the resiot_getapicall it's empty.
 - Url: (String) It's the url of the API you want to use, the url can be found in your APIv3 page, after selecting a get APIs, launch it to retreive the url in the "Request URL" section, the part to copy is the one that begins with "/api/".
Returns
 - Call (String): Contains the response from the APIs, the format is a valid JSON.
 - Err (String): If there is an Error during the execution of the API call, it will be displayed here.

Body = ''                                   -- The Body of the API call, in the resiot_getapicall it's empty
Url = '/api/applications/2423423423234329'  -- It's the url of the API you want to use, the url can be found in your APIv3 page, after selecting a get APIs, 
                                            -- launch it to retreive the url in the "Request URL" section, the part to copy is the one that begins with "/api/"
Call, Err = resiot_getapicall(Body, Url)
resiot_debug(Call)
-- 
-- In This case:
-- 
-- Call = '{"appEUI":"2423423423234329","name":"LuaTest"}'
-- 
-- Err = ''
-- 
Body = ''
Url = '/api/scenes?limit=1'
Call, Err = resiot_getapicall(Body, Url)
resiot_debug(Call)
-- 
-- In This case:
-- 
-- Call = '{"totalCount":10,"result":[{"hexId":"001122334455","name":"Scene Smart Nodes","type":"Smart","enabled":"Enabled"}]}'
-- 
-- Err = ''
-- 
Body = ''
Url = '/api/applicazion'
Call, Err = resiot_getapicall(Body, Url)
resiot_debug(Call)
resiot_debug(Err)
-- 
-- In This case:
-- 
-- Call = ''
-- 
-- Err = 'getApiCallError: API Not Found'
-- 

Return to index


resiot_postapicall(String, String)

Performs an API POST call with the ResIOT™ APIs.
Example
Body = '{"appEUI": "2423423423234329","name": "LuaTest"}'
Url = '/api/applications'
Call, Err = resiot_postapicall(Body, Url)
Input Parameters
 - Body: (String) The Body of the API call, contains the body displayed in the APIv3 page, in this case is '{"appEUI": "2423423423234329","name": "LuaTest"}'.
 - Url: (String) It's the url of the API you want to use, the url can be found in your APIv3 page, after selecting a get APIs, launch it to retreive the url in the "Request URL" section, the part to copy is the one that begins with "/api/".
Returns
 - Call (String): Contains the response from the APIs, the format is a valid JSON.
 - Err (String): If there is an Error during the execution of the API call, it will be displayed here.

Body = '{"appEUI": "2423423423234329","name": "LuaTest"}'   -- The Body of the API call, contains the body displayed in the APIv3 page
Url = '/api/applications'                                   -- It's the url of the API you want to use, the url can be found in your APIv3 page
Call, Err = resiot_postapicall(Body, Url)
resiot_debug(Call)
-- 
-- In This case:
-- 
-- Call = '{"appEUI":"2423423423234329"}'
-- 
-- Err = ''
-- 
Body = ''
Url = '/api/scene/run/736365323639'
Call, Err = resiot_postapicall(Body, Url)
resiot_debug(Call)
-- 
-- In This case:
-- 
-- Call = '{}'
-- 
-- Err = ''
-- 
-- In the log will be printed the result of the scene
-- 
Body = '{"appEUI": "2423423423234329","name": "LuaTest"}'
Url = '/api/applicazion'
Call, Err = resiot_postapicall(Body, Url)
resiot_debug(Err)
-- 
-- In This case:
-- 
-- Call = ''
-- 
-- Err = 'postApiCallError: API Not Found'
-- 

Return to index


resiot_putapicall(String, String)

Performs an API PUT call with the ResIOT™ APIs.
Example
Body = '{"appEUI": "2423423423234329","name": "LuaNewName"}'
Url = '/api/applications/2423423423234329'
Call, Err = resiot_putapicall(Body, Url)
Input Parameters
 - Body: (String) The Body of the API call, contains the body displayed in the APIv3 page, in this case is '{"appEUI": "2423423423234329","name": "LuaNewName"}'.
 - Url: (String) It's the url of the API you want to use, the url can be found in your APIv3 page, after selecting a get APIs, launch it to retreive the url in the "Request URL" section, the part to copy is the one that begins with "/api/".
Returns
 - Call (String): Contains the response from the APIs, the format is a valid JSON.
 - Err (String): If there is an Error during the execution of the API call, it will be displayed here.

Body = '{"appEUI": "2423423423234329","name": "LuaNewName"}'    -- The Body of the API call
Url = '/api/applications/2423423423234329'                      -- It's the url of the API you want to use
Call, Err = resiot_putapicall(Body, Url)
resiot_debug(Call)
-- 
-- In This case:
-- 
-- Call = '{}'
-- 
-- Err = ''
-- 
Body = '{""name": "LuaPutVar", value": "324"}'
Url = '/api/variables/LuaPutVar/value'
Call, Err = resiot_putapicall(Body, Url)
resiot_debug(Call)
-- 
-- In This case:
-- 
-- Call = '{}'
-- 
-- Err = ''
-- 
Body = '{"appEUI": "2423423423234329","name": "LuaTestError"}'
Url = '/api/applicazion/2423423423234329'
Call, Err = resiot_putapicall(Body, Url)
resiot_debug(Err)
-- 
-- In This case:
-- 
-- Call = ''
-- 
-- Err = 'putApiCallError: API Not Found'
-- 

Return to index


resiot_deleteapicall(String, String)

Performs an API DELETE call with the ResIOT™ APIs.
Example
Body = ''
Url = '/api/applications/2423423423234329'
Call, Err = resiot_deleteapicall(Body, Url)
Input Parameters
 - Body: (String) The Body of the API call, contains the body displayed in the APIv3 page, in this case is empty.
 - Url: (String) It's the url of the API you want to use, the url can be found in your APIv3 page, after selecting a get APIs, launch it to retreive the url in the "Request URL" section, the part to copy is the one that begins with "/api/".
Returns
 - Call (String): Contains the response from the APIs, the format is a valid JSON.
 - Err (String): If there is an Error during the execution of the API call, it will be displayed here.

Body = ''                                   -- The Body of the API call
Url = '/api/applications/2423423423234329'  -- It's the url of the API you want to use
Call, Err = resiot_deleteapicall(Body, Url)
resiot_debug(Call)
-- 
-- In This case:
-- 
-- Call = '{}'
-- 
-- Err = ''
-- 
Body = ''
Url = '/api/applicazion/2423423423234329'
Call, Err = resiot_deleteapicall(Body, Url)
resiot_debug(Err)
-- 
-- In This case:
-- 
-- Call = ''
-- 
-- Err = 'putApiCallError: API Not Found'
-- 

Return to index


Example

Example of extraction of all nodes with call of the "Reset/Resend Channels of Node" API

GetAllNodesJson, Err = resiot_getapicall("", "/api/application/nodes") -- Get Count of all nodes
if Err ~= "" then
  resiot_debug("Error during the call of the API.")
  return
end

CountSTR, Err = json_getfield(GetAllNodesJson, "totalCount") -- Get the count from the json
if Err ~= "" then
  resiot_debug("Json badly formatted.")
  return
end

Count = tonumber(CountSTR)  -- Convert count from string to number
Offset = 0                  -- Initialize Offset variable
while Count > 0 do          -- Cycle until the count goes to 0 or below
  resiot_sleep(1000)        -- Sleeps of 1 second between API calls are needed to work correctly
  NodeDatas, Err = resiot_getapicall("", "/api/application/nodes?limit=1000&offset="..tostring(Offset)) -- Get Node datas 
  if Err ~= "" then
    resiot_debug("Error during the call of the API.")
    return
  end
  if Count > 1000 then -- Get the count of the node in this cycle, it can be maximum 1000
    C = 1000
  else
    C = Count-1
  end
  for i=0,C,1 do    -- Cycle all the node that the last call give in response
    appEUI, Err = json_getfield(NodeDatas, "result."..tostring(i)..".appEUI") -- Get AppEUI
    devEUI, Err = json_getfield(NodeDatas, "result."..tostring(i)..".devEUI") -- Get DevEUI
    resiot_sleep(1000)
    Result, Err = resiot_putapicall("", "/api/application/"..appEUI.."/nodes/"..devEUI.."/resetchannel") -- Call the "Reset/Resend Channels of Node" API
    if Err ~= "" then
      resiot_debug("Error during the call of the API.")
    end
  end
  Count = Count - 1000
  Offset = Offset + 1000
end

Return to index