> ## 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 cards

> Manage card definitions, search card entries, and export them to CSV or Excel

A card definition says which properties of which sources make up the entries of a card. Use `occtoo cards` to manage card definitions, search their entries, and export entries to a file.

Property changes work in two steps. `create` and `edit` save them as pending, and `activate` rebuilds the entries with them.

## List and show

```bash theme={null}
occtoo cards list --status active
occtoo cards show product
```

`show` prints the properties in use and the changes that are pending.

| Flag (`list`) | Description |
| - | - |
| `--name <NAME>` | Only card definitions whose name contains this text |
| `--status <STATUS>` | `draft`, `active`, `updating` or `archived` |
| `--limit <LIMIT>` | Maximum number to return. Default `100` |

## Create a card definition

```bash theme={null}
occtoo cards create
occtoo cards create --file card.json
```

In a terminal, you pick a source and its properties. Otherwise, pass JSON. `description`, `tags`, `displayOptions` and `properties` are optional:

```json theme={null}
{
  "id": "product",
  "name": "Product",
  "displayOptions": { "name": "title" },
  "properties": [
    { "id": "title", "sourceId": "products", "sourcePropertyId": "title", "type": "Text", "name": { "en": "Title" } },
    { "id": "tags", "sourceId": "products", "sourcePropertyId": "tags", "type": "List", "delimiter": "," }
  ]
}
```

The card definition is saved as a draft. A property id is a lowercase letter followed by letters and digits. Its type is the type of the source property, and it can't change once the property is in use.

## Edit, activate and discard

```bash theme={null}
occtoo cards edit product --file changes.json
occtoo cards activate product
occtoo cards discard product --yes
```

`edit` prompts for the name and description in a terminal, or takes JSON. Every field is optional:

```json theme={null}
{
  "name": "Product",
  "description": "...",
  "tags": ["commerce"],
  "pendingChanges": {
    "set": [{ "id": "color", "sourceId": "products", "sourcePropertyId": "color", "type": "Text" }],
    "remove": ["legacyCode"]
  }
}
```

`pendingChanges` replaces everything that is pending, so send the whole set. `set` adds a property or changes one in use, and `remove` drops properties in use. To start from what is pending:

```bash theme={null}
occtoo cards show product --output json | jq '{pendingChanges}' > changes.json
```

* `activate` puts the pending changes to use and waits until the entries are rebuilt. Ctrl-C stops the waiting, not the rebuild. `show` tells you whether the card definition is still `Updating` or `Active`.
* `discard` throws away the pending changes and keeps the properties in use.

## Delete a card definition

```bash theme={null}
occtoo cards delete product --yes
```

Deletes a card definition for good. It is refused while destination endpoints, relations or segments use the card.

## Search entries

```bash theme={null}
occtoo cards entries search products --properties name,price --sort price:desc
occtoo cards entries search products --lifecycle <ID> --state incomplete --count
occtoo cards entries search products --segment summer --properties name
occtoo cards entries search products --facet brand --limit 1
occtoo cards entries search products --where '{"hasValue": {"property": "image"}}' --output json
```

Finds entries of a card, with their values and how far they have come in a lifecycle. Without `--properties`, entries come without values, so name the ones to show.

| Flag | Description |
| - | - |
| `--where <JSON>` | Only entries that match this search predicate |
| `--properties <IDS>` | Properties to show, separated by commas |
| `--segment <ID>` | Only entries in this segment of the card |
| `--language <LANGUAGE>` | The language to search in, for localized values |
| `--sort <PROPERTY[:asc\|desc]>` | Order by this property. Add `:desc` for largest first. Repeat for several |
| `--lifecycle <ID>` | Show how far each entry has come in this lifecycle. Repeat for several |
| `--state <STATE>` | Only entries in this lifecycle state: `complete`, `incomplete` or `not-applicable` |
| `--facet <PROPERTY>` | Count the values of this property among the matching entries. Repeat for several |
| `--show-segments` | Show the segments each entry is in |
| `--count` | Count every matching entry |
| `--limit <LIMIT>` | Maximum number of entries to return. Default `25` |
| `--file <FILE>` | Read the whole search request from a JSON file instead of the flags |

### Search predicates

`--where` takes a search predicate as JSON. A predicate names the type of the property it compares:

```json theme={null}
{"text": {"property": "name", "contains": "chair", "ignoreCase": true}}
{"decimal": {"property": "price", "gt": 100}}
{"hasValue": {"property": "image"}}
{"and": [{"boolean": {"property": "active", "eq": true}}, {"not": {"list": {"property": "tags", "contains": "old"}}}]}
```

* Kinds: `text`, `integer`, `decimal`, `timestamp`, `boolean`, `list`, `hasValue`, `segment`, `relation`, `lifecycle`. Combine them with `and`, `or` and `not`.
* Comparisons, depending on the kind: `eq`, `neq`, `in`, `contains`, `pattern`, `regex`, `lt`, `lte`, `gt`, `gte`.

### Full request from a file

`--file` takes the whole request as the API takes it and reads one page. Use it for what the flags don't cover, such as paging by cursor or facet options:

```json theme={null}
{
  "where": {},
  "properties": ["name"],
  "sort": [{ "property": "price", "direction": "Descending" }],
  "lifecycleIds": ["..."],
  "limit": 100,
  "after": "...",
  "includeTotalCount": true,
  "facets": [{ "property": "brand", "first": 20 }]
}
```

## Find related entries

```bash theme={null}
occtoo cards entries related products sku-1 productVariants --properties sku,size
occtoo cards entries related products sku-1 productVariants --sort @position --count
```

Finds the entries that a relation links to one entry. The arguments are the card definition, the entry id and the relation id. The entries come from the card on the other side of the relation, so `--properties`, `--where` and `--sort` name properties of that card. `--sort @position` follows the order of the relation itself.

It takes the same flags as `entries search`, except `--segment`, `--lifecycle`, `--state` and `--facet`. Run `occtoo relations list --source-card <CARD>` to see the relations of a card.

## Export entries

```bash theme={null}
occtoo cards export products
occtoo cards export products --out products.xlsx --languages en,sv
occtoo cards export products --properties title,price --where '{"boolean": {"property": "active", "eq": true}}'
occtoo cards export products --id <EXPORT> --out products.csv
```

Exports entries of a card to a CSV or Excel file and downloads it. Occtoo writes the file in the background, and the CLI shows the progress, waits and saves the file. Ctrl-C stops the waiting, not the export. Pick it up again with `--id`.

| Flag | Description |
| - | - |
| `--out <PATH>` | Where to save the file: a file name or a folder. Without it, the file is saved in the current folder under the name the API gives it |
| `--format <FORMAT>` | `csv` or `excel`. Otherwise the format follows the name in `--out` (`.csv` or `.xlsx`), and is CSV when neither says |
| `--where <JSON>` | Only entries that match this [search predicate](#search-predicates) |
| `--properties <IDS>` | Properties to export, separated by commas. Default: every property that is not hidden |
| `--languages <CODES>` | Languages to export, separated by commas. Default: the default language |
| `--language <LANGUAGE>` | The language `--where` compares localized values in |
| `--timestamps` | Add the time each entry last changed |
| `--delimiter <DELIMITER>` | What joins the items of a list value. Default: the delimiter of each property |
| `--id <EXPORT>` | Wait for and download an export that was started before, instead of starting one |

You can export at most 500,000 entries at once.


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