# Batch edit by entry ID

Edit multiple unrelated Contentful entries without opening a page tree. Useful for link variant sweeps, navigation item tweaks, and other standalone entry updates.

Batch commands use session name **`batch`** by default (override with `--session`). Page sessions from `cms-edit open` are not affected.

## Workflow

```bash
# Queue scalar field updates (one or more entryId:field=value tokens)
cms-edit batch set 3my7n2M84OrhOaaSLHVHvo:variant=link 7MjsLmOq52CR9C5xrYlcub:variant=button

# Review pending changes
cms-edit batch diff

# Write all changes as drafts (single save)
cms-edit batch save

# Or discard without saving
cms-edit batch discard
```

## Token format

```
<entryId>:<fieldId>=<value>
```

- **entryId** — 22-character Contentful entry ID (no `@` prefix)
- **fieldId** — field name on that entry's content type
- **value** — literal token (no shell quotes needed for simple strings). Coercion follows the field type from Contentful:
  - **Symbol** / **Text** — always stored as strings (e.g. `order=42` stays `"42"`)
  - **Integer** / **Number** — parsed as numbers
  - **Boolean** — `true` / `false`
  - **null** — literal `null`
  - Fields with enum validations (e.g. `variant`) must match allowed values

Examples:

```bash
cms-edit batch set abcdefghijklmnopqrstuv:variant=link
cms-edit batch set abcdefghijklmnopqrstuv:cmsLabel=Footer CTA
```

## Link variant sweep

When you already know link entry IDs (from `cms-edit read @cN links` or `cms-edit links list @cN`):

```bash
cms-edit batch set \
  idOne123456789012345678:variant=link \
  idTwo123456789012345678:variant=button
cms-edit batch diff
cms-edit batch save
```

When a page is already open, prefer `cms-edit links set @cN <index> variant link` instead.

## Content type schema cache

Field types and enum validations are loaded from the Contentful Management API. Results are cached:

- In the **batch session file** (`contentTypes` on the session) so `batch set` → `batch save` reuse schema without extra API calls
- On disk at `~/.contentful-cms/content-types/<spaceId>/<environment>/` (24-hour TTL)

## v1 limits

- **Scalar fields only** — no rich text, entry links, asset links, or link arrays
- **Draft-only** — same as `cms-edit save`; never publishes
- **No cross-entry link arrays** — use page session + `cms-edit set --links` for parent arrays
- **Partial save on failure** — if one entry fails during `batch save`, earlier entries may already be saved; the CLI lists failures and reminds you to run `cms-edit batch diff` for remaining changes

## Named sessions

```bash
cms-edit --session link-sweep batch set idOne123456789012345678:variant=link
cms-edit --session link-sweep batch save
```
