Skip to content
Agentpost robot in sunglasses on a red circleAgentpost

Supply

Record, read, and take back supply that is on hand or due.

Paths are relative to https://api.agentpost.tools/v1/resources. Who may call explains each credential.

Add supply

POST /supply

Adds on-hand or expected supply. An added entry is on hand from its validFrom, or as it lands when that is unset or not after now, until its expiresAt; every take, hold, and read honors those times whether or not anything has written its movement yet. An added entry can fulfil an expected entry. On a resource with identity: instance, an entry adds the one unit its scope names, which must not be on hand or due anywhere else. A repeat under a sourceKey already used on the resource answers with the first result.

  • 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.supply.create(body, { idempotencyKey })
  • Idempotency-Key: required. Retrying a write has the rule.

Body

Name Type Required Description
resourceId string Yes 1–256 characters.
scope object No
scope.placeId string No
scope.condition string No 1–64 characters.
scope.holderRef string No 1–256 characters.
scope.instanceId string No
kind "added" or "expected" Yes
quantity number Yes
validFrom string No An ISO 8601 date and time.
expiresAt string No An ISO 8601 date and time.
drawOrder integer No
batchId string No 1–256 characters.
fulfils string No 1–256 characters.
attributes object No Each value is a string.
evidence object Yes
evidence.kind string Yes 1–256 characters.
evidence.ref string Yes 1–256 characters.
sourceKey string Yes 1–200 characters.
batch object No
batch.code string Yes 1–200 characters.
batch.expiresAt string No An ISO 8601 date and time.
batch.attributes object No Each value is a string.

Response

201 Created, with SupplyResponse.

Errors

Any operation can also answer with the codes Conventions lists.

List supply

GET /supply

Lists supply entries, optionally filtered by resource, holder, batch, or status. A caller constrained to one holder lists only its own.

  • Who may call: Your server, with your project’s secret key or a signed-in principal, with a user token for their own principal:<principal> holder.
  • Credential: the examples send your project’s dev secret key, sk_test_…, as Authorization: Bearer <token>.
  • SDK: client.supply.list(query)
  • Pages: limit, 1 to 500, default 100, with next and after. Lists has the rule.

Query parameters

Name Type Required Description
resourceId string No 1–256 characters.
holderRef string No 1–256 characters.
batchId string No 1–256 characters.
status string No One of "pending", "active", "exhausted", "expired", or "reversed".
after string No 1–200 characters.
limit integer No 1–500; default 100.

Response

200 OK, with SupplyPage.

Errors

Any operation can also answer with the codes Conventions lists.

Get a supply entry

GET /supply/:id

Reads a supply entry. A caller constrained to one holder reads only its own.

  • Who may call: Your server, with your project’s secret key or a signed-in principal, with a user token for their own principal:<principal> holder.
  • Credential: the examples send your project’s dev secret key, sk_test_…, as Authorization: Bearer <token>.
  • SDK: client.supply.get(id)

Path parameters

Name Type Required Description
id string Yes Supply ID, sup_…. The id of a SupplyEntry.

Response

200 OK, with SupplyGetResponse.

Errors

Any operation can also answer with the codes Conventions lists.

Reverse supply

POST /supply/:id/reverse

Takes the requested quantity back from a supply entry in a reversal movement. On added supply that has not started, cancels that much of what would start, with no movement. If less is available than requested, the refusal gives the available quantity. A repeat under a sourceKey already used on the resource answers with the first result.

  • 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.supply.reverse(id, body, { idempotencyKey })
  • Idempotency-Key: required. Retrying a write has the rule.

Path parameters

Name Type Required Description
id string Yes Supply ID, sup_…. The id of a SupplyEntry.

Body

Name Type Required Description
quantity number Yes
evidence object Yes
evidence.kind string Yes 1–256 characters.
evidence.ref string Yes 1–256 characters.
sourceKey string Yes 1–200 characters.

Response

200 OK, with SupplyReverseResponse.

Errors

Any operation can also answer with the codes Conventions lists.

The SupplyResponse object

What a supply write recorded, with its movement when there is one.

Name Type Present Description
supply SupplyEntry Always
movement Movement When set The movement that recorded what arrived or is expected.
duplicate true When set Set when the sourceKey already named this request: nothing was added again.

The SupplyPage object

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

Name Type Present Description
supply SupplyEntry array Always
next string When set

The SupplyGetResponse object

The supply entry read by ID.

Name Type Present Description
supply SupplyEntry Always

The SupplyReverseResponse object

What a supply reversal took back.

