---
title: "ResourceShark API: Resources"
description: "Create a resource, list resources, get a resource, update a resource, or archive a resource, with the ResourceShark API."
url: "https://agentpost.tools/docs/resourceshark/reference/resources"
kind: reference
---

# Resources

Define what you count, how it is measured, and which scopes hold it. Read, edit, or archive a resource.

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 resource

`POST /resources`

Creates a resource under a key unique in the project. Send both scope flags, places and holders.

-   **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.resources.create(body)`
-   **Idempotency-Key:** optional. [Retrying a write](/docs/platform/api-basics.md#retrying-a-write) has the rule.

### Body

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `key` | `string` | Yes | 1–200 characters. |
| `name` | `string` | Yes | 1–200 characters. |
| `unit` | `object` | Yes |  |
| `unit.code` | `string` | Yes | 1–40 characters. |
| `unit.singular` | `string` | Yes | 1–80 characters. |
| `unit.plural` | `string` | Yes | 1–80 characters. |
| `unit.precision` | `integer` | Yes | 0–6. |
| `settings` | `object` | Yes |  |
| `settings.time` | `"none"` or `"buckets"` | Yes |  |
| `settings.bucket` | `object` | No |  |
| `settings.bucket.size` | `string` | Yes | One of `"step"`, `"day"`, or `"month"`. |
| `settings.bucket.stepMinutes` | `integer` | No | 1–1440. |
| `settings.bucket.timeZone` | `string` | Yes |  |
| `settings.identity` | `"count"` or `"instance"` | Yes |  |
| `settings.supplyExpiry` | `"none"` or `"expiring"` | Yes |  |
| `scope` | `object` | Yes |  |
| `scope.places` | `boolean` | Yes |  |
| `scope.holders` | `boolean` | Yes |  |
| `tracking` | `"none"` or `"batch"` | Yes |  |
| `shortage` | `string` | Yes | One of `"deny"`, `"backorder"`, or `"negative"`. |
| `capacity` | `number` | No |  |
| `tags` | `string[]` | No |  |
| `attributes` | `object` | No | Each value is a `string`. |
| `contentRef` | `string` | No | 1–256 characters. |
| `externalRef` | `string` | No | 1–256 characters. |

### Response

`201 Created`, with [`ResourceResponse`](/docs/resourceshark/reference/resources.md#the-resourceresponse-object).

### Errors

-   [`invalid_request`](/docs/resourceshark/errors.md#invalid_request) (400)
-   [`payload_too_large`](/docs/resourceshark/errors.md#payload_too_large) (413)
-   [`invalid_quantity`](/docs/resourceshark/errors.md#invalid_quantity) (422)
-   [`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/resources \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "key": "roasted-coffee",
    "name": "Roasted coffee",
    "unit": {
      "code": "g",
      "singular": "gram",
      "plural": "grams",
      "precision": 0
    },
    "settings": {
      "time": "none",
      "identity": "count",
      "supplyExpiry": "expiring"
    },
    "scope": {
      "places": true,
      "holders": false
    },
    "tracking": "batch",
    "shortage": "deny",
    "tags": [
      "coffee"
    ]
  }'
```

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

const client = createClient({ token: 'sk_test_…' });
const { resource } = await client.resources.create({
  key: 'roasted-coffee',
  name: 'Roasted coffee',
  unit: { code: 'g', singular: 'gram', plural: 'grams', precision: 0 },
  settings: { time: 'none', identity: 'count', supplyExpiry: 'expiring' },
  scope: { places: true, holders: false },
  tracking: 'batch',
  shortage: 'deny',
  tags: ['coffee'],
});
```

```json title="Response"
{
  "resource": {
    "key": "roasted-coffee",
    "name": "Roasted coffee",
    "unit": {
      "code": "g",
      "singular": "gram",
      "plural": "grams",
      "precision": 0
    },
    "settings": {
      "time": "none",
      "identity": "count",
      "supplyExpiry": "expiring"
    },
    "scope": {
      "places": true,
      "holders": false
    },
    "tracking": "batch",
    "shortage": "deny",
    "tags": ["coffee"],
    "id": "res_01M83PPH000000000000000001",
    "version": 1
  }
}
```

