> For the complete documentation index, see [llms.txt](https://dev.ubidots.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev.ubidots.com/sdks/javascript/examples.md).

# Examples

How to use UJL

## Devices

### Get all devices in the account

```javascript
const allDevices = await Ubidots.devices.all();
```

### Get the first device in the account

```javascript
const firstDevice = await Ubidots.devices.first();
// This is equivalent to
const firstDevice = (await Ubidots.devices.all())[0];
```

### **Get the first 1000 devices in the account**

```javascript
const devicesPaginated = (await Ubidots.devices.paginate(1, 1000)).results
```

### Get the `lastActivity` field from devices

```javascript
 const allDevicesLastActivity = await Ubidots.devices.addRawParam('fields', 'lastActivity').get();
```

### Get the `lastActivity` and `variablesCount` fields from devices

```javascript
const device = await Ubidots.devices.addRawParams(
  { 
      fields: 'lastActivity,variablesCount'
  }
 ).get();
```

### Get the `lastActivity` and `variablesCount` fields from a specific device using its label

```javascript
const device = await Ubidots.devices.addRawParams(
  { 
      label: 'temperature_sensor',
      fields: 'lastActivity,variablesCount'
  }
).get();
```

### Get a device by label or ID

```javascript
// By label
const temperatureDevice = await Ubidots.devices.where('label').exact('temperature_device_1').first();

// By id
const temperatureDevice = await Ubidots.devices.where('id').exact('some-id').first();
```

### Get a set of devices based on their type

```javascript
const devicesByType = await Ubidots.devices.where('deviceType').exact('temperature-devices').get();
```

## Variables

### **Get all the variables in the account**

```javascript
const allVariables = await Ubidots.variables.all();
```

### **Get the first variable in the account:**

```javascript
const firstVariable = await Ubidots.variables.first();
// This is equivalent to
const firstVariable = (await Ubidots.variables.all())[0];
```

### **Get the first 100 variables in the account:**

```javascript
const variablesPaginated = (await Ubidots.variables.paginate(1, 100)).results;
// Equivalent to
const variablesPaginated = (await Ubidots.variables.paginate()).results;
```

### **Get the `lastActivity` field from variables**

```javascript
const allVariablesLastActivity = await Ubidots.variables.addRawParam('fields', 'lastActivity').get();
```

### **Get the `lastActivity` and `label` fields from all variables**

```javascript
const variables = await Ubidots.variables.addRawParams(
  { 
    fields: 'lastActivity,label'
  }
).get();
```

### **Get the `lastActivity` and `label` fields from a specific variable**

```javascript
const variables = await Ubidots.variables.addRawParams(
  { 
    id: '6452a727df1a8e000c103fce',
    fields: 'lastActivity,label'
  }
).get();
```

### **Get a variable by ID:**

```javascript
const variableById = await Ubidots.variables.where('id').exact('6595770b9de79b000dce0eae').first();
```

### **Get a set of variables based on their label:**

<pre class="language-javascript"><code class="lang-javascript"><strong>const variablesByLabel = await Ubidots.variables.where('label').exact('temperature').get();
</strong></code></pre>

### Send data

First, get the device object and then the variable you want to send data to:

```javascript
// Get the device object
const temperatureDevice = await Ubidots.devices.where('label').exact('temperature_device_1').first();
// Get the variable object
const temperatureVariable = await temperatureDevice.variables.where('label').exact('temperature').first();
```

* Send a value:

  ```javascript
  temperatureVariable.sendDot(34);
  ```
* Send a value with timestamp:

  ```javascript
  temperatureVariable.sendDot(40, new Date().getTime());
  ```
* Send a value with timestamp and context:

  ```javascript
  temperatureVariable.sendDot(4, new Date().getTime(), { status: 'cold' });

  ```

## Get all the users in the account

```javascript
const allUsers = await Ubidots.users.all();
```

## Get all the organizations in the account <a href="#get-all-organizations-in-the-account" id="get-all-organizations-in-the-account"></a>

```javascript
const allOrganizations = await Ubidots.organizations.all();
```

## Get all the devices assigned to an organization <a href="#get-all-devices-assigned-to-an-organization" id="get-all-devices-assigned-to-an-organization"></a>

```javascript
const org = await Ubidots.organizations.where('id').exact('668fffcd88e37d000da10dd0').first();
const orgDevices = await org.devices.all();
orgDevices.forEach(device => {
  // Do something with each device
});
```

## Get all the dashboards in the account <a href="#get-all-dashboards-in-the-account" id="get-all-dashboards-in-the-account"></a>

```javascript
const allDashboards = await Ubidots.dashboards.all();
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://dev.ubidots.com/sdks/javascript/examples.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
