# Filter methods

The Ubidots API supports requests that use [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 use 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 to 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="/pages/XFULG0XtbVJAeNEvhlxe"><code>&#x3C;getMethod></code></a> used.</td></tr><tr><td align="center"><code>addRawParams</code></td><td align="center">Applies filters to 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 query parameter-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="/pages/XFULG0XtbVJAeNEvhlxe"><code>&#x3C;getMethod></code></a> used.</td></tr></tbody></table>

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

The example GET request at the top of this page can be reproduced with the library's `where` method:

```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 the `addRawParams` method <a href="#using-addrawparams-method" id="using-addrawparams-method"></a>

The example GET request at the top of this page can be reproduced with the library's `addRawParams` method:

```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. For example, these [object filters](https://docs.ubidots.com/reference/json) are supported:

* contains
* contained\_by
* has\_key

To follow JavaScript's camel-case convention, the library's filters use camel case, so those same filters look like this:

* contains
* containedBy
* hasKey

Below is the full list of filters, showing the API names and their library equivalents.

### [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`       |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev.ubidots.com/sdks/javascript/ubidots-class/filter-methods.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
