# Write items in bulk

> Up to 25 sets and deletes in one call, in one scope.

`POST https://api.zavu.dev/v1/memory/collections/{collection}/items/batch`

Up to 25 sets and deletes in one call, in one scope.

**Not a transaction.** Each operation succeeds or fails on its own and is reported separately; the call returns `200` even when some failed. Check every entry's `ok` — treating a 200 as "all 25 landed" is the mistake this endpoint invites.

## Parameters

- `collection` (path, string, required): Collection name.
- `scope` (query, string): Which scope to address: `contact:<contactId>`, `conversation:<conversationId>`, or omitted for the project scope. Note the asymmetry with `POST /v1/memory` and `POST /v1/memory/search`, which take the scope in the request BODY as `scope` plus `contactId`/`conversationId`. Every other Memory endpoint takes it here.

## Body

- `ops` (object[], required)
  - `op` (string, required) One of: `set`, `delete`.
  - `key` (string, required)
  - `value` (any): The document, for `set`.
  - `ttlSeconds` (integer)

## Responses

### 200

Every operation was attempted. Inspect each result.

- `results` (object[], required): One entry per submitted operation, in order. Check every `ok`: the call returns 200 even when some operations failed.
  - `key` (string, required)
  - `ok` (boolean, required)
  - `rev` (integer): New revision, on a successful `set`.
  - `error` (string): Why this operation failed. Present when `ok` is false.

### 400

Invalid body, scope, or more than 25 operations.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 401

Unauthorized.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 404

Collection not found.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 429

The plan's monthly unit quota is spent.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

## Example

```bash
curl -X POST "https://api.zavu.dev/v1/memory/collections/collection_abc123/items/batch" \
  -H "Authorization: Bearer $ZAVUDEV_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "ops": [
    {
      "op": "set",
      "key": "ORD-1",
      "value": {
        "status": "shipped"
      }
    },
    {
      "op": "delete",
      "key": "ORD-0"
    }
  ]
}'
```

```typescript
import Zavudev from "@zavudev/sdk";

const zavu = new Zavudev({ apiKey: process.env.ZAVUDEV_API_KEY });

const result = await zavu.memory.collections.items.batch("collection_abc123", {
  ops: [
    {
      op: "set",
      key: "ORD-1",
      value: {
        status: "shipped",
      },
    },
    {
      op: "delete",
      key: "ORD-0",
    },
  ],
});

console.log(result);
```
