Skip to content

PHP code for API calls

ResIOT provides useful APIs that you can call from external environment, php pages are able to use them.
Here we have examples of many API calls :

Type URL Description
GET /api/user/gettoken/api/{Username}/{Password} How to get your API token
POST /api/applications Creation of an application
POST /api/application/node Creation of a node/device
PUT /api/application/{appEUI}/node/{devEUI} Edit a node/device
DELETE /api/application/{appEUI}/node/{devEUI} Delete a node/device
GET /api/application/nodes Get all your nodes/devices
GET /api/application/{appEUI}/nodes/{devEUI}/history Get tag fields history of a node/device
PUT /api/application/{appEUI}/nodes/{devEUI}/position Set the Latitude and the Longitude of a Node
GET /api/application/{appEUI}/nodes/{devEUI}/position Get the Latitude and the Longitude of a Node
POST /api/application/{appEUI}/nodes/{devEUI}/downlink Create a Downlink message
GET /api/application/{appEUI}/nodes/{devEUI}/tags Get all the tags of a node/device
GET /api/application/{appEUI}/nodes/{devEUI}/tag/{name} Get the last value of a Payload field
POST /api/scene/run/{hexId} Run a scene
POST /api/scene/runwithcallback Run a scene that returns an output value
POST /api/variables Creation of a variable
PUT /api/variables/multiple/values Edit multiple variables values
GET /api/variables/{name}/value Get the value of a variable

How to get your API token

Method 1

You can get your token from your settings page.

Step 1: in the top-left corner click on the settings button;

Step1
Step 2: click on button "My Settings"; Step2
Step 3: you will find your token next to "RESTful API V3 Token". Step3

Method 2

You can get your token using your credentials in an API call.
/api/user/gettoken/api/{Username}/{Password}

<?php
$URL = '<Your URL>'; // The URL of your service, Example: "https://eu72.resiot.io"
$Username = '<Your Username>'; // The Username that you use to login in into ResIOT
$Password = '<Your Password>'; // The Password that you use to login in into ResIOT
$Curl = curl_init($URL.'/api/user/gettoken/api/'.$Username.'/'.$Password); // Set up a connection to the server.

$Header = array(); // Initialize Headers
$Header[] = 'Accept: application/json';
curl_setopt($Curl, CURLOPT_HTTPHEADER, $Header);
curl_setopt($Curl, CURLOPT_RETURNTRANSFER, true);

$Response = curl_exec($Curl); // Call the API
curl_close($Curl); // Close the connection

$Obj = json_decode($Response); // Parse the Resulting JSON
echo $Obj->{'Token'}; // Print the resulting Token
?>

Creation of an application

/api/applications

<?php
//Insert your values in these variables
$host='eu72.resiot.io';                         // Enter your website
$token = '0123456789abcdef0123456789abcdef';    // Enter Your Token APIv3

$appEUI="abcd1234efab5678";
$name="New appeui";

// The url of the call used to create an application
$service_url = 'https://'.$host.'/api/applications';
// Set up a connection to the server.
$curl = curl_init($service_url);
$header = array();
$header[] = 'Accept: application/json';
$header[] = 'Grpc-Metadata-Authorization: '.$token;
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

/**     CREATE AN APPLICATION       **/
// POST Calls identifier
curl_setopt($curl, CURLOPT_POST, true);

// Enter the requested values of the body into this array
$curl_post_data = array(
  "appEUI"=> $appEUI,
  "name"=> $name
);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($curl_post_data));

//Use the following methods to see what the API returns in response
// Call the API
$curl_response = curl_exec($curl);
curl_close($curl);

// Print the response
echo $curl_response;
// If everything is ok the result in output will be {}
?>

Creation of a node/device

/api/application/node

<?php
//Insert your values in these variables
$host='eu72.resiot.io';                         // Enter your website
$token = '0123456789abcdef0123456789abcdef';    // Enter Your Token APIv3
$appEUI="abcd1234efab5678";
$devEUI="aaaaaaaaaaaaaaaa";                 // it has only 8 chars if $auth=Sigfox 
$idModel=0;                                 // *** You can find more details
                                            // for the idModel in the
                                            // image under this code
