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

# occtoo segments

> Manage segments: named selections of the entries of a card

A segment is a named selection of the entries of a card, either by a search predicate or by a list of entry ids. Every segment command takes the card definition id first.

## List and show

```bash theme={null}
occtoo segments list products --status active
occtoo segments show products summer
```

`show` prints the segment with the predicate it selects by.

| Flag (`list`) | Description |
| - | - |
| `--name <NAME>` | Only segments whose name contains this text |
| `--type <KIND>` | `query` or `fixed` |
| `--status <STATUS>` | `initializing`, `active`, `scheduled` or `archived` |
| `--limit <LIMIT>` | Maximum number to return. Default `100` |

To see the entries of a segment, search the card:

```bash theme={null}
occtoo cards entries search products --segment summer --properties name
```

## Create a segment

```bash theme={null}
occtoo segments create products
occtoo segments create products --file segment.json
```

In a terminal, the CLI asks for each value. Otherwise, pass JSON. `type`, `description`, `image`, `tags`, `startTime` and `endTime` are optional:

```json theme={null}
{
  "id": "summer",
  "name": "Summer",
  "language": "en",
  "where": {
    "and": [
      { "text": { "property": "brand", "in": ["acme", "globex"] } },
      { "not": { "list": { "property": "tags", "contains": "outlet" } } }
    ]
  }
}
```

Occtoo tags the matching entries in the background. The segment is `Initializing` until that is done.

### Query and fixed segments

* A `Query` segment, the default, follows the entries that match its predicate.
* A `Fixed` segment holds the entries you list by id:

```json theme={null}
{
  "id": "picks",
  "name": "Picks",
  "language": "en",
  "type": "Fixed",
  "where": { "text": { "property": "id", "in": ["sku-1", "sku-2"] } }
}
```

### What a segment predicate can use

`where` is a search predicate, as in [`occtoo cards entries search`](https://docs.occtoo.com/cli/commands/cards#search-predicates), but a segment takes only part of it:

| Kind | Comparisons |
| - | - |
| `text` | `eq`, `in`, `pattern` |
| `list` | `contains`, `pattern` |
| `boolean` | `eq`, `in` |
| `integer`, `decimal`, `timestamp` | `eq`, `in`, `gte`, `lte` |
| `hasValue` | |
| `relation` | By id |

Use `and` at the top level, `or` anywhere, and `not` around a single condition. Patterns are case-sensitive. The API tells you what it doesn't accept.

## Edit a segment

```bash theme={null}
occtoo segments edit products summer
echo '{"name": "Summer sale", "where": {"boolean": {"property": "onSale", "eq": true}}}' | occtoo segments edit products summer
```

Every field is optional. A field you leave out stays as it is.

## Delete a segment

```bash theme={null}
occtoo segments delete products summer --yes
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.