Device Operations
The SDK provides several methods to interact with devices.
Device Object
When working with device-related methods, you'll be using the Device object which has the following properties:
Option | Type | Description |
---|---|---|
id | String | The unique identifier of the device. |
name | String | The name of the device. |
description | String | The description of the device. |
brand | String | The brand of the device. |
model | String | The model of the device. |
avatar | String | The avatar of the device. |
lastSeen | Date | The timestamp when the device was last seen. |
projectId | String | The unique identifier of the project that the device belongs to. |
Get All Devices
Retrieves a list of all devices in a specific project. The method returns an array of Device objects.
Parameters:
Option | Type | Description |
---|---|---|
projectID | String | The unique identifier of the project. |
Using async await syntax:
import { getDevices } from '@qubitro/client';
const projectId = 'your-project-id';
async function fetchDevices() {
try {
const devices = await getDevices(projectId);
devices.forEach(device => {
console.log(`Device ID: ${device.id}`);
// Log other device details...
});
} catch (err) {
console.error(`Error ${err.status}: ${err.message}`);
}
}
fetchDevices();
or promises:
import { getDevices } from '@qubitro/client';
const projectId = 'your-project-id';
getDevices(projectId)
.then(devices => {
devices.forEach(device => {
console.log(`Device ID: ${device.id}`);
// Log other device details...
});
})
.catch(err => {
console.error(`Error ${err.status}: ${err.message}`);
});
Example Response
[
{
"id": "device1",
"name": "My First Device",
"description": "This is my first device.",
"brand": "Device Brand",
"model": "Device Model",
"avatar": "Device Avatar URL",
"lastSeen": "2023-01-01T00:00:00Z",
"projectId": "project1"
},
// ...additional devices
]
Get Device by ID
Retrieves a specific device by its ID. The method returns a Device object.
Parameters:
Option | Type | Description |
---|---|---|
projectID | String | The unique identifier of the project. |
deviceID | String | The unique identifier of the device. |
Using async await syntax:
import { getDeviceById } from '@qubitro/client';
const projectId = 'your-project-id';
const deviceId = 'your-device-id';
async function fetchDevice() {
try {
const device = await getDeviceById(projectId, deviceId);
console.log(`Device ID: ${device.id}`);
// Log other device details...
} catch (err) {
console.error(`Error ${err.status}: ${err.message}`);
}
}
fetchDevice();
or promises:
import { getDeviceById } from '@qubitro/client';
const projectId = 'your-project-id';
const deviceId = 'your-device-id';
// Using Promises
getDeviceById(projectId, deviceId)
.then(device => {
console.log(`Device ID: ${device.id}`);
// Log other device details...
})
.catch(err => {
console.error(`Error ${err.status}: ${err.message}`);
});
Start building today
Collect, process, and activate device data. Scale from one device to thousands.