CavyIoT HTTP RESTful API


Get started

Welcome to CavyIoT API Reference. Here you can reference most of the entities of our application, and how to update, create, retrieve, edit or delete them.

The purpose of this document is to empower hardware and software developers to build innovative IoT applications. This section is to help you understand what happens in the backstage when communicating with CavyIoT, so you can replicate this in your firmware.


Get API-KEY

API-Key authenticate requests to CavyIoT. Every request sent to CavyIoT requires a API-key and it is unique for each Device in your account that authorizes requests sent to CavyIoT.

Sample API-KEY- 3JzIfYb1GXh9cFlTB2do

↳ via GET method-

To get API-key you need to make a GET call to the following url with parameters userid, password-

https://api.cavyiot.com/device/get-apikey?userid={userid}&password={password}

 

Example Request-

 

var link = "https://api.cavyiot.com/device/get-apikey?userid=userid&password=password";
var request = new XMLHttpRequest();

request.open('GET', link);

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send();

  

↳ via POST method-

To get API-key you need to make a POST call to the following url with JSON parameters- userid, password-

https://api.cavyiot.com/device/get-apikey

 

Example Request-

 

var link = "https://api.cavyiot.com/device/get-apikey";
var request = new XMLHttpRequest();
var userid = "Your_userid";
var password = "Your_password";
var rbody= {
            "userid":userid,
            "password":password
            };
request.open('POST', link);

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send(JSON.stringify(rbody));

  

QUERY PARAMETERS

Field Type Description
userid String Your CavyIoT userid
password String Your CavyIoT password
 

Example Response- application/json🔗

 

{
    "code": 200,
    "detail": "success",
    "device_list": [
        {
            "device": "farm",
            "api_key": "3JzIfYb1GXN9cFlTB2do",
            "active_since": "2020-06-25",
            "service_expires": "2021-06-25"
        },
        {
            "device": "Demo",
            "api_key": "5tyIfYb1gu7dcFlTb48x",
            "active_since": "2020-06-30",
            "service_expires": "2020-07-30"
        },
        {
            "device": "Home",
            "api_key": "3JzIfYb1GXN9cFlTB2dL",
            "active_since": "2020-11-05",
            "service_expires": "2020-12-05"
        },
        {
            "device": "industry",
            "api_key": "3JzIfYb1GXN9cFlTB2dM",
            "active_since": "2020-11-15",
            "service_expires": "2020-11-22"
        }
    ]
}
  

Get current status of device

This section explains how to get the status data that's reported to CavyIoT Core by devices. You can monitor the status of each connected device and view diagnostic information to troubleshoot issues and determine the current status of a device. You can get current status of device by API call (GET or POST).

To get current status of device you need to make a GET or POST call to the following URL with parameter API key as path-

https://api.cavyiot.com/{api_key}/device/status

 

QUERY PARAMETERS

Field Type Description
api_key String Your device API key
 

Example Request-

 

var link = "https://api.cavyiot.com/3JzIfYb1GXN9cFlTB2do/device/status";
var request = new XMLHttpRequest();

request.open('GET', link);

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send();
  

Example Response- application/json

 

{
    "code": 200,
    "detail": "success",
    "device_status": {
        "timezone": "Asia\/Calcutta",
        "name": "farm",
        "active_since": "2020-06-25",
        "service_expires": "2021-06-25",
        "auto_mode": true,
        "sensors": [
            {
                "name": "temperature",
                "value": 50,
                "unit": "C",
                "lastupdate": {
                    "time": "21:23:26",
                    "date": "2020-12-03"
                }
            },
            {
                "name": "humidity",
                "value": "25",
                "unit": "RH",
                "lastupdate": {
                    "time": "21:23:26",
                    "date": "2020-12-03"
                }
            }
        ],
        "buttons": [
            {
                "index": "0",
                "lable": "LED1",
                "state": "ON",
                "lastupdate": {
                    "time": "21:23:26",
                    "date": "2020-12-03"
                }
            },
            {
                "index": "1",
                "lable": "LED2",
                "state": "OFF",
                "lastupdate": {
                    "time": "02:34:42",
                    "date": "2020-11-27"
                }
            },
            {
                "index": "2",
                "lable": "LED3",
                "state": "OFF",
                "lastupdate": {
                    "time": "02:34:47",
                    "date": "2020-11-27"
                }
            },
            {
                "index": "3",
                "lable": "LED4",
                "state": "ON",
                "lastupdate": {
                    "time": "02:33:25",
                    "date": "2020-11-27"
                }
            }
        ]
    }
}
  
 

