Skip to content
Agentpost robot in sunglasses on a red circleAgentpost

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 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 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.

Errors

Any operation can also answer with the codes Conventions lists.

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 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.

Errors

Any operation can also answer with the codes Conventions lists.

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.

Response

200 OK, with ResourceResponse.

Errors

Any operation can also answer with the codes Conventions lists.

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 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.

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.

Errors

Any operation can also answer with the codes Conventions lists.

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 has the rule.

Path parameters

Name Type Required Description
id string Yes Resource ID, res_…. The id of a Resource.

Response

200 OK, with ResourceResponse.

Errors

Any operation can also answer with the codes Conventions lists.

The ResourceResponse object

Name Type Present Description
resource Resource Always
overCapacity OverCapacity When set With a change to a bucketed resource’s capacity: the buckets now over it.

The ResourcesPage object

Name Type Present Description
resources Resource array Always
next string When set

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.

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 array Always
more boolean Always

The OverCapacityBucket object

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

Name Type Present Description
span FiniteSpan Always
scope Scope 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 array Always Every claim in it, so your app can choose which to move, release, or cancel.

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.