$adr=true;
$appKey="00112233445566778899aabbccddeeff";
$appSKey="";
$auth="OTAA";                               //OTAA, ABP, Sigfox
$class="A";                                 //A, B, C for OTAA and ABP,
                                            //no class for Sigfox
$devAddr="";
$enabled=true;
$group="";
$name="new node";
$nwkSKey="";
$tag="";

// The url of the call used to create a node/device
$service_url = 'https://'.$host.'/api/application/node';
// Set up a connection to the server.
$curl = curl_init($service_url);  
$header = array();
$header[] = 'Accept: application/json';
$header[] = 'Grpc-Metadata-Authorization: '.$token;
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

/**     CREATE A NODE/DEVICE        **/
// POST Calls identifier
curl_setopt($curl, CURLOPT_POST, true);

// Enter the requested values of the body into this array
// Commented fields are non-mandatory fields,
// if you want to modify some of those fields just uncomment them
$curl_post_data = array(
  "adr"=> $adr,
  "adrFrameCalculate"=> 7,
  "appEUI"=> $appEUI,
  "appKey"=> $appKey,
  // "appSKey"=> $appSKey,
  "auth"=> $auth,
  "chartsonDashboard"=> true,
  "class"=> $class,
  // "commandsOnDashboard"=> true,
  "dataWidgetOnDashboard"=> 0,
  // "devAddr"=> $devAddr,
  "devEUI"=> $devEUI,
  "enabled"=> $enabled,
  // "group"=> $group,
  // "hexIdLoRaWanServer"=> "string",
  // "idModel"=> $idModel,
  // "latitude"=> 0,
  // "longitude"=> 0,
  "name"=> $name,
  // "nwkSKey"=> $nwkSKey,
  "relaxFrameC"=> true,
  // "rx1Droffset"=> 0,
  "rx2Window"=> -1,
  // "rxwin"=> "RX1",
  // "tag"=> $tag,
  "timeout"=> 0
);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($curl_post_data));

//Use the following methods to see what the API returns in response
// Call the API
$curl_response = curl_exec($curl);
curl_close($curl);

// Print the response
echo $curl_response;
// If everything is ok the result in output will be {}
?>

*** You can find the idModel in the top-right corner of each model, as you can see here Model

Edit a node/device

/api/application/{appEUI}/node/{devEUI}

<?php
//Insert your values in these variables
$host='eu72.resiot.io';                             // Enter your website
$token = '0123456789abcdef0123456789abcdef';        // Enter Your Token APIv3
$appeui='abcd1234efab5678';                         // Enter your appEUI
$deveui='aaaaaaaaaaaaaaaa';                         // Enter your devEUI
$appEUINew="abcd1234efab5678";
$idModel=0;
$adr=true;
$appKey="00112233445566778899aabbccddeeff";
$appSKey="";
$auth="OTAA";                                       //OTAA, ABP, Sigfox
$class="A";                                         //A, B, C for OTAA and ABP,
                                                    //no class for Sigfox
$devAddr="";
$enabled=true;
$group="";
$name="new node";
$nwkSKey="";
$tag="";

// The url of the call used to edit a node/device
$service_url = 'https://'.$host.'/api/application/'.$appeui.'/node/'.$deveui;
// Set up a connection to the server.
$curl = curl_init($service_url);  
$header = array();
$header[] = 'Accept: application/json';
$header[] = 'Grpc-Metadata-Authorization: '.$token;
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

/**     EDIT A NODE/DEVICE      **/