Add Device

This endpoint creates a new Device to your IoT Dashboard.

↳ via GET method-

To add a single Device to your IoT Dashboard you need to make a GET call to the following URL with parameters userid, password, and device-

https://api.cavyiot.com/device/add?userid={userid}&password={password}&device={device_name}

 

Example Request-

 

var link = "https://api.cavyiot.com/device/add?userid=userid&password=password&device=device_name";
var request = new XMLHtpRequest();

request.open('GET', link);

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send();
  

↳ via POST method-

To add Multiple Devices to your IoT Dashboard you need to make a POST call to the following URL with JSON parameters- name, value, and unit-

https://api.cavyiot.com/{api_key}/sensor/add

 

Example Request-

 

var link = "https://api.cavyiot.com/device/add";
var request = new XMLHttpRequest();
var rbody= {
            "userid":"Your-userid",
            "password":"Your-password",
            "devices":["device_name1","device_name2"]
            };
request.open('POST', link);

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send(JSON.stringify(rbody));
  

QUERY PARAMETERS

Field Type Description
userid String Your CavyIoT userid
password String Your CavyIoT password
device String Name of Device to be added to your IoT Dashboard
 

Example Response- application/json

 

{
    "code": 200,
    "detail": "success",
    "added": [
        {
            "device": "device_name1",
            "api_key": "YBoMvLSdEIAqiQGFTh6p"
        },
        {
            "device": "device_name2",
            "api_key": "DUhJXjzbxlPc894SdTGB"
        }
    ]
}
  
 

Delete Device

This endpoint deletes a existing Device from your IoT Dashboard.

↳ via GET method-

To delete a single Device you need to make a GET call to the following URL with parameters userid, password, and device-

https://api.cavyiot.com/device/delete?userid={userid}&password={password}&device={device_name}

 

Example Request-

 

var link = "https://api.cavyiot.com/device/delete?userid=userid&password=password&device=device_name";
var request = new XMLHtpRequest();

request.open('GET', link);

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send();
  

↳ via POST method-

To delete Multiple Devices you need to make a POST call to the following URL with JSON parameters- name, value, and unit-

https://api.cavyiot.com/{api_key}/sensor/add

 

Example Request-

 

var link = "https://api.cavyiot.com/device/delete";
var request = new XMLHttpRequest();
var rbody= {
            "userid":"Your-userid",
            "password":"Your-password",
            "devices":["device_name1","device_name2"]
            };
request.open('POST', link);

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send(JSON.stringify(rbody));
  

QUERY PARAMETERS

Field Type Description
userid String Your CavyIoT userid
password String Your CavyIoT password
device String Name of Device to delete from your account
 

Example Response- application/json

 

{
    "code": 200,
    "detail": "success",
    "deleted": [
        "device_name1",
        "device_name2"
    ]
}
  
 

Add Sensor/s

This endpoint Creates a new sensor/s variable.

↳ via GET method-

To add a single sensor variable to your IoT Dashboard you need to make a GET call to the following URL with parameters name, value, and unit-

https://api.cavyiot.com/{api_key}/sensor/add?name={name}&value={value}&unit={unit}

 

Example Request-

 

var link = "https://api.cavyiot.com/3JzIfYb1GXN9cFlTB2do/sensor/add?name=name&value=value&unit=unit";
var request = new XMLHttpRequest();

request.open('GET', link);

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send();
  

↳ via POST method-

To add Multiple sensor variables to your IoT Dashboard you need to make a POST call to the following URL with JSON parameters- name, value, and unit-

https://api.cavyiot.com/{api_key}/sensor/add

 

Example Request-

 

var link = "https://api.cavyiot.com/3JzIfYb1GXN9cFlTB2do/sensor/add";
var request = new XMLHttpRequest();
var rbody= [{
            "name":"Temperature",
            "value":37,
            "unit":"C"
            },
            {
            "name":"Humidity",
            "value":42
            }];
