# Batch edit by entry ID

Edit multiple Contentful entries by ID with scalar field updates. Useful for link variant sweeps, media flags (`autoplay`/`loop`), navigation tweaks, and other standalone updates.

## Sessions

| Context | What happens |
|---------|----------------|
| Default CLI (`--session` omitted) | Uses session name **`batch`** (does not touch a separate page session) |
| Page session already open (e.g. MCP `_mcp`) | `batch set` **stages into that page session** — same `diff` / `save` as article work. Do **not** re-`open`. Do **not** `batch discard` (use `cms-edit discard` only if abandoning everything). |
| Explicit isolation | `cms-edit --session link-sweep batch set …` |

You can also stay on the page session without `batch`:

```bash
cms-edit set <entryId>:autoplay=true <entryId>:loop=true
# or
cms-edit set <entryId> autoplay true
```

## 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 (pure batch sessions only)
cms-edit batch discard
```

Mid-page (MCP / open article session):

```bash
cms-edit batch set 5uMh54rIsJRFRQSXDuJiG:autoplay=true
cms-edit diff
cms-edit save
```

## Token format

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

- **entryId** — Contentful entry ID (alphanumeric, optional `_`/`-`, length 1–64; **not** fixed at 22 characters)
- **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 5uMh54rIsJRFRQSXDuJiG:autoplay=true
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 **session file** (`contentTypes` on the session) so `batch set` → 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 diff for remaining changes