// PUT Calls identifier
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
// Enter the requested values of the body into this array
// Commented fields are non-mandatory fields,
// if you want to modify some of those fields just uncomment them
$curl_post_data = array(
  // "adr"=> $adr,
  // "adrFrameCalculate"=> 7,
  // "appEUI"=> $appEUINew,
  "appKey"=> $appKey,
  // "appSKey"=> $appSKey,
  // "auth"=> $auth,
  // "chartsonDashboard"=> true,
  // "class"=> $class,
  // "commandsOnDashboard"=> true,
  // "dataWidgetOnDashboard"=> 0,
  // "devAddr"=> $devAddr,
  // "devEUI"=>     NOT EDITABLE
  // "enabled"=> $enabled,
  // "group"=> $group,
  // "hexIdLoRaWanServer"=> "string",
  // "idModel"=> $idModel,
  // "latitude"=> 0,
  // "longitude"=> 0,
  "name"=> $name
  // ,"nwkSKey"=> $nwkSKey,
  // "relaxFrameC"=> true,
  // "rx1Droffset"=> 0,
  // "rx2Window"=> -1,
  // "rxwin"=> "RX1",
  // "tag"=> $tag,
  // "timeout"=> 0
);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($curl_post_data));

//Use the following methods to see what the API returns in response
// Call the API
$curl_response = curl_exec($curl);
curl_close($curl);

// Print the response
echo $curl_response;
// If everything is ok the result in output will be {}
?>

Delete a node/device

/api/application/{appEUI}/node/{devEUI}

<?php
$host='eu72.resiot.io';                         // Enter your website
$token = '<Your Token APIv3>';                  // Enter Your Token APIv3   
$appeui='abcd1234efab5678';             // Enter your appEUI
$deveui='aaaaaaaaaaaaaaaa';             // Enter your devEUI
// The url of the call used to delete a node/device
$service_url = 'https://'.$host.'/api/application/'.$appeui.'/node/'.$deveui;
// Set up a connection to the server.
$curl = curl_init($service_url);

// Set up a connection to the server.   
$header = array();
$header[] = 'Accept: application/json';
$header[] = 'Grpc-Metadata-Authorization: '.$token;
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
/**     DELETE A NODE/DEVICE        **/

//DELETE Calls identifier
url_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
//No curl_post_data

//Use the following methods to see what the API returns in response
// Call the API
$curl_response = curl_exec($curl);
curl_close($curl);

// Print the response
echo $curl_response;
// If everything is ok the result in output will be {}
?>

Get all your nodes/devices

/api/application/nodes

<?php
$token = '0123456789abcdef0123456789abcdef';    // Enter Your Token APIv3
$host = 'eu72.resiot.io';                       // insert your website here
$nodesPerCycle=1000;                            //How many nodes/devices we get from each API call and
                                                //also how many are shown in one line (max 1000)
$timeout=150000;                                //Sleep of 150ms in order to prevent the 
                                                //"Too many API calls per second" error. Only for Free version
 ///STEP 1
echo "<h1>List of devices</h1>";
// The url of the call used to get the number of nodes/devices on the platform
$service_url = 'https://'.$host.'/api/application/nodes';
// Set up a connection to the server.
$curl = curl_init($service_url);
$header = array();
$header[] = 'Accept: application/json';
$header[] = 'Grpc-Metadata-Authorization: '.$token;
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

//The following methods are used to get what the API returns in response
// Call the API
$curl_response = curl_exec($curl);
curl_close($curl);
$obj=json_decode($curl_response);       //JSON parsed to object in order to get the data
$num=$obj->totalCount;                  //The number of nodes/devices
//example of API output {"totalCount": "2"}
//The following are the fields of the URL for the next API calls
$limit=$nodesPerCycle;                                  
$offset=0;                              //Initialization of the offset field

 ///STEP 2
