API

Access Ubidots Javascript SDK from the HTML canvas

Javascript SDK

The HTML Canvas' built-in library exposes Ubidots' Javascript SDK through ubidots.api. This simplifies interacting with Ubidots API when developing in the HTML Canvas, hence avoiding making request by hand, or writing wrappers to generalize request making.

To access the SDK methods, follow the below syntax:

ubidots.api.<JS_SDK_METHODS>

Refer to the Javascript SDK Docs to learn more about its supported entities, methods and filtering capabilities.

Usage

Dashboard data preloaded:

// Get token from Ubidots built-in library
const TOKEN = ubidots.token;

// Authenticate the SDK with the token
ubidots.api.authenticate(TOKEN);

// Get first 100 devices from the account
ubidots.api.devices.get().then((devices) => {
    // Prints an array of Device objects
    console.log(devices);
    
    // YOUR LOGIC OVER THESE 100 DEVICES
});

NO dashboard data preloaded:

var ubidots = new Ubidots();

const TOKEN = undefined;

ubidots.on("ready", async () => {
    TOKEN = ubidots.token;
    
    // Authenticate the SDK with the token
    ubidots.api.authenticate(TOKEN);
    
    // Get first 100 devices from the account
    var devices = await ubidots.api.devices.get();
    
    // Prints an array of Device objects
    console.log(devices);
    
    // YOUR LOGIC OVER THESE 100 DEVICES
});

Last updated