request.open('POST', link);

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send(JSON.stringify(rbody));
  

QUERY PARAMETERS

Field Type Description
api_key String Your device API key
name String Your sensor Name
value (Optional) Integer Your sensor Value
unit (Optional) String Your sensor Unit
 

Example Response- application/json

 

{
    "code": 200,
    "detail": "success.",
    "added": [
        "Temperature",
        "Humidity"
    ]
}
  
 

Update Sensor/s

This endpoint Updates value of a existing sensor/s variable.

↳ via GET method-

To update a single sensor variable to your IoT Dashboard you need to make a GET call to the following URL with parameters name, value, and unit-

https://api.cavyiot.com/{api_key}/sensor/update?name={name}&value={value}&unit={unit}

 

Example Request-

 

var link = "https://api.cavyiot.com/3JzIfYb1GXN9cFlTB2do/sensor/update?name=name&value=value&unit=unit";
var request = new XMLHttpRequest();

request.open('GET', link);

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send();
  

↳ via POST method-

To update Multiple sensor variables to your IoT Dashboard you need to make a POST call to the following URL with JSON parameters- name, value, and unit-

https://api.cavyiot.com/{api_key}/sensor/update

 

Example Request-

 

var link = "https://api.cavyiot.com/3JzIfYb1GXN9cFlTB2do/sensor/update";
var request = new XMLHttpRequest();
var rbody= [{
            "name":"Temperature",
            "value":37,
            "unit":"C"
            },
            {
            "name":"Humidity",
            "value":42
            }];
request.open('POST', link);

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send(JSON.stringify(rbody));
  

QUERY PARAMETERS

Field Type Description
api_key String Your device API key
name String Your sensor Name
value Integer/Float Your sensor Value
unit (Optional) String Your sensor Unit
 

Example Response- application/json

 

{
    "code": 200,
    "detail": "success.",
    "updated": [
        {
            "name": "Humidity",
            "value": 45,
            "unit": "C",
            "unix_time": 1607460649
        },
        {
            "name": "Temperature",
            "value": 32.5,
            "unit": "C",
            "unix_time": 1607460649
        }
    ]
}
  
 

Delete Sensor/s

This endpoint Deletes a existing sensor/s variable.

↳ via GET method-

To delete a single sensor variable from your IoT Dashboard you need to make a GET call to the following URL with parameters sensor name with api_key as path as parameter-

https://api.cavyiot.com/{api_key}/sensor/delete?name={name}

 

Example Request-

 

var link = "https://api.cavyiot.com/3JzIfYb1GXN9cFlTB2do/sensor/delete?name=sensor_name";
var request = new XMLHttpRequest();

request.open('GET', link);

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send();
  

↳ via POST method-

To delete Multiple sensor variables from your IoT Dashboard you need to make a POST call to the following URL with JSON parameters- name-

https://api.cavyiot.com/{api_key}/sensor/delete

 

Example Request-

 

var link = "https://api.cavyiot.com/3JzIfYb1GXN9cFlTB2do/sensor/delete";
var request = new XMLHttpRequest();
var sensor_name1 = "Temperature";
var sensor_name2 = "Humidity";
var rbody= [{
            "name":sensor_name1
            },
            {
            "name":sensor_name2
            }];
request.open('POST', link);

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send(JSON.stringify(rbody));
  

QUERY PARAMETERS

Field Type Description
api_key String Your device API key
name String Your sensor Name

Example Response- application/json

 


{
    "code": 200,
    "detail": "success",
    "deleted": [
        "speed"
    ]
}
  
 

Chart Feed Data

This endpoint Feeds a data-points into a Chart.

↳ via GET method-

To update a single data-point to a chart you need to make a GET call to the following URL with parameters api_key, name, and value-

https://api.cavyiot.com/{api_key}/chart/feed?name={name}&value={value}

 

QUERY PARAMETERS

Field Type Description
api_key String Your device API key
name String Sensor name
value Integer/Float Sensor Value
 

Example Request-

 

//Note:- Use this call only if you want a chart for a single sensor variable
// This endpoint creates a Chart Base only for one sensor variable.

