# Pages

This command allows you to:

* Perform CRUD operations over Pages in Ubidots.
* Sync local page files with the Ubidots cloud.
* Set up a local development environment for Pages.

Its subcommands are:

```bash
Usage: ubidots pages [OPTIONS] COMMAND [ARGS]...

 Tool for managing and developing Ubidots Pages.

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --help          Show this message and exit.                                  │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ dev      Local development commands for Ubidots pages.                       │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Cloud Commands ─────────────────────────────────────────────────────────────╮
│ add      Adds a new page in the remote server.                               │
│ delete   Deletes a specific page using its id or label.                      │
│ get      Retrieves a specific page using its id or label.                    │
│ list     Lists all available pages.                                          │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Sync Commands ──────────────────────────────────────────────────────────────╮
│ pull     Retrieve and update your local page code with the latest changes    │
│          from the remote server.                                             │
│ push     Update and synchronize your local page code with the remote server. │
╰──────────────────────────────────────────────────────────────────────────────╯
```

{% hint style="info" %}
To run pages locally, [Docker](https://docs.docker.com/engine/install/) must be installed and running.
{% endhint %}

## Cloud operations

### List all pages

List all Pages in your Ubidots account.

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

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --profile          TEXT          Name of the profile to use for remote       │
│                                  server communication.                       │
│ --fields           TEXT          Comma-separated fields to process * e.g.    │
│                                  field1,field2,field3. * Available fields:   │
│                                  (id, label, name, url, isActive, createdAt, │
│                                  settings).                                  │
│                                  [default: id,label,name]                    │
│ --sort-by          TEXT          [default: None]                             │
│ --page-size        INTEGER       [default: None]                             │
│ --page             INTEGER       [default: None]                             │
│ --format           [table|json]  [default: table]                            │
│ --help                           Show this message and exit.                 │
╰──────────────────────────────────────────────────────────────────────────────╯
```

### Get a page

Retrieve a specific Page from your Ubidots account.

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

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --profile                    TEXT          Name of the profile to use for    │
│                                            remote server communication.      │
│ --id                         TEXT          [default: None]                   │
│ --label                      TEXT          [default: None]                   │
│ --fields                     TEXT          Comma-separated fields to process │
│                                            * e.g. field1,field2,field3. *    │
│                                            Available fields: (id, label,     │
│                                            name, url, isActive, createdAt,   │
│                                            settings).                        │
│                                            [default: id,label,name]          │
│ --format                     [table|json]  [default: table]                  │
│ --verbose    --no-verbose                  [default: no-verbose]             │
│ --help                                     Show this message and exit.       │
╰──────────────────────────────────────────────────────────────────────────────╯
```

### Create a page

Create a new Page in your Ubidots account.

```bash
 Usage: ubidots pages add [OPTIONS] NAME

╭─ Arguments ──────────────────────────────────────────────────────────────────╮
│ *    name      TEXT  The name of the page. [required]                        │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --profile        TEXT  Name of the profile to use for remote server          │
│                        communication.                                        │
│ --label          TEXT  The label for the page.                               │
│ --help                 Show this message and exit.                           │
╰──────────────────────────────────────────────────────────────────────────────╯
```

### Delete a page

Delete a Page from your Ubidots account.

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

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --profile                      TEXT  Name of the profile to use for remote   │
│                                      server communication.                   │
│ --id                           TEXT  [default: None]                         │
│ --label                        TEXT  [default: None]                         │
│ --yes      -y                        Confirm deletion without prompt.        │
│ --verbose      --no-verbose          [default: no-verbose]                   │
│ --help                               Show this message and exit.             │
╰──────────────────────────────────────────────────────────────────────────────╯
```

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

## Sync operations

### Push a page

Push a local Page's files to Ubidots cloud.

```bash
 Usage: ubidots pages push [OPTIONS]

 Update and synchronize your local page code with the remote server.

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --yes      -y                        Confirm file overwrite without prompt.  │
│ --profile  -p                  TEXT  Profile to use.                         │
│ --verbose      --no-verbose          [default: no-verbose]                   │
│ --help                               Show this message and exit.             │
╰──────────────────────────────────────────────────────────────────────────────╯
```

{% hint style="warning" %}
This command must be executed from the local page's directory.
{% endhint %}

If the page has never been pushed before, the CLI will prompt you to confirm creating a new page on the remote server. The remote page ID is saved to local metadata after the first push so subsequent pushes are linked automatically.

### Pull a page

Pull a Page's files from Ubidots cloud to your local machine.

```bash
 Usage: ubidots pages pull [OPTIONS]

 Retrieve and update your local page code with the latest changes from the
 remote server.

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --remote-id  -i                  TEXT  The remote page ID.                   │
│ --profile    -p                  TEXT  Profile to use.                       │
│ --yes        -y                        Confirm file overwrite without        │
│                                        prompt.                               │
│ --verbose        --no-verbose          [default: no-verbose]                 │
│ --help                                 Show this message and exit.           │
╰──────────────────────────────────────────────────────────────────────────────╯
```

When running from outside a page directory, `--remote-id` is required and the page is created in a new subdirectory. When running from inside an existing page directory, the local metadata is used to determine the remote ID automatically.

## Local development

The `pages dev` subcommand group provides local development commands for Ubidots Pages. All commands (except `dev add` and `dev list`) must be run from inside the page's directory. Docker must be running before executing these commands.

```bash
 Usage: ubidots pages dev [OPTIONS] COMMAND [ARGS]...

 Local development commands for Ubidots pages.

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --help          Show this message and exit.                                  │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ add       Create a new local Ubidots page with default structure and         │
│           content. This command creates a directory with all required files. │
│ list      List all pages and their status.                                   │
│ restart   Restart the local development server for the Ubidots page.         │
│ start     Start the local development server for the Ubidots page.           │
│ status    Show the status of the local development server for the Ubidots    │
│           page.                                                              │
│ stop      Stop the local development server for the Ubidots page.            │
╰──────────────────────────────────────────────────────────────────────────────╯
```

### Create a local page

Scaffold a new local Page project with the required file structure.

```bash
 Usage: ubidots pages dev add [OPTIONS]

 Create a new local Ubidots page with default structure and content. This
 command creates a directory with all required files.

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --name                         TEXT         The name for the page.           │
│                                             [default: my_page]               │
│ --remote-id                    TEXT         Optional: remote page ID to pull │
│                                             from cloud.                      │
│ --profile                      TEXT         Profile to use.                  │
│ --type                         [dashboard]  The type of page to create.      │
│                                             [default: dashboard]             │
│ --verbose      --no-verbose                 [default: no-verbose]            │
│ --help                                      Show this message and exit.      │
╰──────────────────────────────────────────────────────────────────────────────╯
```

The command creates a directory with the following structure:

```
plant-a-overview/
├── manifest.toml   # Page configuration and library declarations
├── body.html       # HTML markup for the page body
├── script.js       # JavaScript for the page
├── style.css       # CSS styles for the page
└── static/         # Directory for static assets
```

### Start the local development server

Start the local development server for a Page. The page will be accessible at `http://localhost:8080/<page-name>`.

```bash
 Usage: ubidots pages dev start [OPTIONS]

 Start the local development server for the Ubidots page.

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --verbose    --no-verbose      [default: no-verbose]                         │
│ --help                         Show this message and exit.                   │
╰──────────────────────────────────────────────────────────────────────────────╯
```

{% hint style="warning" %}
This command must be run from inside the page's directory. Docker must be running.
{% endhint %}

### Stop the local development server

Stop the running local development server for a Page.

```bash
 Usage: ubidots pages dev stop [OPTIONS]

 Stop the local development server for the Ubidots page.

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --verbose    --no-verbose      [default: no-verbose]                         │
│ --help                         Show this message and exit.                   │
╰──────────────────────────────────────────────────────────────────────────────╯
```

### Restart the local development server

Restart the local development server for a Page.

```bash
 Usage: ubidots pages dev restart [OPTIONS]

 Restart the local development server for the Ubidots page.

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --verbose    --no-verbose      [default: no-verbose]                         │
│ --help                         Show this message and exit.                   │
╰──────────────────────────────────────────────────────────────────────────────╯
```

### Show page status

Show the status of the local development server for a Page.

```bash
 Usage: ubidots pages dev status [OPTIONS]

 Show the status of the local development server for the Ubidots page.

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --verbose    --no-verbose      [default: no-verbose]                         │
│ --help                         Show this message and exit.                   │
╰──────────────────────────────────────────────────────────────────────────────╯
```

### List all local pages

List all local pages and their development server status.

```bash
 Usage: ubidots pages dev list [OPTIONS]

 List all pages and their status.

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --verbose    --no-verbose      [default: no-verbose]                         │
│ --help                         Show this message and exit.                   │
╰──────────────────────────────────────────────────────────────────────────────╯
```
