REST API
Device

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:

OptionTypeDescription
idStringThe unique identifier of the device.
nameStringThe name of the device.
descriptionStringThe description of the device.
brandStringThe brand of the device.
modelStringThe model of the device.
avatarStringThe avatar of the device.
lastSeenDateThe timestamp when the device was last seen.
projectIdStringThe 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:

OptionTypeDescription
projectIDStringThe 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:

OptionTypeDescription
projectIDStringThe unique identifier of the project.
deviceIDStringThe 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}`);
    });

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