var api_key = "3JzIfYb1GXN9cFlTB2do";
var link = "https://api.cavyiot.com/"+api_key+"/chart/feed?name=Temperature&value=34";
var request = new XMLHttpRequest();

request.open('GET', link);

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send();
  

↳ via POST method-

To update a chart with more than one sensor variable you need to make a POST call to the following URL with JSON body with parameters- Array of name, and value-

https://api.cavyiot.com/{api_key}/chart/feed

 
 

QUERY PARAMETERS

Field Type Description
api_key String Your device API key
name String Sensor name
value Integer/Float Sensor Value
 

Example Request-

 

var api_key = "3JzIfYb1GXN9cFlTB2do";
var link = "https://api.cavyiot.com/api_key/chart/feed";
var request = new XMLHttpRequest();
var rbody= [{
            "name":"Temperature",
            "value":32
            },
            {
            "name":"Humidity",
            "value":40
            }];
request.open('POST', link);

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send(JSON.stringify(rbody));
  

Example Response- application/json

 

{
    "code": 200,
    "detail": "success",
    "base": [
            "Temperature",
            "Humidity"
            ]
}
  
 

Get Button Status

This endpoint fetches a current position/status of button/s.

↳ via GET method-

To get a position of a single button you need to make a GET call to the following URL with parameters api_key, and index-

https://api.cavyiot.com/{api_key}/button/status/{index}

 

QUERY PARAMETERS

Field Type Description
api_key String Your device API key
index Integer Must be between 0-3
 

Example Request-

 

var api_key = "3JzIfYb1GXN9cFlTB2do";
var link = "https://api.cavyiot.com/"+api_key+"/button/status/2";
var request = new XMLHttpRequest();

request.open('GET', link);

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send();
  

↳ via POST method-

To get position of more than one buttons you need to make a POST call to the following URL with JSON body with parameters- Array of index-

https://api.cavyiot.com/{api_key}/button/status

 
 

QUERY PARAMETERS

Field Type Description
api_key String Your device API key
index Array Array of button indexes (must be 0-3)
 

Example Request-

 

var api_key = "3JzIfYb1GXN9cFlTB2do";
var link = "https://api.cavyiot.com/api_key/button/status";
var request = new XMLHttpRequest();
var rbody= {
            "index":[0,1,2]
            };
request.open('POST', link);

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send(JSON.stringify(rbody));
  

Example Response- application/json

 

{
    "code": 200,
    "detail": "success",
    "buttons": [
        {
            "index": "0",
            "label": "Fan",
            "state": "ON",
            "lastupdate": {
                "time": "00:08:37",
                "date": "2020-12-10"
            }
        },
        {
            "index": "1",
            "label": "LED2",
            "state": "ON",
            "lastupdate": {
                "time": "22:44:31",
                "date": "2020-12-10"
            }
        },
        {
            "index": "2",
            "label": "LED3",
            "state": "OFF",
            "lastupdate": {
                "time": "02:34:47",
                "date": "2020-11-27"
            }
        }
    ]
}
  
 

Update Button

This endpoint Updates a current position/status of button/s.

↳ via GET method-

To update a position of a single button you need to make a GET call to the following URL with parameters api_key, index, and state-

https://api.cavyiot.com/{api_key}/button/update?index={index}&state={state}&label={label}

 

QUERY PARAMETERS

Field Type Description
api_key String Your device API key
index Integer Must be between 0-3
state String Must be ON or OFF
label (Optional) String Set button label (Should not contain SPACE character)
 

Example Request-

 

var api_key = "3JzIfYb1GXN9cFlTB2do";
var link = "https://api.cavyiot.com/"+api_key+"/button/update?index=2&state=ON&label=LED1";   //Note:- label is optional
var request = new XMLHttpRequest();

request.open('GET', link);

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send();
  

↳ via POST method-

To update position of more than one buttons you need to make a POST call to the following URL with JSON body with parameters- Array of index, and state-

https://api.cavyiot.com/{api_key}/button/update

 
 

QUERY PARAMETERS

Field Type Description
api_key String Your device API key
index Integer Button index
state String Button state (Must be ON or OFF)
label (Optional) String Button label (Should not contain SPACE character)
 