//A cycle for each node/device, up to the end of the list
for($i = 0; $i < $num/$limit; $i++){
    usleep($timeout);
    $cicle_url='https://'.$host.'/api/application/nodes?limit='.$limit.'&offset='.$offset; //The API call
    // Set up a connection to the server.
    $Ncurl = curl_init($cicle_url);
    $h= array();
    $h[] = 'Accept: application/json';
    $h[] = 'Grpc-Metadata-Authorization: '.$token;
    curl_setopt($Ncurl, CURLOPT_HTTPHEADER,$h);
    curl_setopt($Ncurl, CURLOPT_RETURNTRANSFER, true);
    // What the API returns in response
    $Ncurl_response = curl_exec($Ncurl);
    curl_close($Ncurl);
    echo $Ncurl_response."<br>";
    //example echo output:
    // {
    //      "totalCount":"1","result":[{"name":"Emotion node","auth":"NULLA","devEUI":"1122334455667788",
    //      "appEUI":"abcd1234efab5678","enabled":true,"timeout":129600,"rx2Window":-1,"adr":true,
    //      "adrFrameCalculate":7,"relaxFrameC":true,"class":"NULLC","hexId":"6e6f6436303039"}]
    // }
    $object=json_decode($Ncurl_response);               //JSON parsed to object in order to get the data
    for($j=0;$j<$limit;$j++){
        echo $object->result[$j]->name;                 //This is the name of the node/device
        echo "devEUI: ".$object->result[$j]->devEUI;    //This is its deveui
        echo "appEUI: ".$object->result[$j]->appEUI;    //This is its appeui
    }
    //example of object values output: Emotion node     devEUI: 1122334455667788    appEUI: abcd1234efab5678
    echo "<br><br>";
    $offset+=1;         //Increment of the offset in order to get the next node/device in the next cycle
}
?>

Get tag fields history of a node/device

/api/application/{appEUI}/nodes/{devEUI}/history

<?php
$appeui='abcd1234efab5678';                     //insert your appeui here
$deveui='1122334455667788';                     //insert your deveui here
$token = '0123456789abcdef0123456789abcdef';    // Enter Your Token APIv3
$host = 'eu72.resiot.io';                       // insert your website here
$nodesPerCycle=2;                               //How many events we get from each API call and also how many are shown in one line (max 50)
$timeout=150000;                                //Sleep of 150ms in order to prevent the "Too many API calls per second" error. Only for Free version
// The url of the call used to get the number of events in the history of the node/devices
$service_url = 'https://'.$host.'/api/application/'.$appeui.'/nodes/'.$deveui.'/history';
 ///STEP 1
// Set up a connection to the server.
$curl = curl_init($service_url);
$header = array();
$header[] = 'Accept: application/json';
$header[] = 'Grpc-Metadata-Authorization: '.$token;
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

//The following methods are used to get what the API returns in response
// Call the API
$curl_response = curl_exec($curl);
curl_close($curl);
$obj=json_decode($curl_response);       //JSON parsed to object in order to get the data
$num=$obj->totalCount;                  //The number of events in the history
//example of API output {"totalCount": "75"}

 ///STEP 2
//The following are the fields of the URL for the next API calls
$limit=$nodesPerCycle;
$offset=0;                              //Initialization of the offset field

echo "<h1>History of the node/device</h1>";

//A cycle every two events, up to the end of the history
for($i = 0; $i < $num/$limit; $i++){
    usleep($timeout);
    $cycle_url= $service_url.'?limit='.$limit.'&offset='.$offset; //The API call
    // Set up a connection to the server.
    $Ncurl = curl_init($cycle_url);
    $h= array();
    $h[] = 'Accept: application/json';
    $h[] = 'Grpc-Metadata-Authorization: '.$token;
    curl_setopt($Ncurl, CURLOPT_HTTPHEADER,$h);
    curl_setopt($Ncurl, CURLOPT_RETURNTRANSFER, true);
    // What the API returns in response
    $Ncurl_response = curl_exec($Ncurl);
    curl_close($Ncurl);
    echo $Ncurl_response."<br>";
    //example echo output:
    // {
    //      "totalCount":"75","result":[{"date":"2018-10-16 23:49:33.008543 +0100 usr",
    //      "result":[{"tag":"Distance","value":"2290"}]},{"date":"2018-10-16 23:44:33.010617 +0100 usr",
    //      "result":[{"tag":"Distance","value":"2260"}]}]
    // }
    $object=json_decode($Ncurl_response);           //JSON parsed to object in order to get the data
    for($j=0;$j<$limit;$j++){
        echo $object->result[$j]->date;             //This is the date of the event of the node/device
        echo $object->result[$j]->result[0]->tag;   //This is the name of the tag involved
        echo $object->result[$j]->result[0]->value; //This is the value registered in the tag
    }
    //example of object values output: 2018-10-16 23:49:33.008543 +0100 usr     Distance: 2290      2018-10-16 23:44:33.010617 +0100 usr    Distance: 2260
    echo "<br><br>";
    $offset+=$limit;                    //Increment of the offset in order to get the next 2 events in the next cycle
}
?>

