> ## Documentation Index
> Fetch the complete documentation index at: https://code.dcycle.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Facilities

> Manage physical locations — offices, warehouses, factories, and stores

<Note>
  **Early Access** - The Dcycle CLI is currently available for enterprise customers.
  [Contact us](/docs/support) to learn more about access.
</Note>

## Overview

The `facility` command manages physical locations in your organization. Facilities are the primary anchors for energy invoices, Scope 1 and Scope 2 emissions, and logistic hubs.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
dcy facility <subcommand> [flags]
```

### Available Commands

| Command  | Description           |
| -------- | --------------------- |
| `list`   | List facilities       |
| `show`   | Show facility details |
| `create` | Create a facility     |
| `edit`   | Edit a facility       |
| `delete` | Delete a facility     |

***

## List Facilities

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
dcy facility list [flags]

# Aliases
dcy facility ls
```

### Examples

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
# List all facilities
dcy facility list

# Filter by status
dcy facility list --status active

# Filter by name
dcy facility list --name "Madrid"

# By date range
dcy facility list --start-date 2025-01-01 --end-date 2025-12-31

# Pagination
dcy facility list --page 2 --size 100

# JSON output for scripting
dcy facility list --format json | jq '.[] | {id, name, type}'
```

### Flags

| Flag           | Short | Default | Description                             |
| -------------- | ----- | ------- | --------------------------------------- |
| `--name`       | `-n`  | —       | Filter by name                          |
| `--status`     | —     | —       | Filter by status (`active`, `inactive`) |
| `--start-date` | —     | —       | Filter from date (YYYY-MM-DD)           |
| `--end-date`   | —     | —       | Filter to date (YYYY-MM-DD)             |
| `--page`       | —     | `1`     | Page number                             |
| `--size`       | —     | `50`    | Items per page                          |
| `--org`        | —     | —       | Organization ID override                |

### Output

```
Showing 3 of 3 facilities in Acme Corp
abc123-def456-... | Madrid HQ           | office    | ES | active
def456-ghi789-... | Barcelona Warehouse | warehouse | ES | active
ghi789-jkl012-... | Valencia Factory    | factory   | ES | active
```

Columns: ID, name, type, country, status.

***

## Show Facility Details

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
dcy facility show <facility-id>
```

### Examples

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
dcy facility show 00000000-0000-0000-0000-000000000000

# JSON output
dcy facility show <facility-id> --format json
```

### Flags

| Flag    | Description              |
| ------- | ------------------------ |
| `--org` | Organization ID override |

### Output

```
ID: abc123-def456-...
Name: Madrid HQ
Type: office
Country: ES
Status: active
Address: Calle Gran Via 1, Madrid
Categories: scope1, scope2
CUPS: ES0021000012345678AB
CO2e: 45.20000 tCO2e
Invoices Count: 12
Created: 2024-01-15
Updated: 2024-06-01
```

***

## Create Facility

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
dcy facility create [flags]
```

### Examples

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
dcy facility create --name "Madrid HQ" --type office

dcy facility create \
  --name "Madrid HQ" \
  --type office \
  --country ES \
  --address "Calle Gran Via 1, Madrid"

dcy facility create \
  --name "Warehouse" \
  --type warehouse \
  --country ES \
  --categories "scope1,scope2"
```

### Flags

| Flag                | Short | Required | Default  | Description                                           |
| ------------------- | ----- | -------- | -------- | ----------------------------------------------------- |
| `--name`            | `-n`  | Yes      | —        | Facility name                                         |
| `--type`            | `-t`  | Yes      | —        | Facility type (e.g. `office`, `warehouse`, `factory`) |
| `--country`         | —     | No       | `ES`     | Country code                                          |
| `--address`         | `-a`  | No       | —        | Physical address                                      |
| `--status`          | —     | No       | `active` | `active` or `inactive`                                |
| `--categories`      | —     | No       | —        | Comma-separated categories                            |
| `--logistic-factor` | —     | No       | —        | Logistic factor                                       |
| `--org`             | —     | No       | —        | Organization ID override                              |

***

## Edit Facility

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
dcy facility edit <facility-id> [flags]
```

### Examples

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
dcy facility edit <facility-id> --name "Madrid HQ v2"
dcy facility edit <facility-id> --status active --country FR
dcy facility edit <facility-id> --categories "scope1,scope2,scope3"
```

### Flags

Accepts the same flags as `create` (all optional — only provided fields are updated).

***

## Delete Facility

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
dcy facility delete <facility-id> [flags]

# Aliases
dcy facility rm <facility-id>
```

### Examples

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
# Interactive confirmation
dcy facility delete <facility-id>

# Skip confirmation
dcy facility delete <facility-id> --yes
```

### Flags

| Flag    | Short | Default | Description              |
| ------- | ----- | ------- | ------------------------ |
| `--yes` | `-y`  | `false` | Skip confirmation prompt |
| `--org` | —     | —       | Organization ID override |

### Output

Confirmation prompt:

```
Delete facility Madrid HQ (abc123-...)? [y/N]
```

```
facility deleted successfully: Madrid HQ
```

***

## Common Options

All facility commands support:

| Flag            | Description                        |
| --------------- | ---------------------------------- |
| `--format json` | JSON output (default: `text`)      |
| `--verbose`     | Show HTTP request/response details |
| `--timeout`     | Request timeout in seconds         |

***

## Workflows

### Export Facilities for Reporting

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
# Export all facilities as JSON
dcy facility list --format json > facilities.json

# Count facilities by type
dcy facility list --format json | jq 'group_by(.type) | map({type: .[0].type, count: length})'

# Find facilities without emissions
dcy facility list --format json | jq '[.[] | select(.co2e == null or .co2e == 0)]'
```

### Facility Lifecycle

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
# 1. Create a new facility
dcy facility create --name "New Office" --type office --country ES

# 2. Link invoices and data (via dcy invoice, dcy file, etc.)

# 3. Review facility details
dcy facility show <facility-id>

# 4. Deactivate when no longer needed
dcy facility edit <facility-id> --status inactive
```

### Piping with jq

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
# List facility IDs for scripting
dcy facility list --format json | jq -r '.[].id'

# Get facility names and countries
dcy facility list --format json | jq '.[] | {name, country, type}'

# Count invoices per facility
dcy facility list --format json | jq '.[] | {name, invoices: .invoices_length}'
```
