# Ubidots class

## Definition

The `Ubidots` class is the library's entry point. It provides subclasses to interact with each [supported entity](/sdks/javascript/overview.md#supported-entities) in the API. For example, to use the [devices API](https://docs.ubidots.com/reference/device-object), use:

```javascript
Ubidots.devices.<methods>
```

The methods exposed by the `devices` subclass let you use the full [devices API](https://docs.ubidots.com/reference/device-object).

## `Ubidots` class properties

|    Property   |                                           Description                                           |
| :-----------: | :---------------------------------------------------------------------------------------------: |
|    devices    |       Provides access to [devices](https://docs.ubidots.com/reference/device-object) API.       |
|   variables   |     Provides access to [variables](https://docs.ubidots.com/reference/variable-object) API.     |
|   dashboards  |    Provides access to [dashboards](https://docs.ubidots.com/reference/dashboard-object) API.    |
|     users     |         Provides access to [users](https://docs.ubidots.com/reference/user-object) API.         |
| organizations | Provides access to [organizations](https://docs.ubidots.com/reference/organization-object) API. |

{% hint style="info" %}
In this section, these properties are referred to as `entity` or `entities`. This reflects the part of the API they interact with. For example, `device entity` refers to the `Ubidots` class property that interacts with the [devices](https://docs.ubidots.com/reference/device-object) API.
{% endhint %}

## `Ubidots` class methods <a href="#ubidots-class-methods" id="ubidots-class-methods"></a>

<table><thead><tr><th width="148" align="center">Method</th><th width="197" align="center">Arguments</th><th align="center">Description</th></tr></thead><tbody><tr><td align="center">authenticate</td><td align="center">A valid Ubidots token.</td><td align="center">Authenticates with the Ubidots API.</td></tr><tr><td align="center">setBaseUrl</td><td align="center">Custom API Host</td><td align="center">Configures a custom base URL for all API requests.</td></tr></tbody></table>

## Usage

### Authentication <a href="#authentication" id="authentication"></a>

Authentication with a valid [Ubidots token](https://help.ubidots.com/en/articles/590078-find-your-token-from-your-ubidots-account) is required to use the library:

```javascript
Ubidots.authenticate('BBFF-ubidots-token');
```

### Custom API Host <a href="#instantiation" id="instantiation"></a>

Configure a custom base URL when connecting to a dedicated Ubidots deployment:

```javascript
Ubidots.setBaseUrl('https://custom.api.ubidots.com/api');
```

### Instantiation <a href="#instantiation" id="instantiation"></a>

This class is implemented as a singleton and is instantiated when exported. You do not need to create an instance. Use it directly:

```javascript
// Import the class
const { Ubidots } = require('@ubidots/ubidots-javascript-library');
// Call the 'authenticate' method without instantiating 'Ubidots' first
Ubidots.authenticate('ubidots-valid-token');
```

### General syntax <a href="#general-syntax" id="general-syntax"></a>

The `Ubidots` class exposes its [methods](/sdks/javascript/ubidots-class/get-methods.md) through [`entities`](#ubidots-class-properties) for specific parts of the API, such as devices or variables. Use the following syntax:

```javascript
Ubidots.<entity>.<getMethod>([args]);
```

### Filters syntax <a href="#filters-syntax" id="filters-syntax"></a>

[Field filtering](https://docs.ubidots.com/reference/field-filters) is available for each [`entity`](#ubidots-class-properties) through the following syntax:

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

**Here:**

* `<entity>` is any of the valid [entities](#ubidots-class-properties).
* `<filterMethod>` is either of these 2 methods:
  * [`where()`](/sdks/javascript/ubidots-class/filter-methods.md)
  * [`addRawParams()`](/sdks/javascript/ubidots-class/filter-methods.md)
* `<getMethod>` is any of the following methods used to retrieve [`entities`](#ubidots-class-properties):
  * [`all()`](/sdks/javascript/ubidots-class/get-methods.md)
  * [`get()`](/sdks/javascript/ubidots-class/get-methods.md)
  * [`first()`](/sdks/javascript/ubidots-class/get-methods.md)
  * [`paginate()`](/sdks/javascript/ubidots-class/get-methods.md)

{% hint style="info" %}
Neither `where` nor `addRawParams` sends a request to the API. They only build the URL with the corresponding query parameters. To perform the request, chain any of the [`<getMethod>`s](/sdks/javascript/ubidots-class/get-methods.md) after the filter statements.
{% endhint %}


---

# 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.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.