Set the Latitude and the Longitude of a Node/Device

/api/application/{appEUI}/nodes/{devEUI}/position

<?php
//Insert your values in these variables
$host='eu72.resiot.io';                             // Enter your website
$token = '0123456789abcdef0123456789abcdef';        // Enter Your Token APIv3

$appeui='abcd1234efab5678';                         // Enter your appEUI
$deveui='aaaaaaaaaaaaaaaa';                         // Enter your devEUI
$latitude=20.354;                                   // Enter the latitude
$longitude=30.857;                                  // Enter the longitude

// The url of the call used to edit a node/device
$service_url = 'https://'.$host.'/api/application/'.$appeui.'/nodes/'.$deveui.'/position';
// Set up a connection to the server.
$curl = curl_init($service_url);  
$header = array();
$header[] = 'Accept: application/json';
$header[] = 'Grpc-Metadata-Authorization: '.$token;
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

/**     EDIT LATITUDE/LONGITUDE     **/

// PUT Calls identifier
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
// Enter the requested values of the body into this array
// Commented fields are non-mandatory fields,
// if you want to modify some of those fields just uncomment them
$curl_post_data = array(
  "latitude"=> $latitude,
  "longitude"=> $longitude
);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($curl_post_data));

//Use the following methods to see what the API returns in response
// Call the API
$curl_response = curl_exec($curl);
curl_close($curl);

// Print the response
echo $curl_response;
// If everything is ok the result in output will be {}
?>

Get the Latitude and Longitude of a Node/Device

/api/application/{appEUI}/nodes/{devEUI}/position

<?php
$host = 'eu72.resiot.io';                       // Insert your website here
$token = '0123456789abcdef0123456789abcdef';    // Enter Your Token APIv3
$appeui='abcd1234efab5678';                     // Enter your appEUI
$deveui='aaaaaaaaaaaaaaaa';                     // Enter your devEUI
$service_url = 'https://'.$host.'/api/application/'.$appeui.'/nodes/'.$deveui.'/position';
// Set up a connection to the server.   
$curl = curl_init($service_url);  
$header = array();
$header[] = 'Accept: application/json';
$header[] = 'Grpc-Metadata-Authorization: '.$token;
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// Call the API
$curl_response = curl_exec($curl);
curl_close($curl);

// Print the response
echo $curl_response;
//Example of echo output:   {
//                            "latitude": 20.354,
//                            "longitude": 40,
//                            "lastTimeEdit": "2018-10-19 11:30:11 +0200 CEST"
//                          }
?>

/api/application/{appEUI}/nodes/{devEUI}/downlink

<?php
//Insert your values in these variables
$host='eu72.resiot.io';                         // Enter your website
$token = '0123456789abcdef0123456789abcdef';    // Enter Your Token APIv3

$appeui="4321567812349876";
$deveui="4321567812349876";
$command="";
$timeoutDuration="0";
$askConfirmation=false;
$extraData="";
$gwEUI="";
$hexIdConnector="";
$payload="1234";
$port=1;
$raw=false;
$reference="myrefnum";

// The url of the call used to create a variable
$service_url = 'https://'.$host.'/api/variables';
// Set up a connection to the server.
$curl = curl_init($service_url);
// Set up a connection to the server.   
$header = array();
$header[] = 'Accept: application/json';
$header[] = 'Grpc-Metadata-Authorization: '.$token;
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

/**     CREATE A DOWNLINK MESSAGE       **/
// POST Calls identifier
curl_setopt($curl, CURLOPT_POST, true);

