> For a complete page index of the Captain API documentation, fetch https://docs.captain.dev/llms.txt?excludeSpec=true

# Algolia Batch

POST https://acme.captain.dev/1/indexes/{index}/batch
Content-Type: application/json

Algolia's batch writes with a Captain write key: addObject, updateObject, partialUpdateObject(NoCreate), deleteObject, clear and delete. `taskID` is the write's seq.

Reference: https://docs.captain.dev/reference/product-search/algolia-compatibility/algolia-batch

## Authentication

- `x-algolia-api-key` header (required) — A Captain key, as Algolia clients send it: a search key for queries, a write key for writes.
- `x-algolia-application-id` header (required) — Any value; the hostname selects the tenant.

## Request

### Path parameters

- `index` (string, required)

### Body (application/json)

This endpoint expects an object.

- `requests` (list of 1IndexesIndexBatchPostRequestBodyContentApplicationJsonSchemaRequestsItems, required)

## Response

### 200

accepted

- `taskID` (1IndexesIndexBatchPostResponsesContentApplicationJsonSchemaTaskId, optional) — the write's seq (an object of index -> seq for the multi-index batch, /1/indexes/*/batch)
- `objectIDs` (list of string, optional)

## Types

### 1IndexesIndexBatchPostRequestBodyContentApplicationJsonSchemaRequestsItems

- `action` (enum, required)
  - Allowed values: `addObject`, `updateObject`, `partialUpdateObject`, `partialUpdateObjectNoCreate`, `deleteObject`, `delete`, `clear`
- `body` (1IndexesIndexBatchPostRequestBodyContentApplicationJsonSchemaRequestsItemsBody, optional)
- `indexName` (string, optional) — the multi-index form only

### 1IndexesIndexBatchPostResponsesContentApplicationJsonSchemaTaskId

the write's seq (an object of index -> seq for the multi-index batch, /1/indexes/*/batch)

### 1IndexesIndexBatchPostRequestBodyContentApplicationJsonSchemaRequestsItemsBody

## Examples

**Request**

```json
{
  "requests": [
    {
      "action": "addObject",
      "body": {
        "objectID": "sku-10482",
        "title": "Moab 3 Mid Waterproof Hiking Boot",
        "price": 139
      }
    },
    {
      "action": "deleteObject",
      "body": {
        "objectID": "sku-10517"
      }
    }
  ]
}
```

**Response**

```json
{
  "taskID": 1854,
  "objectIDs": [
    "sku-10482",
    "sku-10517"
  ]
}
```

**SDK Code**

```python Python REST
import json
import requests

BASE_URL = "https://acme.captain.dev"
API_KEY = "your_write_key"
INDEX = "products"

headers = {
    "x-algolia-api-key": API_KEY,
    "x-algolia-application-id": "acme",
    "Content-Type": "application/json",
}

response = requests.post(
    f"{BASE_URL}/1/indexes/{INDEX}/batch",
    headers=headers,
    json={
        "requests": [
            {
                "action": "addObject",
                "body": {
                    "objectID": "sku-10482",
                    "title": "Moab 3 Mid Waterproof Hiking Boot",
                    "price": 139.0,
                },
            },
            {"action": "deleteObject", "body": {"objectID": "sku-10517"}},
        ],
    },
    timeout=30.0,
)

print(json.dumps(response.json(), indent=2))
```

```typescript TypeScript REST
const BASE_URL = "https://acme.captain.dev";
const API_KEY = "your_write_key";
const index = "products";

const response = await fetch(`${BASE_URL}/1/indexes/${index}/batch`, {
  method: "POST",
  headers: {
    "x-algolia-api-key": API_KEY,
    "x-algolia-application-id": "acme",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    requests: [
      {
        action: "addObject",
        body: {
          objectID: "sku-10482",
          title: "Moab 3 Mid Waterproof Hiking Boot",
          price: 139.0,
        },
      },
      { action: "deleteObject", body: { objectID: "sku-10517" } },
    ],
  }),
});

const result = await response.json();
console.log(JSON.stringify(result, null, 2));
```