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.
API URL
API access can be over HTTP or secure HTTP, HTTPs, using the following endpoint- https://api.cavyiot.com
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-
↳ via GET
method-
To get API-key you need to make a GET
call to the following url with parameters
https://api.cavyiot.com/device/get-apikey?userid=
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-
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 |
password | String | Your CavyIoT |
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
https://api.cavyiot.com/
QUERY PARAMETERS
Field | Type | Description |
---|---|---|
api_key | String | Your device |
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
↳ 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
https://api.cavyiot.com/device/add?userid=
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-
https://api.cavyiot.com/
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 |
password | String | Your CavyIoT |
device | String | Name of |
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
↳ via GET
method-
To delete a single Device you need to make a GET
call to the following URL with parameters
https://api.cavyiot.com/device/delete?userid=
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-
https://api.cavyiot.com/
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 |
password | String | Your CavyIoT |
device | String | Name of |
Example Response- application/json
{
"code": 200,
"detail": "success",
"deleted": [
"device_name1",
"device_name2"
]
}
Add Sensor/s
This endpoint
↳ 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
https://api.cavyiot.com/
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-
https://api.cavyiot.com/
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 |
name | String | Your sensor |
value (Optional) | Integer | Your sensor |
unit (Optional) | String | Your sensor |
Example Response- application/json
{
"code": 200,
"detail": "success.",
"added": [
"Temperature",
"Humidity"
]
}
Update Sensor/s
This endpoint
↳ 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
https://api.cavyiot.com/
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-
https://api.cavyiot.com/
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 |
name | String | Your sensor |
value | Integer/Float | Your sensor |
unit (Optional) | String | Your sensor |
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
↳ 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
https://api.cavyiot.com/
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-
https://api.cavyiot.com/
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 |
name | String | Your sensor |
Example Response- application/json
{
"code": 200,
"detail": "success",
"deleted": [
"speed"
]
}
Chart Feed Data
This endpoint Feeds a data-points into a
↳ 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
https://api.cavyiot.com/
QUERY PARAMETERS
Field | Type | Description |
---|---|---|
api_key | String | Your device |
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
https://api.cavyiot.com/
QUERY PARAMETERS
Field | Type | Description |
---|---|---|
api_key | String | Your device |
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
QUERY PARAMETERS
Field | Type | Description |
---|---|---|
api_key | String | Your device |
index | Integer | Must be between |
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();
QUERY PARAMETERS
Field | Type | Description |
---|---|---|
api_key | String | Your device |
index | Array | Array of button |
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
QUERY PARAMETERS
Field | Type | Description |
---|---|---|
api_key | String | Your device |
index | Integer | Must be between |
state | String | Must be |
label (Optional) | String | Set button label (Should not contain |
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();
QUERY PARAMETERS
Field | Type | Description |
---|---|---|
api_key | String | Your device |
index | Integer | Button |
state | String | Button |
label (Optional) | String | Button |
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_status | JSON object | JSON object of specific device. Contains information of device such as-
|
added | Array | When the record is added in database. Response parameters depends on API call-
|
discarded | Array | When the record is added in database. Response parameters depends on API call-
|
deleted | Array | When the record or variable is deleted from database.-
|
updated | Array | When the record is added in database. Response parameters depends on API call-
|
notfound | Array | When you try to UPDATE or DELETE an entity which does not exist, then server returns this ( |
base | Array | List of sensor names present in your chart data. |
buttons | Array | JSON object of buttons with information of
|
sensors | Array | JSON object of sensors with information of
|
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
or 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. |