# API

## Javascript SDK

The HTML Canvas' built-in library exposes [Ubidots' Javascript SDK](https://dev.ubidots.com/sdks/javascript) through `ubidots.api`. This simplifies interacting with Ubidots API when developing in the HTML Canvas, hence avoiding making request by hand, or writing wrappers to generalize request making.&#x20;

To access the SDK methods, follow the below syntax:

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

{% hint style="info" %}
Refer to the [Javascript SDK Docs](https://dev.ubidots.com/sdks/javascript) to learn more about its supported entities, methods and filtering capabilities. &#x20;
{% endhint %}

## Usage

[**Dashboard data preloaded**](https://dev.ubidots.com/dashboards-and-widgets/html-canvas/preload-dashboard-data)**:**&#x20;

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

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

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

**NO dashboard data preloaded:**

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

const TOKEN = undefined;

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