# API

## JavaScript SDK

The HTML Canvas built-in library exposes the [Ubidots JavaScript SDK](/sdks/javascript.md) through `ubidots.api`. This simplifies interactions with the Ubidots API when you develop in HTML Canvas. It avoids manual requests and custom wrappers.

Use the following syntax to access SDK methods:

```
ubidots.api.<JS_SDK_METHODS>
```

{% hint style="info" %}
See the [JavaScript SDK docs](/sdks/javascript.md) for supported entities, methods, and filtering capabilities.
{% endhint %}

## Usage

**With** [**Preload dashboard data**](/dashboards-and-widgets/html-canvas/preload-dashboard-data.md) **enabled:**

```javascript
// Get the token from the Ubidots built-in library
const TOKEN = ubidots.token;

// Authenticate the SDK with the token
ubidots.api.authenticate(TOKEN);

// Get the first 100 devices in the account
ubidots.api.devices.get().then((devices) => {
    // Print an array of Device objects
    console.log(devices);
    
    // YOUR LOGIC FOR THESE 100 DEVICES
});
```

**With Preload dashboard data disabled:**

```javascript
var ubidots = new Ubidots();

let TOKEN;

ubidots.on("ready", async () => {
    TOKEN = ubidots.token;
    
    // Authenticate the SDK with the token
    ubidots.api.authenticate(TOKEN);
    
    // Get the first 100 devices in the account
    var devices = await ubidots.api.devices.get();
    
    // Print an array of Device objects
    console.log(devices);
    
    // YOUR LOGIC FOR THESE 100 DEVICES
});
```


---

# 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/dashboards-and-widgets/html-canvas/built-in-library/api.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.
