How to use UJL

Get devices

Get all devices in the account

const allDevices = await Ubidots.devices.all();

Get the first device in the account

const firstDevice = await Ubidots.devices.first();
// This is equivalent to
const firstDevice = (await Ubidots.devices.all())[0];

Get the first 1000 devices in the account

const devicesPaginated = (await Ubidots.devices.paginate(1, 1000)).results

Get lastActivity field from devices

 const allDevicesLastActivity = await Ubidots.devices.addRawParam('fields', 'lastActivity').get();

Get lastActivity and variablesCount fields from devices

const device = await Ubidots.devices.addRawParams(
      fields: 'lastActivity,variablesCount'

Get lastActivity and variablesCount fields from a specific device using its label

const device = await Ubidots.devices.addRawParams(
      label: 'temperature_sensor',
      fields: 'lastActivity,variablesCount'

Get a device by label or id

// By label
const temperatureDevice = await Ubidots.devices.where('label').is('temperature_device_1').first();

// By id
const temperatureDevice = await Ubidots.devices.where('id').is('some-id').first();

Get a set of devices based on their type

const devicesByType = await Ubidots.devices.where('deviceType').exact('temperature-devices').get();

Get variables

Get all variables in the account

const allVariables = await Ubidots.variables.all();

Get the first variable in the account:

const firstVariable = await Ubidots.variables.first();
// This is equivalent to
const firstVariable = (await Ubidots.variables.all())[0];

Get the first 100 variables in the account:

const variablesPaginated = (await Ubidots.variables.paginate(1, 100)).results;
// Equivalent to
const variablesPaginated = (await Ubidots.variables.paginate()).results;

Get lastActivity field from variables

const allVariablesLastActivity = await Ubidots.variables.addRawParam('fields', 'lastActivity').get();

Get lastActivity and label fields from all variables

const variables = await Ubidots.variables.addRawParams(
    fields: 'lastActivity,label'

Get lastActivity and label fields from a specific variable

const variables = await Ubidots.variables.addRawParams(
    id: '6452a727df1a8e000c103fce',
    fields: 'lastActivity,label'

Get a variable by id:

const variableById = await Ubidots.variables.where('id').exact('6595770b9de79b000dce0eae').first();

Get a set of variables based on their label:

const variablesByLabel = await Ubidots.variables.where('label').exact('temperature').get();

Send data

First, you need to get the device object and then, the variables to which you want to send the data:

// Get the device object
const temperatureDevice = await Ubidots.devices.where('label').exact('temperature_device_1').first();
// Get the variable object
const temperatureVariable = await temperatureDevice.variables.where('label').exact('temperature').first();
  • Send a value

  • Send a value with timestamp

    temperatureVariable.sendDot(40, new Date().getTime());
  • Send a value with timestamp and context

    temperatureVariable.sendDot(4, new Date().getTime(), { status: 'cold' });

Last updated