## List resources

`GET /resources`

Lists active resources, optionally filtered by tag, key, or both.

-   **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.resources.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 |
| --- | --- | --- | --- |
| `after` | `string` | No | 1–200 characters. |
| `limit` | `integer` | No | 1–500; default `100`. |
| `key` | `string` | No | 1–200 characters. |
| `tag` | `string` | No | 1–200 characters. |

### Response

`200 OK`, with [`ResourcesPage`](/docs/resourceshark/reference/resources.md#the-resourcespage-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/resources?tag=coffee&limit=20' \
  -H "Authorization: Bearer sk_test_…"
```

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

const client = createClient({ token: 'sk_test_…' });
const { resources } = await client.resources.list({ tag: 'coffee', limit: 20 });
```

```json title="Response"
{
  "resources": [
    {
      "key": "roasted-coffee",
      "name": "Juniper roasted coffee",
      "unit": {
        "code": "g",
        "singular": "gram",
        "plural": "grams",
        "precision": 0
      },
      "settings": {
        "time": "none",
        "identity": "count",
        "supplyExpiry": "expiring"
      },
      "scope": {
        "places": true,
        "holders": false
      },
      "tracking": "batch",
      "shortage": "deny",
      "tags": ["coffee"],
      "id": "res_01M83PPH000000000000000001",
      "version": 2
    },
    {
      "key": "green-coffee",
      "name": "Green coffee",
      "unit": {
        "code": "g",
        "singular": "gram",
        "plural": "grams",
        "precision": 0
      },
      "settings": {
        "time": "none",
        "identity": "count",
        "supplyExpiry": "none"
      },
      "scope": {
        "places": true,
        "holders": false
      },
      "tracking": "none",
      "shortage": "deny",
      "tags": ["coffee"],
      "id": "res_01M83PPH000000000000000002",
      "version": 1
    }
  ]
}
```

## Get a resource

`GET /resources/:id`

Reads a resource by ID, including an archived 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.resources.get(id)`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | Resource ID, `res_…`. The `id` of a [`Resource`](/docs/resourceshark/reference/resources.md#the-resource-object). |

### Response

`200 OK`, with [`ResourceResponse`](/docs/resourceshark/reference/resources.md#the-resourceresponse-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/resources/res_01M83PPH000000000000000001 \
  -H "Authorization: Bearer sk_test_…"
```

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

const client = createClient({ token: 'sk_test_…' });
const { resource } = await client.resources.get(
  'res_01M83PPH000000000000000001',
);
```

```json title="Response"
{
  "resource": {
    "key": "roasted-coffee",
    "name": "Juniper roasted coffee",
    "unit": {
      "code": "g",
      "singular": "gram",
      "plural": "grams",
      "precision": 0
    },
    "settings": {
      "time": "none",
      "identity": "count",
      "supplyExpiry": "expiring"
    },
    "scope": {
      "places": true,
      "holders": false
    },
    "tracking": "batch",
    "shortage": "deny",
    "tags": ["coffee"],
    "id": "res_01M83PPH000000000000000001",
    "version": 2
  }
}
```

## Update a resource

`PATCH /resources/:id`

Edits an active resource at the version in If-Match. The first supply, stock write, claim, schedule save, or exception save locks the settings, unit code and precision, scope, and tracking. A change to a bucketed resource’s capacity lands whatever is already held or taken, and answers with overCapacity: the buckets now over it, with the claims in each.

-   **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.resources.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 | Resource ID, `res_…`. The `id` of a [`Resource`](/docs/resourceshark/reference/resources.md#the-resource-object). |

### Body

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `key` | `string` | No | 1–200 characters. |
| `name` | `string` | No | 1–200 characters. |
| `unit` | `object` | No |  |
| `unit.code` | `string` | No | 1–40 characters. |
| `unit.singular` | `string` | No | 1–80 characters. |
| `unit.plural` | `string` | No | 1–80 characters. |
| `unit.precision` | `integer` | No | 0–6. |
| `settings` | `object` | No |  |
| `settings.time` | `"none"` or `"buckets"` | No |  |
| `settings.bucket` | `object` or `null` | No |  |
| `settings.identity` | `"count"` or `"instance"` | No |  |
| `settings.supplyExpiry` | `"none"` or `"expiring"` | No |  |
| `scope` | `object` | No |  |
| `scope.places` | `boolean` | No |  |
| `scope.holders` | `boolean` | No |  |
| `tracking` | `"none"` or `"batch"` | No |  |
| `shortage` | `string` | No | One of `"deny"`, `"backorder"`, or `"negative"`. |
| `capacity` | `number` or `null` | No |  |
| `tags` | `string[]` | No |  |
| `attributes` | `object` or `null` | No | Each value is a `string`. |
| `contentRef` | `string` or `null` | No |  |
| `externalRef` | `string` or `null` | No |  |

### Response

`200 OK`, with [`ResourceResponse`](/docs/resourceshark/reference/resources.md#the-resourceresponse-object).

### Errors

-   [`invalid_request`](/docs/resourceshark/errors.md#invalid_request) (400)
-   [`payload_too_large`](/docs/resourceshark/errors.md#payload_too_large) (413)
-   [`invalid_quantity`](/docs/resourceshark/errors.md#invalid_quantity) (422)
-   [`key_in_use`](/docs/resourceshark/errors.md#key_in_use) (409)
-   [`not_found`](/docs/resourceshark/errors.md#not_found) (404)
-   [`stale_version`](/docs/resourceshark/errors.md#stale_version) (409)
-   [`settings_locked`](/docs/resourceshark/errors.md#settings_locked) (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/resources/res_01M83PPH000000000000000001 \
  -H "Authorization: Bearer sk_test_…" \
  -H "If-Match: 1" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Juniper roasted coffee"
  }'
```

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

const client = createClient({ token: 'sk_test_…' });
const { resource } = await client.resources.patch(
  'res_01M83PPH000000000000000001',
  { name: 'Juniper roasted coffee' },
  { ifMatch: 1 },
);
```

```json title="Response"
{
  "resource": {
    "key": "roasted-coffee",
    "name": "Juniper roasted coffee",
    "unit": {
      "code": "g",
      "singular": "gram",
      "plural": "grams",
      "precision": 0
    },
    "settings": {
      "time": "none",
      "identity": "count",
      "supplyExpiry": "expiring"
    },
    "scope": {
      "places": true,
      "holders": false
    },
    "tracking": "batch",
    "shortage": "deny",
    "tags": ["coffee"],
    "id": "res_01M83PPH000000000000000001",
    "version": 2
  }
}
```

## Archive a resource

`POST /resources/:id/archive`

Archives a resource, keeping its key and making it read-only.

-   **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.resources.archive(id)`
-   **Idempotency-Key:** optional. [Retrying a write](/docs/platform/api-basics.md#retrying-a-write) has the rule.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | Resource ID, `res_…`. The `id` of a [`Resource`](/docs/resourceshark/reference/resources.md#the-resource-object). |

### Response

`200 OK`, with [`ResourceResponse`](/docs/resourceshark/reference/resources.md#the-resourceresponse-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 -X POST https://api.agentpost.tools/v1/resources/resources/res_01M83PPH000000000000000002/archive \
  -H "Authorization: Bearer sk_test_…"
```

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

const client = createClient({ token: 'sk_test_…' });
const { resource } = await client.resources.archive(
  'res_01M83PPH000000000000000002',
);
```

```json title="Response"
{
  "resource": {
    "key": "green-coffee",
    "name": "Green coffee",
    "unit": {
      "code": "g",
      "singular": "gram",
      "plural": "grams",
      "precision": 0
    },
    "settings": {
      "time": "none",
      "identity": "count",
      "supplyExpiry": "none"
    },
    "scope": {
      "places": true,
      "holders": false
    },
    "tracking": "none",
    "shortage": "deny",
    "tags": ["coffee"],
    "id": "res_01M83PPH000000000000000002",
    "version": 2,
    "archivedAt": "2026-11-27T17:00:00.000Z"
  }
}
```

## The ResourceResponse object

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `resource` | [`Resource`](/docs/resourceshark/reference/resources.md#the-resource-object) | Always |  |
| `overCapacity` | [`OverCapacity`](/docs/resourceshark/reference/resources.md#the-overcapacity-object) | When set | With a change to a bucketed resource’s `capacity`: the buckets now over it. |

```json title="The ResourceResponse object"
{
  "resource": {
    "key": "roasted-coffee",
    "name": "Juniper roasted coffee",
    "unit": {
      "code": "g",
      "singular": "gram",
      "plural": "grams",
      "precision": 0
    },
    "settings": {
      "time": "none",
      "identity": "count",
      "supplyExpiry": "expiring"
    },
    "scope": {
      "places": true,
      "holders": false
    },
    "tracking": "batch",
    "shortage": "deny",
    "tags": ["coffee"],
    "id": "res_01M83PPH000000000000000001",
    "version": 2
  }
}
```

## The ResourcesPage object

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

```json title="The ResourcesPage object"
{
  "resources": [
    {
      "key": "roasted-coffee",
      "name": "Juniper roasted coffee",
      "unit": {
        "code": "g",
        "singular": "gram",
        "plural": "grams",
        "precision": 0
      },
      "settings": {
        "time": "none",
        "identity": "count",
        "supplyExpiry": "expiring"
      },
      "scope": {
        "places": true,
        "holders": false
      },
      "tracking": "batch",
      "shortage": "deny",
      "tags": ["coffee"],
      "id": "res_01M83PPH000000000000000001",
      "version": 2
    },
    {
      "key": "green-coffee",
      "name": "Green coffee",
      "unit": {
        "code": "g",
        "singular": "gram",
        "plural": "grams",
        "precision": 0
      },
      "settings": {
        "time": "none",
        "identity": "count",
        "supplyExpiry": "none"
      },
      "scope": {
        "places": true,
        "holders": false
      },
      "tracking": "none",
      "shortage": "deny",
      "tags": ["coffee"],
      "id": "res_01M83PPH000000000000000002",
      "version": 1
    }
  ]
}
```

## The Resource object

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `key` | `string` | Always | 1–200 characters. |
| `name` | `string` | Always | 1–200 characters. |
| `unit` | `object` | Always |  |
| `unit.code` | `string` | Always | 1–40 characters. |
| `unit.singular` | `string` | Always | 1–80 characters. |
| `unit.plural` | `string` | Always | 1–80 characters. |
| `unit.precision` | `integer` | Always | 0–6. |
| `settings` | `object` | Always |  |
| `settings.time` | `"none"` or `"buckets"` | Always |  |
| `settings.bucket` | `object` | When set |  |
| `settings.bucket.size` | `string` | Always | One of `"step"`, `"day"`, or `"month"`. |
| `settings.bucket.stepMinutes` | `integer` | When set | 1–1440. |
| `settings.bucket.timeZone` | `string` | Always |  |
| `settings.identity` | `"count"` or `"instance"` | Always |  |
| `settings.supplyExpiry` | `"none"` or `"expiring"` | Always |  |
| `scope` | `object` | Always |  |
| `scope.places` | `boolean` | Always |  |
| `scope.holders` | `boolean` | Always |  |
| `tracking` | `"none"` or `"batch"` | Always |  |
| `shortage` | `string` | Always | One of `"deny"`, `"backorder"`, or `"negative"`. |
| `tags` | `string[]` | Always |  |
| `attributes` | `object` | When set | Each value is a `string`. |
| `contentRef` | `string` | When set | 1–256 characters. |
| `externalRef` | `string` | When set | 1–256 characters. |
| `id` | `string` | Always | Resource ID, `res_…`. |
| `capacity` | `number` | When set | An integer in the resource’s base unit at its precision, as money is in cents: grams at precision 0, meters at precision 2, so 1 is 1 cm. A quantity with a fraction is refused with `invalid_quantity`. |
| `version` | `number` | Always |  |
| `archivedAt` | `string` | When set | An ISO 8601 date and time. |

```json title="The Resource object"
{
  "key": "roasted-coffee",
  "name": "Juniper roasted coffee",
  "unit": {
    "code": "g",
    "singular": "gram",
    "plural": "grams",
    "precision": 0
  },
  "settings": {
    "time": "none",
    "identity": "count",
    "supplyExpiry": "expiring"
  },
  "scope": {
    "places": true,
    "holders": false
  },
  "tracking": "batch",
  "shortage": "deny",
  "tags": ["coffee"],
  "id": "res_01M83PPH000000000000000001",
  "version": 2
}
```

## The OverCapacity object

What a change that moves capacity leaves over it, in buckets that have not ended, nearest first. `more` is true when there may be more than the answer lists: past `MAX_OVER_CAPACITY_BUCKETS` buckets or `MAX_OVER_CAPACITY_CLAIMS` claims, or past the nearest 1,000 buckets a claim has touched. `GET /slots` and `GET /claims` over a range read the rest.

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `buckets` | [`OverCapacityBucket`](/docs/resourceshark/reference/resources.md#the-overcapacitybucket-object) array | Always |  |
| `more` | `boolean` | Always |  |

```json title="The OverCapacity object"
{
  "buckets": [
    {
      "span": {
        "start": "2026-11-23T18:00:00.000Z",
        "end": "2026-11-23T19:00:00.000Z"
      },
      "scope": {
        "instanceId": "ins_01M83PPH000000000000000001"
      },
      "capacity": 0,
      "taken": 1,
      "held": 0,
      "claims": [
        {
          "id": "clm_01M83PPH000000000000000004",
          "kind": "booking",
          "status": "committed",
          "quantity": 1,
          "holdId": "hld_01M83PPH000000000000000002",
          "holderRef": "principal:external:u_maya"
        }
      ]
    }
  ],
  "more": false
}
```

## The OverCapacityBucket object

A bucket where what is held and taken is more than its capacity.

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `span` | [`FiniteSpan`](/docs/resourceshark/reference/schedules.md#the-finitespan-object) | Always |  |
| `scope` | [`Scope`](/docs/resourceshark/reference/supply.md#the-scope-object) | Always |  |
| `capacity` | `number` | Always | An integer in the resource’s base unit at its precision, as money is in cents: grams at precision 0, meters at precision 2, so 1 is 1 cm. A quantity with a fraction is refused with `invalid_quantity`. |
| `taken` | `number` | Always | What bookings took. |
| `held` | `number` | Always | What holds not past their expiry hold. |
| `claims` | [`OverCapacityClaim`](/docs/resourceshark/reference/resources.md#the-overcapacityclaim-object) array | Always | Every claim in it, so your app can choose which to move, release, or cancel. |

```json title="The OverCapacityBucket object"
{
  "span": {
    "start": "2026-11-23T18:00:00.000Z",
    "end": "2026-11-23T19:00:00.000Z"
  },
  "scope": {
    "instanceId": "ins_01M83PPH000000000000000001"
  },
  "capacity": 0,
  "taken": 1,
  "held": 0,
  "claims": [
    {
      "id": "clm_01M83PPH000000000000000004",
      "kind": "booking",
      "status": "committed",
      "quantity": 1,
      "holdId": "hld_01M83PPH000000000000000002",
      "holderRef": "principal:external:u_maya"
    }
  ]
}
```

## The OverCapacityClaim object

One claim in a bucket over capacity.

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `id` | `string` | Always | Claim ID, `clm_…`. |
| `kind` | `string` | Always | One of `"hold"`, `"consumption"`, or `"booking"`. |
| `status` | `string` | Always | `held` or `committed`. One of `"held"`, `"committed"`, `"released"`, `"expired"`, or `"cancelled"`. |
| `quantity` | `number` | Always | What it holds, or what it took. |
| `holdId` | `string` | When set | Hold ID, `hld_…`. |
| `holderRef` | `string` | When set | Your app’s name for the holder, such as `principal:external:u_maya`. |

```json title="The OverCapacityClaim object"
{
  "id": "clm_01M83PPH000000000000000004",
  "kind": "booking",
  "status": "committed",
  "quantity": 1,
  "holdId": "hld_01M83PPH000000000000000002",
  "holderRef": "principal:external:u_maya"
}
```
