Skip to main content

Worked Agentic Commerce samples

An AI shopping agent drives the four operations below in order: fetch the discovery manifest, browse the catalogue, build a cart, and complete checkout under the purchaser’s payment mandate. Substitute your storefront id (org_…) and issued mandate where shown. Successful requests below return raw ACP documents (not the { data, meta } envelope the authenticated Commerce API uses).

1. Catalogue browse

GET /api/v1/public/commerce/acp/{storefrontId}/feed
Return the merchant’s published catalogue. The items array is what the agent presents to the shopper.

2. Cart build

POST /api/v1/public/commerce/acp/{storefrontId}/checkout
Open a session with the agent’s requested items. Every price on the response is computed server-side against the stored catalogue, so a shopper-facing message tells you when a product was unknown, out of stock, or quantity-clamped.
Any line’s problem — unknown, out of stock, or clamped quantity — comes back in messages with type: "error" and a code you can surface to the shopper. Repeat a re-priced session through update, or replace items entirely with a POST to checkout/update.

3. Payment-token mint (AP2 mandate issue)

POST /api/v1/commerce/agent-mandate
A mandate is the scoped, spend-capped purchase authorization a principal hands the shopping agent. Issue it on the authenticated Commerce API (API key or session JWT), then hand the returned mandate snapshot to the agent for the pay step below. The completion endpoint only accepts a mandate inside its own scope — the ledger reference in the Commerce API reference describes issue, authorize, charge, verify, and revoke.

4. Checkout complete

POST /api/v1/public/commerce/acp/{storefrontId}/checkout/complete
The agent’s retirement of the mandate into a settled checkout. The signed request is verified before any priced line is evaluated; the response is a raw ACP receipt. Merchant-side order fulfilment subscribes to the commerce.payment_request.status_changed webhook event.
A 422 at completion carries the deny reason (“exceeds per-transaction cap”, “category not allowed”) so the agent can re-purchase against a corrected cart, not blind-retry the same request.