---
title: "ResourceShark API: Batches"
description: "Create a batch, list batches, get a batch, or update a batch, with the ResourceShark API."
url: "https://agentpost.tools/docs/resourceshark/reference/batches"
kind: reference
---

# Batches

Group supply entries for a resource by batch and manage their expiry.

Paths are relative to `https://api.agentpost.tools/v1/resources`. [Who may call](/docs/resourceshark/reference.md#who-may-call) explains each credential.

## Create a batch

`POST /batches`

Creates a batch with a code unique within its resource.

-   **Who may call:** Your server, with your project’s secret key.
-   **Credential:** the examples send your project’s `dev` secret key, `sk_test_…`, as `Authorization: Bearer <token>`.
-   **SDK:** `client.batches.create(body)`
-   **Idempotency-Key:** optional. [Retrying a write](/docs/platform/api-basics.md#retrying-a-write) has the rule.

### Body

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `resourceId` | `string` | Yes | 1–256 characters. |
| `code` | `string` | Yes | 1–200 characters. |
| `expiresAt` | `string` | No | An ISO 8601 date and time. |
| `attributes` | `object` | No | Each value is a `string`. |

### Response

`201 Created`, with [`BatchResponse`](/docs/resourceshark/reference/batches.md#the-batchresponse-object).

### Errors

-   [`invalid_request`](/docs/resourceshark/errors.md#invalid_request) (400)
-   [`payload_too_large`](/docs/resourceshark/errors.md#payload_too_large) (413)
-   [`not_found`](/docs/resourceshark/errors.md#not_found) (404)
-   [`key_in_use`](/docs/resourceshark/errors.md#key_in_use) (409)

Any operation can also answer with the codes [Conventions](/docs/resourceshark/reference.md#conventions) lists.

```bash tab="curl"
curl -X POST https://api.agentpost.tools/v1/resources/batches \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "resourceId": "res_01M83PPH000000000000000001",
    "code": "ROAST-2026-11-23",
    "expiresAt": "2026-11-28T17:00:00.000Z",
    "attributes": {
      "origin": "Colombia"
    }
  }'
```

```ts tab="SDK"
import { createClient } from '@agentpost-tools/resourceshark-sdk';

const client = createClient({ token: 'sk_test_…' });
const { batch } = await client.batches.create({
  resourceId: 'res_01M83PPH000000000000000001',
  code: 'ROAST-2026-11-23',
  expiresAt: '2026-11-28T17:00:00.000Z',
  attributes: { origin: 'Colombia' },
});
```

```json title="Response"
{
  "batch": {
    "resourceId": "res_01M83PPH000000000000000001",
    "code": "ROAST-2026-11-23",
    "expiresAt": "2026-11-28T17:00:00.000Z",
    "attributes": {
      "origin": "Colombia"
    },
    "id": "bat_01M83PPH000000000000000001",
    "version": 1,
    "createdAt": "2026-11-23T08:00:00.000Z",
    "updatedAt": "2026-11-23T08:00:00.000Z"
  }
}
```

## List batches

`GET /batches`

Lists batches, optionally filtered by resource.

-   **Who may call:** Your server, with your project’s secret key.
-   **Credential:** the examples send your project’s `dev` secret key, `sk_test_…`, as `Authorization: Bearer <token>`.
-   **SDK:** `client.batches.list(query)`
-   **Pages:** `limit`, 1 to 500, default 100, with `next` and `after`. [Lists](/docs/platform/api-basics.md#lists) has the rule.

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `resourceId` | `string` | No | 1–256 characters. |
| `after` | `string` | No | 1–200 characters. |
| `limit` | `integer` | No | 1–500; default `100`. |

### Response

`200 OK`, with [`BatchesPage`](/docs/resourceshark/reference/batches.md#the-batchespage-object).

### Errors

-   [`invalid_request`](/docs/resourceshark/errors.md#invalid_request) (400)

Any operation can also answer with the codes [Conventions](/docs/resourceshark/reference.md#conventions) lists.

```bash tab="curl"
curl 'https://api.agentpost.tools/v1/resources/batches?resourceId=res_01M83PPH000000000000000001&limit=20' \
  -H "Authorization: Bearer sk_test_…"
```

```ts tab="SDK"
import { createClient } from '@agentpost-tools/resourceshark-sdk';

const client = createClient({ token: 'sk_test_…' });
const { batches } = await client.batches.list({
  resourceId: 'res_01M83PPH000000000000000001',
  limit: 20,
});
```

```json title="Response"
{
  "batches": [
    {
      "resourceId": "res_01M83PPH000000000000000001",
      "code": "ROAST-2026-11-23",
      "expiresAt": "2026-11-29T17:00:00.000Z",
      "attributes": {
        "origin": "Colombia"
      },
      "id": "bat_01M83PPH000000000000000001",
      "version": 2,
      "createdAt": "2026-11-23T08:00:00.000Z",
      "updatedAt": "2026-11-23T08:25:00.000Z"
    }
  ]
}
```

## Get a batch

`GET /batches/:id`

Reads a batch by ID.

-   **Who may call:** Your server, with your project’s secret key.
-   **Credential:** the examples send your project’s `dev` secret key, `sk_test_…`, as `Authorization: Bearer <token>`.
-   **SDK:** `client.batches.get(id)`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | Batch ID, `bat_…`. The `id` of a [`Batch`](/docs/resourceshark/reference/batches.md#the-batch-object). |

### Response

`200 OK`, with [`BatchResponse`](/docs/resourceshark/reference/batches.md#the-batchresponse-object).

### Errors

-   [`not_found`](/docs/resourceshark/errors.md#not_found) (404)

Any operation can also answer with the codes [Conventions](/docs/resourceshark/reference.md#conventions) lists.

```bash tab="curl"
curl https://api.agentpost.tools/v1/resources/batches/bat_01M83PPH000000000000000001 \
  -H "Authorization: Bearer sk_test_…"
```

```ts tab="SDK"
import { createClient } from '@agentpost-tools/resourceshark-sdk';

const client = createClient({ token: 'sk_test_…' });
const { batch } = await client.batches.get('bat_01M83PPH000000000000000001');
```

```json title="Response"
{
  "batch": {
    "resourceId": "res_01M83PPH000000000000000001",
    "code": "ROAST-2026-11-23",
    "expiresAt": "2026-11-29T17:00:00.000Z",
    "attributes": {
      "origin": "Colombia"
    },
    "id": "bat_01M83PPH000000000000000001",
    "version": 2,
    "createdAt": "2026-11-23T08:00:00.000Z",
    "updatedAt": "2026-11-23T08:25:00.000Z"
  }
}
```

## Update a batch

`PATCH /batches/:id`

Edits a batch and keeps its live supply in step with its expiry.

-   **Who may call:** Your server, with your project’s secret key.
-   **Credential:** the examples send your project’s `dev` secret key, `sk_test_…`, as `Authorization: Bearer <token>`.
-   **SDK:** `client.batches.patch(id, body, { ifMatch })`
-   **Idempotency-Key:** optional. [Retrying a write](/docs/platform/api-basics.md#retrying-a-write) has the rule.
-   **If-Match:** Required. Send the version you read.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | Batch ID, `bat_…`. The `id` of a [`Batch`](/docs/resourceshark/reference/batches.md#the-batch-object). |

### Body

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `resourceId` | `string` | No | 1–256 characters. |
| `code` | `string` | No | 1–200 characters. |
| `expiresAt` | `string` or `null` | No |  |
| `attributes` | `object` or `null` | No | Each value is a `string`. |

### Response

`200 OK`, with [`BatchResponse`](/docs/resourceshark/reference/batches.md#the-batchresponse-object).

### Errors

-   [`invalid_request`](/docs/resourceshark/errors.md#invalid_request) (400)
-   [`payload_too_large`](/docs/resourceshark/errors.md#payload_too_large) (413)
-   [`not_found`](/docs/resourceshark/errors.md#not_found) (404)
-   [`key_in_use`](/docs/resourceshark/errors.md#key_in_use) (409)
-   [`stale_version`](/docs/resourceshark/errors.md#stale_version) (409)

Any operation can also answer with the codes [Conventions](/docs/resourceshark/reference.md#conventions) lists.

```bash tab="curl"
curl -X PATCH https://api.agentpost.tools/v1/resources/batches/bat_01M83PPH000000000000000001 \
  -H "Authorization: Bearer sk_test_…" \
  -H "If-Match: 1" \
  -H "Content-Type: application/json" \
  -d '{
    "expiresAt": "2026-11-29T17:00:00.000Z"
  }'
```

```ts tab="SDK"
import { createClient } from '@agentpost-tools/resourceshark-sdk';

const client = createClient({ token: 'sk_test_…' });
const { batch } = await client.batches.patch(
  'bat_01M83PPH000000000000000001',
  { expiresAt: '2026-11-29T17:00:00.000Z' },
  { ifMatch: 1 },
);
```

```json title="Response"
{
  "batch": {
    "resourceId": "res_01M83PPH000000000000000001",
    "code": "ROAST-2026-11-23",
    "expiresAt": "2026-11-29T17:00:00.000Z",
    "attributes": {
      "origin": "Colombia"
    },
    "id": "bat_01M83PPH000000000000000001",
    "version": 2,
    "createdAt": "2026-11-23T08:00:00.000Z",
    "updatedAt": "2026-11-23T08:25:00.000Z"
  }
}
```

## The BatchResponse object

A batch read or returned from a write.

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `batch` | [`Batch`](/docs/resourceshark/reference/batches.md#the-batch-object) | Always |  |

```json title="The BatchResponse object"
{
  "batch": {
    "resourceId": "res_01M83PPH000000000000000001",
    "code": "ROAST-2026-11-23",
    "expiresAt": "2026-11-29T17:00:00.000Z",
    "attributes": {
      "origin": "Colombia"
    },
    "id": "bat_01M83PPH000000000000000001",
    "version": 2,
    "createdAt": "2026-11-23T08:00:00.000Z",
    "updatedAt": "2026-11-23T08:25:00.000Z"
  }
}
```

## The BatchesPage object

One page of batches, with the cursor for the next page when there is one.

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `batches` | [`Batch`](/docs/resourceshark/reference/batches.md#the-batch-object) array | Always |  |
| `next` | `string` | When set |  |

```json title="The BatchesPage object"
{
  "batches": [
    {
      "resourceId": "res_01M83PPH000000000000000001",
      "code": "ROAST-2026-11-23",
      "expiresAt": "2026-11-29T17:00:00.000Z",
      "attributes": {
        "origin": "Colombia"
      },
      "id": "bat_01M83PPH000000000000000001",
      "version": 2,
      "createdAt": "2026-11-23T08:00:00.000Z",
      "updatedAt": "2026-11-23T08:25:00.000Z"
    }
  ]
}
```

## The Batch object

The batch a resource’s supply can name.

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `id` | `string` | Always | Batch ID, `bat_…`. |
| `resourceId` | `string` | Always | Resource ID, `res_…`. |
| `code` | `string` | Always |  |
| `expiresAt` | `string` | When set | An ISO 8601 date and time. |
| `attributes` | `object` | When set | The business’s own labels. ResourceShark stores them and answers with them. Each value is a `string`. |
| `version` | `number` | Always |  |
| `createdAt` | `string` | Always | An ISO 8601 date and time. |
| `updatedAt` | `string` | Always | An ISO 8601 date and time. |

```json title="The Batch object"
{
  "resourceId": "res_01M83PPH000000000000000001",
  "code": "ROAST-2026-11-23",
  "expiresAt": "2026-11-29T17:00:00.000Z",
  "attributes": {
    "origin": "Colombia"
  },
  "id": "bat_01M83PPH000000000000000001",
  "version": 2,
  "createdAt": "2026-11-23T08:00:00.000Z",
  "updatedAt": "2026-11-23T08:25:00.000Z"
}
```
