REST API
Device Data
Fetch Device Data

Fetch Device Data

GET /v2/projects/{PROJECT_ID}/devices/{DEVICE_ID}/data

Retrieve the data of a specific device within a specific project, with optional pagination and time range filters.

This endpoint has two flexible options based on the range parameter. Check query parameters for all available options.

Range Selection: 'all'
device_data.ts
import { NextApiRequest, NextApiResponse } from 'next';
import fetch from 'node-fetch';
 
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
const projectId = "your_project_id";
const deviceId = "your_device_id";
const apiKey = "your_api_key";
 
const page = 1;
const limit = 25;
const keys = "key1,key2,key3";
const range = "all";
 
try {
const response = await fetch(`https://api.qubitro.com/v2/projects/${projectId}/devices/${deviceId}/data?page=${page}&limit=${limit}&range=${range}&keys=${keys}`, {
  headers: {
    "Authorization": `Bearer ${apiKey}`
  }
});
 
const data = await response.json();
res.status(200).json(data);
} catch (error) {
console.error(error);
res.status(500).json({ error: "An error occurred while retrieving device data." });
}
}
 
Range Selection: 'time'
device_data.ts
import { NextApiRequest, NextApiResponse } from 'next';
import fetch from 'node-fetch';
 
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
const projectId = "your_project_id";
const deviceId = "your_device_id";
const apiKey = "your_api_key";
 
const page = 1;
const limit = 25;
const keys = "key1,key2,key3";
const range = "time";
const start = "2023-06-01T00:00:00Z"; // Specify the desired start time
const end = "2023-06-30T23:59:59Z";   // Specify the desired end time
 
try {
const response = await fetch(`https://api.qubitro.com/v2/projects/${projectId}/devices/${deviceId}/data?page=${page}&limit=${limit}&range=${range}&start=${start}&end=${end}&keys=${keys}`, {
  headers: {
    "Authorization": `Bearer ${apiKey}`
  }
});
 
const data = await response.json();
res.status(200).json(data);
} catch (error) {
console.error(error);
res.status(500).json({ error: "An error occurred while retrieving device data." });
}
}
Path Parameters
OptionTypeDescription
PROJECT_ID`String`The ID of the project.
DEVICE_ID`String`The ID of the device.
Query Parameters
OptionTypeDescription
page`Number`REQUIRED: Page number for data pagination. All data fetch operations are paginated.
limit`Number`REQUIRED: Limit per page for the number of data entries.
range`String`REQUIRED: Range type. Value can only be "all" or "time".
start`Date`REQUIRED if "range" is "time": Start time of the data range.
end`Date`REQUIRED if "range" is "time": End time of the data range.
keys`String`NOT REQUIRED: List of Device Data Keys separated by ",". Omitting keys will fetch all available keys.
Response
{
    "success": true,
    "action": "retrieve data",
    "status": 200,
    "message": "Data retrieved successfully.",
    "data": [
        {
            "key1": 12.3456,
            "key2": "SomeData1",
            "key3": 23.4567,
            "timestamp": "2023-06-23T15:43:45.994249Z"
        },
        {
            "key1": 34.5678,
            "key2": "SomeData2",
            "key3": 45.6789,
            "timestamp": "2023-06-23T15:41:43.895835Z"
        },
        {
            "key1": 56.7890,
            "key2": "SomeData3",
            "key3": 67.8901,
            "timestamp": "2023-06-23T15:39:40.630993Z"
        }
    ]
}
Response codes
OptionTypeDescription
200OKThe request was successful.
400Bad RequestThe request could not be understood or was missing required parameters.
401UnauthorizedAuthentication failed or was not provided.
403ForbiddenAuthentication succeeded, but the authenticated user does not have access to the requested resource.
404Not FoundThe requested resource could not be found.
500Internal Server ErrorAn error occurred on the server.

logo

Start building today

Collect, process, and activate device data. Scale from one device to thousands.

Qubitro Logo

Product

Resources

Industries

Decision Aids

Solutions

Company

© 2024 Qubitro, Inc. All rights reserved