REST API
Device Data

Data Operations

The SDK provides several methods to interact with device data.

Fetch All Device Data

This method is used to fetch all the available data from a specified device.

Parameters:

OptionTypeDescription
projectIDStringThe unique identifier of the project.
deviceIDStringThe unique identifier of the device.
pageNumberPage number for data pagination.
limitNumberNumber of data entries per page.

Using async await syntax:

import { getData } from '@qubitro/client'
 
const projectID = "yourProjectId";
const deviceID = "yourDeviceId";
const page = 1;
const limit = 10;
 
// Using async/await
async function fetchData() {
    const data = await getData(projectID, deviceID, page, limit);
    console.log(data);
}

or promises:

import { getData } from '@qubitro/client'
 
const projectID = "yourProjectId";
const deviceID = "yourDeviceId";
const page = 1;
const limit = 10;
 
// Using Promises
getData(projectID, deviceID, page, limit)
    .then(data => console.log(data))
    .catch(error => console.log(error));

Example Response

[
    {
        "timestamp": "2023-07-01T00:00:00Z",
        "temperature": 24.5,
        "humidity": 60
    },
    {
        "timestamp": "2023-07-01T01:00:00Z",
        "temperature": 24.6,
        "humidity": 59
    }
]

Fetch Device Data by Keys

This method fetches device data using an array of keys.

Parameters:

OptionTypeDescription
projectIDStringThe unique identifier of the project.
deviceIDStringThe unique identifier of the device.
pageNumberPage number for data pagination.
limitNumberNumber of data entries per page.
keysArray<String>Array of data keys to fetch.

Using async await syntax:

import { getDataByKeys } from '@qubitro/client'
 
const projectID = "yourProjectId";
const deviceID = "yourDeviceId";
const page = 1;
const limit = 10;
const keys = ["temperature"];
 
// Using async/await
async function fetchData() {
    const data = await getDataByKeys(projectID, deviceID, page, limit, keys);
    console.log(data);
}

or promises:

import { getDataByKeys } from '@qubitro/client'
 
const projectID = "yourProjectId";
const deviceID = "yourDeviceId";
const page = 1;
const limit = 10;
const keys = ["temperature"];
 
// Using Promises
getDataByKeys(projectID, deviceID, page, limit, keys)
    .then(data => console.log(data))
    .catch(error => console.log(error));

Example Response

[
    {
        "timestamp": "2023-07-01T00:00:00Z",
        "temperature": 24.5
    },
    {
        "timestamp": "2023-07-01T01:00:00Z",
        "temperature": 24.6
    }
]

Fetch Device Data by Time Range

This method fetches device data for a specific time range.

Parameters:

OptionTypeDescription
projectIDStringThe unique identifier of the project.
deviceIDStringThe unique identifier of the device.
pageNumberPage number for data pagination.
limitNumberNumber of data entries per page.
startDateStart date of the time range.
endDateEnd date of the time range.

Using async await syntax:

import { getDataByTime } from '@qubitro/client'
 
const projectID = "yourProjectId";
const deviceID = "yourDeviceId";
const page = 1;
const limit = 10;
const start = new Date("2023-06-01T00:00:00Z");
const end = new Date("2023-07-01T01:00:00Z");
 
// Using async/await
async function fetchData() {
    const data = await getDataByTime(projectID, deviceID, page, limit, start, end);
    console.log(data);
}

or promises:

import { getDataByTime } from '@qubitro/client'
 
const projectID = "yourProjectId";
const deviceID = "yourDeviceId";
const page = 1;
const limit = 10;
const start = new Date("2023-06-01T00:00:00Z");
const end = new Date("2023-07-01T01:00:00Z");
 
// Using Promises
getDataByTime(projectID, deviceID, page, limit, start, end)
    .then(data => console.log(data))
    .catch(error => console.log(error));

Example Response

[
    {
        "timestamp": "2023-06-01T00:00:00Z",
        "temperature": 24.5,
        "humidity": 60
    },
    {
        "timestamp": "2023-07-01T01:00:00Z",
        "temperature": 24.6,
        "humidity": 59
    }
]

Fetch Device Data by Time Range and Keys

This method fetches device data for a specific time range using an array of keys.

Parameters:

OptionTypeDescription
projectIDStringThe unique identifier of the project.
deviceIDStringThe unique identifier of the device.
pageNumberPage number for data pagination.
limitNumberNumber of data entries per page.
startDateStart date of the time range.
endDateEnd date of the time range.
keysArray<String>Array of data keys to fetch.

Using async await syntax:

import { getDataByTimeAndKeys } from '@qubitro/client'
 
const projectID = "yourProjectId";
const deviceID = "yourDeviceId";
const page = 1;
const limit = 10;
const start = new Date("2023-07-01T00:00:00Z");
const end = new Date("2023-07-01T01:00:00Z");
const keys = ["temperature"];
 
// Using async/await
async function fetchData() {
    const data = await getDataByTimeAndKeys(projectID, deviceID, page, limit, start, end, keys);
    console.log(data);
}

or promises:

import { getDataByTimeAndKeys } from '@qubitro/client'
 
const projectID = "yourProjectId";
const deviceID = "yourDeviceId";
const page = 1;
const limit = 10;
const start = new Date("2023-07-01T00:00:00Z");
const end = new Date("2023-07-01T01:00:00Z");
const keys = ["temperature"];
 
// Using Promises
getDataByTimeAndKeys(projectID, deviceID, page, limit, start, end, keys)
    .then(data => console.log(data))
    .catch(error => console.log(error));

Example Response

[
    {
        "timestamp": "2023-07-01T00:00:00Z",
        "temperature": 24.5
    },
    {
        "timestamp": "2023-07-01T01:00:00Z",
        "temperature": 24.6
    }
]

Fetch All Available Data Keys

This method fetches all available data keys for a specified device.

Parameters:

OptionTypeDescription
projectIDStringThe unique identifier of the project.
deviceIDStringThe unique identifier of the device.

Using async await syntax:

import { getDataKeys } from '@qubitro/client'
 
const projectID = "yourProjectId";
const deviceID = "yourDeviceId";
 
// Using async/await
async function fetchData() {
    const data = await getDataKeys(projectID, deviceID);
    console.log(data);
}

or promises:

import { getDataKeys } from '@qubitro/client'
 
const projectID = "yourProjectId";
const deviceID = "yourDeviceId";
 
// Using Promises
getDataKeys(projectID, deviceID)
    .then(data => console.log(data))
    .catch(error => console.log(error));

Example Response

[
    "temperature",
    "humidity"
]

Delete All Device Data

This method deletes all data from a specified device.

Parameters:

OptionTypeDescription
projectIDStringThe unique identifier of the project.
deviceIDStringThe unique identifier of the device.

Using async await syntax:

import { deleteDataByDeviceId } from '@qubitro/client'
 
const projectID = "yourProjectId";
const deviceID = "yourDeviceId";
 
// Using async/await
async function deleteData() {
    const response = await deleteDataByDeviceId(projectID, deviceID);
    console.log(response);
}

or promises:

import { deleteDataByDeviceId } from '@qubitro/client'
 
const projectID = "yourProjectId";
const deviceID = "yourDeviceId";
 
// Using Promises
deleteDataByDeviceId(projectID, deviceID)
    .then(response => console.log(response))
    .catch(error => console.log(error));

Example Response

{
    "message": "Data has been successfully deleted."
}

Ready to accelerate>>> INNOVATIONat your organization?

We’d love to talk about how we can work together.
Qubitro Logo

Product

Resources

Industries

Decision Aids

Solutions

Company

© 2024 Qubitro, Inc. All rights reserved