REST API
Device
Create device

Create Device

POST /v2/projects/{PROJECT_ID}/devices

Create a new device by sending a POST request to the Qubitro API. The device will be associated with the specified project ID.

device.ts
import type { NextApiRequest, NextApiResponse } from 'next';
 
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
    const projectId = "string";
    const apiKey = "<API_KEY>";
    const requestBody = {
        name: "string",
        description: "string",
        source: "string",
        tags: ["string"],
        brand: "string",
        model: "string"
    };
 
    try {
        const result = await fetch(`https://api.qubitro.com/v2/projects/${projectId}/devices`, {
            headers: {
                "Content-Type": "application/json",
                "Authorization": `Bearer ${apiKey}`
            },
            method: "POST",
            body: JSON.stringify(requestBody)
        });
 
        const data = await result.json();
        res.status(200).json(data);
    } catch (error) {
        console.error(`Error: ${error}`);
        res.status(500).json({ message: 'Internal server error' });
    }
}
OptionTypeDescription
project_id`String`The ID of the project to which the device will be added.
name`String`The name of the device.
description`String`A brief description of the device.
source`String`The source of the device, only 'http' or 'mqtt'.
tags`Array[String]`Tags associated with the device. An empty array is acceptable.
brand`String`The brand of the device. Default is 'Custom' if omitted.
model`String`The model of the device. Default is 'Custom' if omitted.

Response

On success, the API will return a JSON object with the following structure:

{
    "success": true,
    "action": "create device",
    "status": 201,
    "message": "Device created successfully.",
    "data": {
        "id": "string",
        "name": "string",
        "description": "string",
        "brand": "string",
        "model": "string",
        "avatar": "https://static.qubitro.com/portal/device/avatar/default.png",
        "last_seen": "0001-01-01T00:00:00Z",
        "tags": ["string"],
        "metadata": {
            "device_id": "string",
            "device_token": "string"
        }
    }
}
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