// Enter the requested values of the body into this array
// Commented fields are non-mandatory fields,
// if you want to modify some of those fields just uncomment them
$curl_post_data = array(
  "appEUI"=> $appeui,
  "devEUI"=> $deveui,
 // "Command"=> $command,
  "TimeoutDuration"=> $timeoutDuration,
  "askConfirmation"=> $askConfirmation,
 // "extraData"=> $extraData,
 // "gwEUI"=> $gwEUI,
 // "hexIdConnector"=> $hexIdConnector,
  "payload"=> $payload,
  "port"=> $port,
  "raw"=> $raw,
  "reference"=> $reference
);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($curl_post_data));

//Use the following methods to see what the API returns in response
// Call the API
$curl_response = curl_exec($curl);
curl_close($curl);

// Print the response
echo $curl_response;
// If everything is ok the result in output will be {}
?>

Get all the tags of a node/device

/api/application/{appEUI}/nodes/{devEUI}/tags

<?php
$host = 'eu72.resiot.io';                       // Insert your website here
$token = '0123456789abcdef0123456789abcdef';    // Enter Your Token APIv3
$appeui='abcd1234efab5678';                     // Enter your appEUI
$deveui='aaaaaaaaaaaaaaaa';                     // Enter your devEUI
$limit=20;                                      // Enter the max number of tags you get from one call
$service_url = 'https://'.$host.'/api/application/'.$appeui.'/nodes/'.$deveui.'/tags?limit='.$limit;
// Set up a connection to the server.   
$curl = curl_init($service_url);  
$header = array();
$header[] = 'Accept: application/json';
$header[] = 'Grpc-Metadata-Authorization: '.$token;
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// Call the API
$curl_response = curl_exec($curl);
curl_close($curl);

// Print the response
echo $curl_response;
//Example of echo output:   
//{
//  "result": [
//      {
//        "value": "0",
//        "lastTimeEdit": "0001-01-01 02:00:00 +0200 usr",
//        "type": "Numeric",
//        "name": "Altitude"
//      },
//      {
//        "value": "20.354",
//        "lastTimeEdit": "2018-10-19 11:30:11 +0200 usr",
//        "type": "Numeric",
//        "name": "Latitude"
//      },
//      {
//        "value": "40",
//        "lastTimeEdit": "2018-10-19 11:30:11 +0200 usr",
//        "type": "Numeric",
//        "name": "Longitude"
//      }
//  ]
//}
?>

Get the last value of a payload field

/api/application/{appEUI}/nodes/{devEUI}/tag/{name}

<?php
$host = 'eu72.resiot.io';                       // Insert your website here
$token = '0123456789abcdef0123456789abcdef';    // Enter Your Token APIv3
$appeui='abcd1234efab5678';                     // Enter your appEUI
$deveui='aaaaaaaaaaaaaaaa';                     // Enter your devEUI
$tag='Latitude';                                // Enter the max number of tags
                                                // you get from one call
$service_url = 'https://'.$host.'/api/application/'.$appeui.'/nodes/'.$deveui.'/tag/'.$tag;
// Set up a connection to the server.   
$curl = curl_init($service_url);  
$header = array();
$header[] = 'Accept: application/json';
$header[] = 'Grpc-Metadata-Authorization: '.$token;
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// Call the API
$curl_response = curl_exec($curl);
curl_close($curl);

// Print the response
echo $curl_response;
//Example of echo output:   
//{
//  "value": "20.354",
//  "lastTimeEdit": "2018-10-19 11:30:11 +0200 usr",
//  "type": "Numeric",
//  "name": "Latitude"
//}
?>

Run a scene

/api/scene/run/{hexId}

<?php
//Insert your values in these variables
$host='eu72.resiot.io';                         // Enter your website
$token = '0123456789abcdef0123456789abcdef';    // Enter Your Token APIv3

$hexId=736365333431;

// The url of the call used to run a scene
$service_url = 'https://'.$host.'/api/scene/run/'.$hexId;
// Set up a connection to the server.
$curl = curl_init($service_url);
// Set up a connection to the server.   
$header = array();
$header[] = 'Accept: application/json';
$header[] = 'Grpc-Metadata-Authorization: '.$token;
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

