Ubidots Developer Guides
Help CenterAPI ReferenceData APICommunity
  • Welcome to our Dev Guides
  • ⚡️ Getting Started
    • What is Ubidots?
    • Devices, Variables, and Dots
    • Technical FAQs
    • Business FAQs
  • 🧩Integration Guides
    • Industrial IoT
      • Advantech
      • Amplified Engineering
      • AWS
      • Azimut
      • Balena
      • Bivocom
      • CESVA
      • Controllino
      • Digital Communications Technologies (DCT)
      • Everactive
      • Golioth
      • Kepware
      • Kunbus
      • Monnit
      • MultiTech
      • NCD.io
      • Node-RED
      • Omicron IoT
      • Red Lion
      • Robustel
      • Senquip
      • Sielco
      • Siemens
      • Strega
      • vNode
      • WAGO
      • Weintek
      • YuDash
    • Cellular
      • Blues Wireless
      • Digi International
      • Hologram
      • Monogoto
      • Particle
      • Quectel
      • Soracom
    • LoRaWAN
      • AonChip
      • Chirpstack
      • Decentlab
      • Helium
      • ioThings
      • LORIOT
      • Milesight
      • MOKOSmart
      • RAKwireless
      • Sagemcom
      • Seeed Studio
      • Senet
      • The Things Industries
        • The Things Stack
        • The Things Network
    • Sigfox
      • Digital Matter
      • McThings
      • Sigfox
      • Suntech
      • Thinxtra
      • UnaBiz
    • Satellite
      • Swarm
    • Dev Kits
      • Adafruit
      • Advantech
      • AloriumTech
      • Arduino
      • Blues Wireless
      • DFRobot
      • Dragino
      • Electric Imp
      • Espressif Systems
      • McThings
      • Microchip Technology
      • Onion
      • Particle
      • Pycom
      • RAKwireless
      • Raspberry Pi
      • Seeed Studio
      • Sodaq
      • STMicroelectronics
      • Texas Instruments
      • Thinxtra
      • Verse Technology
    • Weather
      • Weather Plugins
      • Ambient Weather
    • Tools
      • Gambit Communications
      • PubNub
  • 📊Dashboards & Widgets
    • HTML Canvas
      • 3rd party packages
      • Preload Dashboard data
      • Built-in library
        • Properties
        • Methods
        • Listening events
        • API
      • Examples
        • Basics
        • Create an LCD screen with the HTML Canvas
        • Interacting with dashboard data
        • Change header's custom style
        • Adding real time using Socket.IO
        • Delete Variable data from a Device
        • Delete Variable data from Groups or Types of Devices
        • Navigation through Dashboard
        • Using a React library
      • Code editor
        • HTML Tab
        • CSS Tab
        • JavaScript Tab
    • Custom UI
      • Paragraph
      • Input combo
        • Text
        • Numeric
        • Numeric with buttons
        • Date
        • Time
        • Toggle
        • Dropdown
        • Multiple selection dropdown
      • Button
    • Custom Style
      • Dashboards
      • Widgets
    • Line chart
    • Pages
      • Getting started
      • Development
      • API
        • Page creation
        • Publish
  • 🤖UbiFunctions
    • Getting Started
      • Creating an UbiFunction
      • Coding an UbiFunction
      • Testing an UbiFunction
      • Authentication
      • Execution Time
      • Logs
    • Runtimes
      • Python
      • NodeJS
      • Custom Runtimes
    • Invocation
      • Time-based Trigger
      • HTTPS
      • MQTT Publish
      • Ubidots Event
    • Advanced
      • Account Token
      • Execution time
      • Raw Functions
      • CORS Policy
      • Async Execution
      • DaaS (Decoder as a Service)
      • Developing and Managing UbiFunctions with Ubidots CLI
    • Examples
    • Specs and Limits
    • Storage
      • File Storage API
      • Mutiple files
  • 🧩Plugins
    • What is a plugin?
    • Public vs. Private
    • Public plugins
      • Cron
      • Webhook
    • Private Plugins
      • Cron
      • Webhook
      • Widget
      • Device
    • Plugins development
      • Getting started
      • Cron
      • Webhook
      • Widget
      • Device
      • view.xml
      • view_widget.xml
    • Plugins deployment
      • Cron and Webhook
      • Widget
      • Device
    • Using the plugins
      • Cron and Webhook
      • Widget
      • Device
  • 📈SYNTHETIC VARIABLES
    • Getting started
      • Creating synthetic variables
      • Synthetic Variables' editor
    • Expressions
      • Mathematical
      • Date range
      • Rolling
      • Special functions
    • Specs and limits
    • Examples
      • Mathematical
      • Date range
      • Rolling
      • Special functions
  • ⌨️Developer tools
    • Javascript SDK
      • Overview
      • Getting started
      • Ubidots class
        • Get methods
        • Filter methods
        • Ubidots objects
          • Entity object
          • Paginator
      • Examples
    • CLI
      • Overview
      • Installing
      • Usage
      • SDK for UbiFunctions
  • 🏗️Apps
    • App builder
      • Custom sidebar
Powered by GitBook
On this page
  • Devices
  • Get all devices in the account
  • Get the first device in the account
  • Get the first 1000 devices in the account
  • Get the lastActivity field from devices
  • Get the lastActivity and variablesCount fields from devices
  • Get the lastActivity and variablesCount fields from a specific device using its label
  • Get a device by label or ID
  • Get a set of devices based on their type
  • Variables
  • Get all the variables in the account
  • Get the first variable in the account:
  • Get the first 100 variables in the account:
  • Get the lastActivity field from variables
  • Get the lastActivity and label fields from all variables
  • Get the lastActivity and label fields from a specific variable
  • Get a variable by ID:
  • Get a set of variables based on their label:
  • Send data
  • Get all the users in the account
  • Get all the organizations in the account
  • Get all the devices asigned to an organization
  • Get all the dashboards in the account

Was this helpful?

Export as PDF
  1. Developer tools
  2. Javascript SDK

Examples

How to use UJL

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 the lastActivity field from devices

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

Get the lastActivity and variablesCount fields from devices

const device = await Ubidots.devices.addRawParams(
  { 
      fields: 'lastActivity,variablesCount'
  }
 ).get();

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

const device = await Ubidots.devices.addRawParams(
  { 
      label: 'temperature_sensor',
      fields: 'lastActivity,variablesCount'
  }
).get();

Get a device by label or ID

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

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

Get a set of devices based on their type

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

Variables

Get all the 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 the lastActivity field from variables

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

Get the lastActivity and label fields from all variables

const variables = await Ubidots.variables.addRawParams(
  { 
    fields: 'lastActivity,label'
  }
).get();

Get the lastActivity and label fields from a specific variable

const variables = await Ubidots.variables.addRawParams(
  { 
    id: '6452a727df1a8e000c103fce',
    fields: 'lastActivity,label'
  }
).get();

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:

    temperatureVariable.sendDot(34);
  • 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' });
    

Get all the users in the account

const allUsers = await Ubidots.users.all();

Get all the organizations in the account

const allOrganizations = await Ubidots.organizations.all();

Get all the devices asigned to an organization

const org = await Ubidots.organizations.where('id').exact('668fffcd88e37d000da10dd0').first();
const orgDevices = await org.devices.all();
orgDevices.forEach(device => {
  // Do something with each device
});

Get all the dashboards in the account

const allDashboards = await Ubidots.dashboards.all();
PreviousPaginatorNextCLI

Last updated 6 months ago

Was this helpful?

⌨️