Example Request-

 

var api_key = "3JzIfYb1GXN9cFlTB2do";
var link = "https://api.cavyiot.com/api_key/button/update";
var request = new XMLHttpRequest();
var rbody= [{
            "index":1,
            "state":"ON"
            },
            {
            "index":2,
            "state":"OFF",
            "label":"BULB"
            }];
request.open('POST', link);

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send(JSON.stringify(rbody));
  

Example Response- application/json

 

{
    "code": 200,
    "detail": "success",
    "updated": [
        {
            "index": "1",
            "state": "OFF",
            "unix_time": 1607784578
        },
        {
            "index": "2",
            "state": "ON",
            "unix_time": 1607784578
        }
    ]
}
  

{
    "code": 207,
    "detail": "Partial success",
    "updated": [
        {
            "index": "2",
            "state": "OFF",
            "unix_time": 1607784779
        }
    ],
    "discarded": [
        {
            "index": "1",
            "state": "OFF"
        }
    ]
}
  

{
    "code": 208,
    "detail": "Already reported",
    "discarded": [
        {
            "index": "1",
            "state": "ON"
        },
        {
            "index": "2",
            "state": "OFF"
        }
    ]
}
  
 

Response Schema-

Field Type Description
code Integer Response status code
detail String Response status description
device_list Array Array of devices in your account. Contains information of device such as- (JSON object)
  • device name (String)
  • api_key (String)
  • active_since (String)
  • service_expires (String)
device_status JSON object JSON object of specific device. Contains information of device such as-
  • timezone (String)
  • name (String)
  • active_since (String)
  • service_expires (String)
  • auto_mode (boolean)
  • sensors (Array JSON object of sensors connected to device) contains information-
    • name (String)
    • value (Integer)
    • unit (String)
    • time (String)
    • date (String)
added Array When the record is added in database. Response parameters depends on API call-
  1. Add Device (JSON object)
    • device name (String)
    • api_key (String)
  2. Add Sensor- (List of Added sensors into IoT Dashboard)
discarded Array When the record is added in database. Response parameters depends on API call-
  1. Add Device 207 (JSON object)
    • device name (String)
    • api_key (String)

  2. Add Device 208 (List of Device name/s)

  3. Add Sensor- (List of Added sensors into IoT Dashboard)

  4. Update Button (JSON object)
    • index (String)
    • state (String)
deleted Array When the record or variable is deleted from database.-
  1. Delete Device (List of Deleted device/s)

  2. Add Device (List of Deleted sensor/s)

updated Array When the record is added in database. Response parameters depends on API call-
  1. Update Sensor/s (JSON object)
    • name (String)
    • value (Integer)
    • unit (String)
    • unix_time (Integer)

  2. Update Button/s (JSON object)
    • index (String)
    • state (String)
    • unix_time (Integer)

notfound Array When you try to UPDATE or DELETE an entity which does not exist, then server returns this (notfound) response as array of entity or entities(sensor name/device name).
base Array List of sensor names present in your chart data.
buttons Array JSON object of buttons with information of
  • index (String)
  • label (String)
  • state (String)
  • lastupdate (JSON object)-
    • time (String)
    • date (String)
sensors Array JSON object of sensors with information of
  • name (String)
  • value (Integer)
  • unit (String)
  • lastupdate (JSON object)-
    • time (String)
    • date (String)

Response Codes-

The CavyIoT RESTful API uses the following response codes:

Code Meaning Description
200 Success. This response code indicates that the request has succeeded.
207 Partially success. This response code indicates that when you try to UPDATE, DELETE, or ADD multiple entities, and the server could not find or discarded any of them entity.
208 Already reported. This response code indicates that you are trying to overwrite an entity.
401 Incorrect authentication credentials. This response code indicates that the request has not been applied because it lacks valid authentication credentials such as api_key or userid & password for the target resource.
404 Not found. This response code indicates that the resource you are trying to UPDATE or DELETE is not available on server.
406 Not Acceptable. This response code indicates that the server could not accept your request.
410 Service expired. Resource not available. This response code indicates that service for your device has been expired.
415 Syntax error. This response code indicates that the request body is not valid i.e. syntax error.