# Filter methods

The Ubidots API supports requests using [field filters](https://docs.ubidots.com/reference/field-filters), like this:

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

This library also provides a way to construct custom requests that take advantage of these filters.

## Filter methods

<table data-full-width="true"><thead><tr><th width="176" align="center">Filter method</th><th width="148" align="center">Description</th><th align="center">Usage</th><th width="221" align="center">Arguments</th><th align="center">Response</th></tr></thead><tbody><tr><td align="center"><code>where</code></td><td align="center">Applies a filter on a single property of the given <code>entity</code></td><td align="center"><code>Ubidots.&#x3C;entity>.where(&#x3C;entity-property>).&#x3C;filter>(&#x3C;filter-value>).&#x3C;get-method>(, [args])</code></td><td align="center">A valid property of the given <code>entity</code></td><td align="center">Depends on the <a href="get-methods"><code>&#x3C;getMethod></code></a> used.</td></tr><tr><td align="center"><code>addRawParams</code></td><td align="center">Applies filters on multiple properties of the given <code>entity</code></td><td align="center"><code>Ubidots.&#x3C;entity>.addRawParams(&#x3C;query-object>).&#x3C;get-method>(, [args])</code></td><td align="center"><p><code>query-object: object</code> An object containing queryparam-value pairs</p><pre class="language-json"><code class="lang-json">{
  queryParam1: value1 
  ···    
  queryParamN: valueN
}
</code></pre></td><td align="center">Depends on the <a href="get-methods"><code>&#x3C;getMethod></code></a> used.</td></tr></tbody></table>

## Using `where` method <a href="#using-where-method" id="using-where-method"></a>

The example GET request shown at the top of this page can be replicated using the library's `where` method, like this:

```javascript
const tempDevices = await Ubidots.devices.where('label').startsWith('temp').get();
```

**Here:**

* `<entity> = devices`
* `<entity-property> = 'label'`
* `<filter> = startsWith`
* `<filter-value> = 'temp'`
* `<getMethod> = get`

## Using `addRawParams` method <a href="#using-addrawparams-method" id="using-addrawparams-method"></a>

The example GET request shown at the top of this page can be replicated using the library's `addRawParams` method, like this:

```javascript
const filterParameters = {
  label__startswith: 'temp',
};
const tempDevices = await Ubidots.devices.addRawParams(filterParameters).get();
```

**Here:**

* `<entity> = devices`
* `<queryObject> = filterParameters`
* `<getMethod> = get`
* `<queryParam1> = label__startswith`
* `<value1> = 'temp'`

## Accessing the filters

[API filters](https://docs.ubidots.com/reference/field-filters) are written in snake-case. Take a look at some of the supported [object filters](https://docs.ubidots.com/reference/json) for example:

* contains
* contained\_by
* has\_key

In order to maintain the camel-case standard of JavaScript, the library's filters are written in camel-case, so the previous filters would look like this:

* contains
* containedBy
* hasKey

Below you'll find the full list filters, as defined in the API vs. how they look in the library.

### [ID](https://docs.ubidots.com/reference/id)

| Filter in the API | Filter in the library |
| :---------------: | :-------------------: |
|    exact ( = )    |        `exact`        |
|         in        |          `in`         |

### [Boolean](https://docs.ubidots.com/reference/boolean)

| Filter in the API | Filter in the library |
| :---------------: | :-------------------: |
|    exact ( = )    |          `is`         |
|       isnull      |        `isNull`       |

### [Number](https://docs.ubidots.com/reference/number)

| Filter in the API | Filter in the library |
| :---------------: | :-------------------: |
|       exact       |          `is`         |
|       range       |        `range`        |
|      gt ( > )     |     `greaterThan`     |
|     gte (`≥`)     |    `greaterThanEq`    |
|      lt ( < )     |      `lowerThan`      |
|     lte (`≤`)     |     `lowerThanEq`     |
|       isnull      |        `isNull`       |

### [String](https://docs.ubidots.com/reference/string)

|        Filter in the API       | Filter in the library |
| :----------------------------: | :-------------------: |
|  exact ( = ) (case sensitive)  |        `exact`        |
|     iexact (case sensitive)    |        `iexact`       |
|            contains            |       `contains`      |
|  icontains (case insensitive)  |      `iContains`      |
|           startswith           |      `startsWith`     |
| istartswith (case insensitive) |     `iStartsWith`     |
|            endswith            |       `endsWith`      |
|  iendswith (case insensitive)  |      `iEndsWith`      |
|       in (case sensitive)      |          `in`         |
|             isnull             |        `isNull`       |

### [Array](https://docs.ubidots.com/reference/array)

| Filter in the API | Filter in the library |
| :---------------: | :-------------------: |
|    exact ( = )    |        `exact`        |
|      contains     |       `contains`      |
|   contained\_by   |     `containedBy`     |
|      overlap      |       `overlap`       |
|        len        |         `len`         |
|       isnull      |        `isNull`       |

### [Object](https://docs.ubidots.com/reference/json)

| Filter in the API | Filter in the library |
| :---------------: | :-------------------: |
|      contains     |       `contains`      |
|   contained\_by   |     `containedBy`     |
|      has\_key     |        `hasKey`       |
|   has\_any\_keys  |      `hasAnyKeys`     |
|     has\_keys     |       `hasKeys`       |
|       isnull      |        `isNull`       |

### [Date](https://docs.ubidots.com/reference/date)

| Filter in the API | Filter in the library |
| :---------------: | :-------------------: |
|    exact ( = )    |        `exact`        |
|        date       |         `date`        |
|        year       |         `year`        |
|      quarter      |       `quarter`       |
|       month       |        `month`        |
|        week       |         `week`        |
|        day        |         `day`         |
|        hour       |         `hour`        |
|       minute      |        `minute`       |
|       second      |        `second`       |
|       isnull      |        `isNull`       |
