Field filters

Use Ubidots Field filters

Overview

Just as the Ubidots API supports Field filters, allowing to perform request such as:

GET https://industrial.api.ubidots.com/api/v2.0/devices/?label__startswith=temp

The library also provides a way to construct custom requests that take advantage of said filters.

Filter methods

The general filter syntax is:

Ubidots.<entity>.<filterMethod>(args).<getMethod>(, [args]);

Here:

where

Arguments: A valid entity property.

Signature: Ubidots.<entity>.where(<entity-property>).<filter>(<filter-value>)

The request above can be done as follows:

const tempDevices = await Ubidots.devices.where('label').startswith('temp').get();

Note here that:

  • <entity> = 'devices'.

  • <entity-property> = 'label' is a property of the Ubidots Device object.

  • <filter> = 'startswith' is one of the available filters that can be applied to the label property.

  • <filter-value> = 'temp' is the matching criteria for the startswith filter.

addRawParams

Arguments: queryObject: Object => An object containing query param value pairs. The query param values must be a string.

{
  "queryParam1" : "value1",
  ··· ,
  "queryParamN" : "valueN",
}

Signature: Ubidots.<entity>.addRawParams(<queryObject>)

The request above can be done as follows:

const tempDevices = await Ubidots.devices.addRawParams({
    label__startswith: "temp" 
}).get();

Note here that the filter is label__startswith in accordance withstring filters

Get methods usage

all

// Retrieves all devices matching the filter
const tempDevices = await Ubidots.devices.where('label').startswith('temp').all();

get

// Retrieves the first 100 devices matching the filter
const tempDevices = await Ubidots.devices.where('label').startswith('temp').get();

first

// Retrieves the first device matching the filter
const tempDevices = await Ubidots.devices.where('label').startswith('temp').first();

paginate

// Retrieves first page with 10 devices matching the filter
const tempDevices = await Ubidots.devices.where('label').startswith('temp').paginate(1, 10);

Last updated