/**     RUN A SCENE     **/
// POST Calls identifier
curl_setopt($curl, CURLOPT_POST, true);

//Use the following methods to see what the API returns in response
// Call the API
$curl_response = curl_exec($curl);
curl_close($curl);

// Print the response
echo $curl_response;
// If everything is ok the result in output will be {}
?>

Run a scene that returns an output value

/api/scene/runwithcallback

Script Lua Scene

Here's an example of a Script Lua Scene which reads a tag and returns the double of the value.

-- Node/device informations
AppEUI = "4321567812349876"     -- The AppEUI of the node/device
DevEUI = "4321567812349876"     -- The DevEUI of the node/device
Tag = "Longitude"               -- The tag field you want to read,
                                -- in this example the value of this field is 40
JSON = resiot_comm_getparam("input")
Value1, err1 = json_getfield(JSON, "value1")
Value2, err2 = json_getfield(JSON, "value2")
Content, Error = resiot_getnodevalue(AppEUI, DevEUI, Tag)
Result = tonumber(Value1)+tonumber(Value2)+Content
Result = Result * 2
resiot_setreturnvalue(tostring(Result))

In order to create a Script Lua Scene follow these steps:

  1. Click in the left menu on "Smart Scenes/Lua Scripts"
  2. Click on the green Add New button and choose "Script Lua 5.1 Scene"
  3. Write a name for your scene in the Name field, then write your lua code
  4. When you're ready click on the "Create" blue button
  5. Now you can copy the Hex ID from the list of your scenes into the php variable called $hexId

PHP code

Here's the PHP code to run that scene

<?php
//Insert your values in these variables
$host='eu72.resiot.io';                         // Enter your website
$token = '0123456789abcdef0123456789abcdef';    // Enter Your Token APIv3

$hexId="736365333433";
$input='{"value1":27, "value2":4}';
$tag="Scene_tag";

// The url of the call used to run a scene with callback
$service_url = 'https://'.$host.'/api/scene/runwithcallback';
// Set up a connection to the server.
$curl = curl_init($service_url);
$header = array();
$header[] = 'Accept: application/json';
$header[] = 'Grpc-Metadata-Authorization: '.$token;
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

/**     RUN A SCENE WITH OUTPUT     **/
// POST Calls identifier
curl_setopt($curl, CURLOPT_POST, true);

// Enter the requested values of the body into this array
// You can select the scene to run by the HexID or by the Tag
$curl_post_data = array(
  "HexId"=> $hexId,
  "Input"=> $input/*,
  "Tag"=> $tag      */
);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($curl_post_data));

//Use the following methods to see what the API returns in response
// Call the API
$curl_response = curl_exec($curl);
curl_close($curl);

// Print the response
echo $curl_response;
// If everything is ok the result in output will be the output of the scene
// In this example the result will be {"Output":"142"}
?>

For an example of an application that uses this API call click on this icon. Find

Creation of a variable

/api/variables

<?php
//Insert your values in these variables
$host='eu72.resiot.io';                         // Enter your website
$token = '0123456789abcdef0123456789abcdef';    // Enter Your Token APIv3

$enabled=true;
$name="Example";
$resetOnStart=false;
$timeout=0;
$type="String";
$unitsOfMeasurament="km";
$value="This is the value";
$valueOnServerReset="Server resetted";

// The url of the call used to create a variable
$service_url = 'https://'.$host.'/api/variables';
// Set up a connection to the server.
$curl = curl_init($service_url);
// Set up a connection to the server.   
$header = array();
$header[] = 'Accept: application/json';
$header[] = 'Grpc-Metadata-Authorization: '.$token;
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

/**     CREATE A VARIABLE       **/
// POST Calls identifier
curl_setopt($curl, CURLOPT_POST, true);