Name Type Present Description
supply SupplyEntry Always
movement Movement When set The reversal movement, absent when the entry had not started.
taken number Always What was taken back.
duplicate true When set Set when the sourceKey already named this request: nothing was taken again.

The SupplyEntry object

What arrived or is expected, and what remains of it.

Name Type Present Description
id string Always Supply ID, sup_….
resourceId string Always Resource ID, res_….
scope Scope Always The scope it was added to.
kind string Always One of "added", "expected", or "output".
quantity 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.
remaining number Always What is free to take when pegging applies. Together with held, it is what the entry still has. For expected supply it is what is still due; for added supply that has not started, what will be on hand when it does; and otherwise it is the quantity the entry was made with. Where the balance owed something when the entry became on hand, what paid it is not remaining: one whose start has come reads so whether or not anything has landed it.
held number Always What open holds have pegged here, or zero when pegging does not apply.
fulfils string When set The expected entry this added entry fulfils.
validFrom string When set For expected supply, when it is due. For added supply, when it starts: set when it was added to start later than it landed.
expiresAt string When set When what it has left stops being on hand.
batchId string When set Batch ID, bat_….
attributes object When set The business’s own labels for this entry. ResourceShark stores them and answers with them. Each value is a string.
drawOrder number When set Lower numbers are drawn first; a missing value counts as 0.
evidence Evidence Always
sourceKey string Always
actor PrincipalRef Always
onBehalfOf PrincipalRef When set
status string Always One of "pending", "active", "exhausted", "expired", or "reversed".
createdAt string Always An ISO 8601 date and time.

The Movement object

The history of one change to a balance.

Name Type Present Description
quantity 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.
before 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.
after 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.
id string Always Movement ID, mov_….
seq number Always The project’s movement sequence: every movement in the project, in the order they committed.
resourceId string Always Resource ID, res_….
scope Scope Always
bucketStart string When set The bucket it moved, for a resource whose time is counted in buckets.
held QuantityChange When set How held moved, when it did.
expected QuantityChange When set
owed object When set How what the balance owes moved, when it did. On a take, what its pegs don’t cover was owed. On an add, what paid it down left the entry at once, so the entry keeps the rest.
owed.quantity 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.
owed.before 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.
owed.after 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.
owed.pegs Peg array When set The supply entries whose units paid it down, and how much each paid. What came down without them was a claim’s own debt given back.
reason string Always One of "add", "expected", "hold", "release", "expire_hold", "commit", "use", "settle", "transfer", "count", "adjustment", "reversal", "convert_in", "convert_out", "expire_supply", "cancel", or "capacity".
supplyId string When set Supply ID, sup_….
pegs Peg array When set The supply entries it drew from or returned to.
batchId string When set Set when everything it moved was from or for the same batch.
transformationId string When set The conversion this movement was part of.
claimId string When set Claim ID, clm_….
holdId string When set Hold ID, hld_….
transferId string When set Transfer ID, trf_….
reversesId string When set Movement ID, mov_….
evidence Evidence When set
note string When set
actor PrincipalRef Always The principal that made the change with its own credential. Your project’s secret key is key: and the key’s name, with no kind; ResourceShark’s own changes are the service principal resourceshark.
onBehalfOf PrincipalRef When set The delegator, when the actor acted under a delegation.
at string Always An ISO 8601 date and time.

The Scope object

Where a quantity sits. Each resource says which dimensions apply: stock has places, prepaid credits have holders, and a resource with identity: instance has units. A resource kept by place requires a placeId and can carry a free-form condition label. Omitting the condition selects the unlabeled balance. A resource that tells its units apart requires an instanceId: each unit has a balance of its own, in one place and under one label at a time, and a line on it moves one unit.

Name Type Present Description
placeId string When set Place ID, plc_….
condition string When set
holderRef string When set Your app’s name for the holder, such as principal:external:u_maya.
instanceId string When set Instance ID, ins_….

The Evidence object

What a change was made for, such as { kind: "order", ref: "ord_…" }.

Name Type Present Description
kind string Always
ref string Always An opaque reference to another system’s record, such as ord_01J…. ResourceShark stores it and answers with it.

The PrincipalRef object

A principal that acted, with the kind it declared for itself.

Name Type Present Description
kind string When set The kind a principal may declare. A principal that declared none has no kind. One of "human", "agent", or "service".
id string Always

The QuantityChange object

How one of a balance’s quantities moved: signed, with the value before and after.

Name Type Present Description
quantity 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.
before 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.
after 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.

The Peg object

How much a claim or movement drew from one supply entry.

Name Type Present Description
supplyId string Always Supply ID, sup_….
quantity 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.