Catalog purchases are in beta. A field can still change before the API is final.
What you need
- Your company’s
client_idandclient_secret, exchanged for an access token (Create an access token). Agentcard refuses an API key when you create, answer or cancel a purchase. Your company’s API key reads a purchase too. - The person connected to your app with a card in their Vault (Adding a card).
- Catalog purchases turned on for your company. Ask Agentcard to turn them on.
- Commerce billing set up in the dashboard, for live purchases.
- A Channel3 API key, to search Channel3’s catalog (Channel3’s docs). A purchase that names the store’s own product page needs no Channel3 key.
Find the product
Search Channel3’s catalog with your Channel3 key:products. Three parts of the product your agent picks become the purchase:
Agentcard reads
options against the labels Channel3 lists for the product at that store. A value the store does not list comes back as a question for you to answer, and so does a size that sold out while others are in stock, as Answer the store shows. To read one product again with each store’s current price and stock, call Channel3’s GET /v1/products/{id}.
Each offer also carries a url, which is Channel3’s buy link. Agentcard refuses a Channel3 link in url:
id and the offer’s domain instead.
Create the purchase
Send the product, the store and the person it is for, with anIdempotency-Key you keep when you retry the same purchase. The answer comes back at once, with the purchase building its cart:
A store’s own product page works in place of
catalog.items. Send the page as url, with its options and quantity beside it, and Agentcard finds the product in Channel3’s catalog:
catalog.items or url, never both. One purchase buys at one store. At a store Agentcard orders from directly, one purchase holds up to 10 products. At a store whose own checkout page Agentcard fills in, one purchase holds one product. A product_id with no store buys the cheapest offer in stock at a store Agentcard can order from.
Send an Idempotency-Key header with each create. A retry with the same body, the same credentials and the same mode within 24 hours gets the first answer back instead of making another purchase. Agentcard keeps refusals too, so use a new key once you correct the body: Agentcard refuses the same key with a changed body as idempotency_key_reused. Agentcard refuses a retry while the first request still runs as idempotency_key_in_flight; wait, and retry with the same key. After 24 hours the key expires, and reusing it can make another purchase.
Follow the purchase
Read where the purchase stands at any time:Read why a purchase failed
A failed purchase carriesfailure.code and failure.message. These codes come from Channel3’s catalog or the store:
Any other
failure.code comes with a failure.message that says why.
Answer the store
A purchase inneeds_input carries the store’s question in input. Here the size the person chose sold out, and the store still has two others:
For a
contact question, input.field reads email, phone or name. Answer a name with first_name and last_name in user_details.
A delivery address names the street, the city, a two-letter state or province code, and a US ZIP or ZIP+4 or a Canadian postal code. The name, a second address line, a two-letter country code and the phone are optional:
delivery_address on the create takes the same fields.
A card question for a sandbox person carries no input.url, because the add-a-card link is a live one. Open a Vault session for them with POST /api/v2/vault_sessions, as Adding a card shows, and send {} once they saved a card.
Agentcard refuses an answer that leaves out what the store asked, and the question stays open:
expired.
Send the approval link
A purchase inawaiting_approval carries the cart, the store’s total, and the approval link:
approvalUrl right away. They see the store and the total, and approve with their passkey. approval_expires_at says when the link stops working; after that the purchase ends expired. When the store may authorize more than its total, amount is that larger figure and cart.total_cents is what the person pays.
Hear each step
Subscribe your webhook endpoint topurchase.message or purchase.* in the purchase’s mode. A catch-all * alone does not turn these messages on.
Agentcard tells your company about each step as a purchase.message event. The step is in the event’s data: data.facts.authorization_id names the purchase, and data.text is ready to send to the person as it is:
data.note is the same step written for your own agent to read.
Drop an event that arrives after its
data.facts.valid_until: its link no longer works.
Cancel a purchase
Cancel a purchase the person has not approved yet:cancelled, and an approval link already sent stops working. Once the person approved, or the purchase ended, Agentcard refuses the cancel and the purchase goes on as it stands:
building_cart, because the store can take the order at once. Agentcard refuses that cancel too, and the purchase goes on to its order:
Fix a refusal
A create that Agentcard refuses makes nothing. Each refusal names what to change:Idempotency-Key:
Test in sandbox
Your sandbox credentials make sandbox purchases. Agentcard builds the cart at the store and the approval opens as it does live, and after the person approves the purchase endsapproved with no order placed and nothing charged. Stores Agentcard orders from directly take live purchases only. A sandbox credential never reads, cancels or answers a live purchase.
Know the limits
- One purchase buys at one store, with one product at a store whose checkout page Agentcard fills in.
- A purchase never takes an amount: the amount is always the store’s own total.
- A cart that takes long to build leaves the person less time to approve.
approval_expires_atalways says how long.