// Enter the requested values of the body into this array
// Commented fields are non-mandatory fields,
// if you want to modify some of those fields just uncomment them
$curl_post_data = array(
  "enabled"=> $enabled,
  "name"=> $name,
  // "resetOnRestart"=> $resetOnStart,
  // "timeout"=> $timeout,
  "type"=> $type,
  // "unitsOfMeasurament"=> $unitsOfMeasurament,
  "value"=> $value,
  // "valueOnServerReset"=> $valueOnServerReset
);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($curl_post_data));

//Use the following methods to see what the API returns in response
// Call the API
$curl_response = curl_exec($curl);
curl_close($curl);

// Print the response
echo $curl_response;
// If everything is ok the result in output will be {}


/**     CREATION OF A SECOND VARIABLE       **/

$enabled=true;
$name="APIVAR2";
$resetOnStart=false;
$timeout=0;
$type="String";
$unitsOfMeasurament="km";
$value="This is the value";
$valueOnServerReset="Server resetted";

// The url of the call used to create a variable
$service_url = 'https://'.$host.'/api/variables';
// Set up a connection to the server.
$curl = curl_init($service_url);
// Set up a connection to the server.   
$header = array();
$header[] = 'Accept: application/json';
$header[] = 'Grpc-Metadata-Authorization: '.$token;
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);


// POST Calls identifier
curl_setopt($curl, CURLOPT_POST, true);

// Enter the requested values of the body into this array
// Commented fields are non-mandatory fields,
// if you want to modify some of those fields just uncomment them
$curl_post_data = array(
  "enabled"=> $enabled,
  "name"=> $name,
  // "resetOnRestart"=> $resetOnStart,
  // "timeout"=> $timeout,
  "type"=> $type,
  // "unitsOfMeasurament"=> $unitsOfMeasurament,
  "value"=> $value,
  // "valueOnServerReset"=> $valueOnServerReset
);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($curl_post_data));

//Use the following methods to see what the API returns in response
// Call the API
$curl_response = curl_exec($curl);
curl_close($curl);

// Print the response
echo $curl_response;
// If everything is ok the result in output will be {}
?>

Edit multiple variables values

/api/variables/multiple/values

<?php
$host = 'eu72.resiot.io';                       // Insert your website here
$token = '0123456789abcdef0123456789abcdef';    // Enter Your Token APIv3
$name1="Example";
$nameN="APIVAR2";
$value1="updated value";
$valueN="24";
// Enter the url of the call you want to perform
$service_url = 'https://'.$host.'/api/variables/multiple/values';
// Set up a connection to the server.   
$curl = curl_init($service_url);
// Set up a connection to the server.   
$header = array();
$header[] = 'Accept: application/json';
$header[] = 'Grpc-Metadata-Authorization: '.$token;
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

// PUT Calls identifier
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");

// Enter the requested values of the body (if there is one) into the Data array
//Create an array for each variable to modify
$var1=array("name"=>$name1 ,"value"=>$value1 );
$var2=array("name"=>$nameN ,"value"=>$valueN );
//Create an array that contains the data array (which contains the variables)
$curl_post_data = array("data"=>array($var1,$var2));
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($curl_post_data));

// Call the API
$curl_response = curl_exec($curl);
curl_close($curl);

// Print the response
echo $curl_response;
// If everything is ok the result in output will be {}
?>

Get the value of a variable

/api/variables/{name}/value

<?php
$host = 'eu72.resiot.io';                       // Insert your website here
$token = '0123456789abcdef0123456789abcdef';    // Enter Your Token APIv3
$name="Example";
$service_url = 'https://'.$host.'/api/variables/'.$name.'/value';
// Set up a connection to the server.   
$curl = curl_init($service_url);  
$header = array();
$header[] = 'Accept: application/json';
$header[] = 'Grpc-Metadata-Authorization: '.$token;
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// Call the API
$curl_response = curl_exec($curl);
curl_close($curl);

// Print the response
echo $curl_response;
//Example of echo output:   {
//                            "value": "updated value",
//                            "lastTimeEdit": "2018-10-18 17:39:16 +0200 CEST",
//                            "type": "String"
//                          }
?>