# Variables

This command allows you to perform CRUD operations over variables in Ubidots. Its subcommands are:

```
Usage: ubidots variables [OPTIONS] COMMAND [ARGS]...

 Variable management and operations.

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --help          Show this message and exit.                                  │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ add        Create a new variable in a given device.                          │
│ delete     Deletes a specific variable using its id.                         │
│ get        Retrieves a specific variable using its id.                       │
│ list       Lists all available variables.                                    │
│ update     Update a variable.                                                │
╰──────────────────────────────────────────────────────────────────────────────╯
```

## Create a variable

```bash
Create a new variable in a given device in Ubidots.

 Usage: ubidots variables add [OPTIONS] DEVICE [LABEL] [NAME]

╭─ Arguments ──────────────────────────────────────────────────────────────────╮
│      device      TEXT     The device associated with the variable. Its id or │
│                           ['~label'|\~label].                                │
│                           [required]                                         │
│      label       [LABEL]  The label for the variable.                        │
│      name        [NAME]   The name of the variable.                          │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --description                 TEXT             A brief description of the    │
│                                                variable.                     │
│ --type                        [raw|synthetic]  The type of variable.         │
│                                                [default: raw]                │
│ --unit                        TEXT             The unit of measurement that  │
│                                                represents the variable.      │
│ --synthetic-expression        TEXT             If the variable is of type    │
│                                                'synthetic', this is the      │
│                                                corresponding synthetic       │
│                                                expression used to calculate  │
│                                                its value.                    │
│ --tags                        TEXT             Comma-separated tags for the  │
│                                                variable. e.g. tag1,tag2,tag3 │
│ --properties                  TEXT             Device properties in JSON     │
│                                                format.                       │
│                                                [default: {}]                 │
│ --min                         INTEGER          Lowest value allowed.         │
│ --max                         INTEGER          Highest value allowed.        │
│ --help                                         Show this message and exit.   │
╰──────────────────────────────────────────────────────────────────────────────╯
```

## Get a variable <a href="#get-a-variable" id="get-a-variable"></a>

Retrieve a variable from Ubidots.

```bash
 Usage: ubidots variables get [OPTIONS]

╭─ Options ────────────────────────────────────────────────────────────────────╮
│    --id            TEXT  Unique identifier for the variable. [required]      │
│    --fields        TEXT  Comma-separated fields to process. e.g.             │
│                          field1,field2,field3                                │
│                          [default: id,label,name]                            │
│    --help                Show this message and exit.                         │
╰──────────────────────────────────────────────────────────────────────────────╯
```

## Update a variable <a href="#update-a-variable" id="update-a-variable"></a>

Update a variable in Ubidots.

```bash
 Usage: ubidots variables update [OPTIONS]

╭─ Options ────────────────────────────────────────────────────────────────────╮
│    --id                          TEXT             Unique identifier for      │
│                                                   the variable.              │
│                                                   [required]                 │
│    --new-label                   TEXT             The label for the          │
│                                                   variable.                  │
│    --new-name                    TEXT             The name of the variable.  │
│    --description                 TEXT             A brief description of the │
│                                                   variable.                  │
│    --type                        [raw|synthetic]  The type of variable.      │
│                                                   [default: raw]             │
│    --unit                        TEXT             The unit of measurement    │
│                                                   that represents the        │
│                                                   variable.                  │
│    --synthetic-expression        TEXT             If the variable is of type │
│                                                   'synthetic', this is the   │
│                                                   corresponding synthetic    │
│                                                   expression used to         │
│                                                   calculate its value.       │
│    --tags                        TEXT             Comma-separated tags for   │
│                                                   the variable. e.g.         │
│                                                   tag1,tag2,tag3             │
│    --properties                  TEXT             Device properties in JSON  │
│                                                   format.                    │
│                                                   [default: {}]              │
│    --min                         INTEGER          Lowest value allowed.      │
│    --max                         INTEGER          Highest value allowed.     │
│    --help                                         Show this message and      │
│                                                   exit.                      │
╰──────────────────────────────────────────────────────────────────────────────╯
```

## Delete a variable <a href="#delete-a-variable" id="delete-a-variable"></a>

Delete a variable from your Ubidots account.

```bash
 Usage: ubidots variables delete [OPTIONS]

╭─ Options ────────────────────────────────────────────────────────────────────╮
│    --id          TEXT  Unique identifier for the variable. [required]        │
│    --help              Show this message and exit.                           │
╰──────────────────────────────────────────────────────────────────────────────╯
```

{% hint style="warning" %}
This command permanently deletes the variable, just like removing it through the platform, thus special care is advised.
{% endhint %}

## List all variables

List all variables on your Ubidots account.

```bash
 Usage: ubidots variables list [OPTIONS]

╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────╮
│ --fields           TEXT          Comma-separated fields to process * e.g. field1,field2,field3. *   │
│                                  Available fields: (id, label, name, createdAt,                     │
│                                  syntheticExpression, description, device, lastActivity, lastValue, │
│                                  properties, tags, type, unit, url, valuesUrl). For more details,   │
│                                  visit the documentation at:                                        │
│                                  https://docs.ubidots.com/reference/variable-object                 │
│                                  [default: id,label,name]                                           │
│ --filter           TEXT          Filter results by attributes. e.g.                                 │
│                                  'key1=val1&key2__in=val20,val21' or                                │
│                                  key1=val1\&key2__in=val20,val21                                    │
│ --sort-by          TEXT          Attribute to sort the result set by.                               │
│ --page-size        INTEGER       Defines the page number to be retrieved.                           │
│ --page             INTEGER       Defines how many items per page are retrieved.                     │
│ --format           [table|json]  [default: table]                                                   │
│ --help                           Show this message and exit.                                        │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────╯
```


---

# 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/cli/variables.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.
