Lua Api Calls¶
Name | Input Params | Return Data | Description |
---|---|---|---|
resiot_getapicall | String, String | String, String | Performs an API GET call with the ResIOT™ APIs |
resiot_postapicall | String, String | String, String | Performs an API POST call with the ResIOT™ APIs |
resiot_putapicall | String, String | String, String | Performs an API PUT call with the ResIOT™ APIs |
resiot_deleteapicall | String, String | String, String | Performs an API DELETE call with the ResIOT™ APIs |
resiot_getapicallwithhostandtoken | String, String, String, String | String, String | Performs an API GET call with the ResIOT™ APIs on a chosen server and token |
resiot_postapicallwithhostandtoken | String, String, String, String | String, String | Performs an API POST call with the ResIOT™ APIs on a chosen server and token |
resiot_putapicallwithhostandtoken | String, String, String, String | String, String | Performs an API PUT call with the ResIOT™ APIs on a chosen server and token |
resiot_deleteapicallwithhostandtoken | String, String, String, String | String, String | Performs an API DELETE call with the ResIOT™ APIs on a chosen server and token |
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.
-- Single Application Get Test
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)
if Err ~= "" then
-- error
resiot_debug(Err)
else
-- value read correctly
resiot_debug(Call)
end
-- Get Scene List with Limit 1 Test
Body = ''
Url = '/api/scenes?limit=1'
Call, Err = resiot_getapicall(Body, Url)
if Err ~= "" then
-- error
resiot_debug(Err)
else
-- value read correctly
resiot_debug(Call)
end
-- Get Applications List Count Test
Body = ''
Url = '/api/applications'
Call, Err = resiot_getapicall(Body, Url)
if Err ~= "" then
-- error
resiot_debug(Err)
else
-- value read correctly
resiot_debug(Call)
end
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.
-- Application Creation Test
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)
if Err ~= "" then
-- error
resiot_debug(Err)
else
-- value read correctly
resiot_debug(Call)
end
-- Scene Start Test
Body = ''
Url = '/api/scene/run/736365323639'
Call, Err = resiot_postapicall(Body, Url)
if Err ~= "" then
-- error
resiot_debug(Err)
else
-- value read correctly
resiot_debug(Call)
end
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.
-- Edit Name Application Test
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)
if Err ~= "" then
-- error
resiot_debug(Err)
else
-- value read correctly
resiot_debug(Call)
end
-- Edit Value of Application Test
Body = '{"name": "LuaPutVar", "value": "324"}'
Url = '/api/variables/LuaPutVar/value'
Call, Err = resiot_putapicall(Body, Url)
if Err ~= "" then
-- error
resiot_debug(Err)
else
-- value read correctly
resiot_debug(Call)
end
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.
-- Delete Application Test
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)
if Err ~= "" then
-- error
resiot_debug(Err)
else
-- value read correctly
resiot_debug(Call)
end
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
resiot_getapicallwithhostandtoken(String, String, String, String)¶
Performs an API GET call with the ResIOT™ APIs on a chosen server and token.
Example
Body = ''
Host = 'https://eu72.resiot.io'
Url = '/api/applications/2423423423234329'
Token = 'YOUR_API_TOKEN'
Call, Err = resiot_getapicallwithhostandtoken(Body, Host, Url, Token)
Input Parameters
- Body: (String) The Body of the API call, in the resiot_getapicallwithhostandtoken it's empty.
- Host: (String) It's the url of the server you want to use to make your API calls, it must contain the protocol (http:// or https://) and the server address or IP (and the port used if required, for example :8088).
- 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/".
- Token: (String) It's your API token, you can find it in ResIOT in Tutorial -> RESTful API V3
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.
-- Get Single Application Test
Body = '' -- The Body of the API call, in the resiot_getapicallwithhostandtoken it's empty
Host = 'https://eu72.resiot.io' -- The Host of the API call, it contains the protocol, the server address and the port
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/"
Token = 'YOUR_API_TOKEN' -- Your API Token, you must replace the value in this example, you can find it in ResIOT in Tutorial -> RESTful API V3
Call, Err = resiot_getapicallwithhostandtoken(Body, Host, Url, Token)
if Err ~= "" then
-- error
resiot_debug(Err)
else
-- value read correctly
resiot_debug(Call)
end
-- Get Scene List with Limit 1 Test
Body = ''
Host = 'https://eu72.resiot.io'
Url = '/api/scenes?limit=1'
Token = 'YOUR_API_TOKEN'
Call, Err = resiot_getapicallwithhostandtoken(Body, Host, Url, Token)
if Err ~= "" then
-- error
resiot_debug(Err)
else
-- value read correctly
resiot_debug(Call)
end
-- Get Applications List Count Test
Body = ''
Host = 'https://eu72.resiot.io'
Url = '/api/applications'
Token = 'YOUR_API_TOKEN'
Call, Err = resiot_getapicallwithhostandtoken(Body, Host, Url, Token)
if Err ~= "" then
-- error
resiot_debug(Err)
else
-- value read correctly
resiot_debug(Call)
end
resiot_postapicallwithhostandtoken(String, String, String, String)¶
Performs an API POST call with the ResIOT™ APIs on a chosen server and token.
Example
Body = '{"appEUI": "2423423423234329","name": "LuaTest"}'
Host = 'https://eu72.resiot.io'
Url = '/api/applications'
Token = 'YOUR_API_TOKEN'
Call, Err = resiot_postapicallwithhostandtoken(Body, Host, Url, Token)
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"}'.
- Host: (String) It's the url of the server you want to use to make your API calls, it must contain the protocol (http:// or https://) and the server address or IP (and the port used if required, for example :8088).
- 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/".
- Token: (String) It's your API token, you can find it in ResIOT in Tutorial -> RESTful API V3
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.
-- Create Application Test
Body = '{"appEUI": "2423423423234329","name": "LuaTest"}' -- The Body of the API call, contains the body displayed in the APIv3 page
Host = 'https://eu72.resiot.io' -- The Host of the API call, it contains the protocol, the server address and the port
Url = '/api/applications' -- It's the url of the API you want to use, the url can be found in your APIv3 page
Token = 'YOUR_API_TOKEN' -- Your API Token, you must replace the value in this example, you can find it in ResIOT in Tutorial -> RESTful API V3
Call, Err = resiot_postapicallwithhostandtoken(Body, Host, Url, Token)
if Err ~= "" then
-- error
resiot_debug(Err)
else
-- value read correctly
resiot_debug(Call)
end
-- Start Scene Test
Body = ''
Host = 'https://eu72.resiot.io'
Url = '/api/scene/run/736365323639'
Token = 'YOUR_API_TOKEN'
Call, Err = resiot_postapicallwithhostandtoken(Body, Host, Url, Token)
if Err ~= "" then
-- error
resiot_debug(Err)
else
-- value read correctly
resiot_debug(Call)
end
resiot_putapicallwithhostandtoken(String, String, String, String)¶
Performs an API PUT call with the ResIOT™ APIs on a chosen server and token.
Example
Body = '{"appEUI": "2423423423234329","name": "LuaNewName"}'
Host = 'https://eu72.resiot.io'
Url = '/api/applications/2423423423234329'
Token = 'YOUR_API_TOKEN'
Call, Err = resiot_putapicallwithhostandtoken(Body, Host, Url, Token)
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"}'.
- Host: (String) It's the url of the server you want to use to make your API calls, it must contain the protocol (http:// or https://) and the server address or IP (and the port used if required, for example :8088).
- 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/".
- Token: (String) It's your API token, you can find it in ResIOT in Tutorial -> RESTful API V3
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.
-- Edit Application Test
Body = '{"appEUI": "2423423423234329","name": "LuaNewName"}' -- The Body of the API call
Host = 'https://eu72.resiot.io' -- The Host of the API call, it contains the protocol, the server address and the port
Url = '/api/applications/2423423423234329' -- It's the url of the API you want to use
Token = 'YOUR_API_TOKEN' -- Your API Token, you must replace the value in this example, you can find it in ResIOT in Tutorial -> RESTful API V3
Call, Err = resiot_putapicallwithhostandtoken(Body, Host, Url, Token)
if Err ~= "" then
-- error
resiot_debug(Err)
else
-- value read correctly
resiot_debug(Call)
end
-- Edit Value of Variabile Test
Body = '{"name": "LuaPutVar", "value": "324"}'
Host = 'https://eu72.resiot.io'
Url = '/api/variables/LuaPutVar/value'
Token = 'YOUR_API_TOKEN'
Call, Err = resiot_putapicallwithhostandtoken(Body, Host, Url, Token)
if Err ~= "" then
-- error
resiot_debug(Err)
else
-- value read correctly
resiot_debug(Call)
end
resiot_deleteapicallwithhostandtoken(String, String, String, String)¶
Performs an API DELETE call with the ResIOT™ APIs on a chosen server and token.
Example
Body = ''
Host = 'https://eu72.resiot.io'
Url = '/api/applications/2423423423234329'
Token = 'YOUR_API_TOKEN'
Call, Err = resiot_deleteapicallwithhostandtoken(Body, Host, Url, Token)
Input Parameters
- Body: (String) The Body of the API call, contains the body displayed in the APIv3 page, in this case is empty.
- Host: (String) It's the url of the server you want to use to make your API calls, it must contain the protocol (http:// or https://) and the server address or IP (and the port used if required, for example :8088).
- 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/".
- Token: (String) It's your API token, you can find it in ResIOT in Tutorial -> RESTful API V3
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.
-- Delete Application Test
Body = '' -- The Body of the API call
Host = 'https://eu72.resiot.io' -- The Host of the API call, it contains the protocol, the server address and the port
Url = '/api/applications/2423423423234329' -- It's the url of the API you want to use
Token = 'YOUR_API_TOKEN' -- Your API Token, you must replace the value in this example, you can find it in ResIOT in Tutorial -> RESTful API V3
Call, Err = resiot_deleteapicallwithhostandtoken(Body, Host, Url, Token)
if Err ~= "" then
-- error
resiot_debug(Err)
else
-- value read correctly
resiot_debug(Call)
end