Spend is in preview. Contact Ionic to enable it for your platform.
What your platform builds
- A mapping from each of your customers to their Ionic business, and secure storage for your agent’s keys.
- A purchase job that stores the cart, amount, currency, checkout URL, and billing details the owner approves.
- Links to Ionic’s card setup and approval pages, and a way to pause the job while the owner decides.
- A trusted browser worker that uses the returned proxy, enters the card, and submits checkout.
- A lock so only one worker submits each purchase, and a record of the seller’s result.
Set up the business and agent
Your platform needs an active connection to the business, and your Platform Program and the connection must allowspend:read and spend:write. Your agent
needs approved access to that business and an agent secret key with the same
permissions.
Send the business’s mer_… ID in Ionic-Account on every request.
Use your platform’s secret key for setup sessions, and the agent’s key for
cards and spend intents. Only the owner can approve a purchase.
Keep keys on your server. Store the business, agent, and grant IDs with each
purchase job, so a replacement worker continues under the same access.
Add a card
Create a setup session from your server withPOST /v1/spend/setup_sessions,
using spend:write, Ionic-Account, and an Idempotency-Key. The body can be
{}, or include a label and a return_url. The return_url must be an HTTPS
URL on one of your platform’s approved origins, with no query string or
fragment. Otherwise the request fails with 400 invalid_return_url.
Send the returned url privately to an owner of the business. They sign in and
add the card on the Ionic page. The session expires after 30 minutes.
To confirm setup, retrieve the session with GET /v1/spend/setup_sessions/{id}.
Setup is complete when status is completed and card_id is set. Don’t treat
a visit to your return_url as confirmation.
If setup expires, create a new session with a new idempotency key. Don’t retry
setup_session_expired (422) or setup_access_denied (403).
Get access to the card
After setup, the owner gives your agent access to the card in the Ionic dashboard. Share Manage cards and agent purchases with them for the steps. Your agent then sees the card inGET /v1/spend/cards. An empty list
means the agent has no card access yet.
Request approval for a purchase
Create a spend intent withPOST /v1/spend_intents. Store the
Idempotency-Key before you send the request, and retry with the same key and
body. Every Spend POST takes Content-Type: application/json and an
Idempotency-Key of 16 to 255 printable ASCII characters with no spaces.
This request asks to spend $60.00. Replace the card ID, checkout URL, and
allowed_hosts with your own.
amountis in the smallest currency unit.checkout_urlmust use HTTPS, with no query string, fragment, user information, or port.allowed_hostsis required. List the exact hosts where your worker submits card fields. They’re fixed when the owner approves, and redirects don’t add hosts. Payment frames often use a different host from the checkout page, so include it.
approval_url. They review the seller, amount, purpose, and claim window. A
spending limit can require your platform’s approval before the business
decides. The request stays pending_approval until every approval in
approvals is complete.
A request that breaks a limit set to block fails with 422 limit_exceeded, and
the spend intent is saved as blocked. Don’t retry it. If your SDK doesn’t
return the spend intent with the error, find it by reference with
GET /v1/spend_intents.
Set agent limits
Limits cap how much card access an agent can be approved for. Your platform and each business set their own, and every active limit applies. For each rule, the smallest value wins.
A limit covers one agent and one currency, with up to 10 rules:
Windows are rolling and count usage at one business, even for your platform’s
limits. Usage is the card access approved, not the amount the seller charged.
Each rule sets what happens when a request goes over it:
- Ask for approval: the request stays
pending_approvaland lists the rule inlimit_breaches. When your platform’s rule is exceeded, your platform approves first, and the business decides last. If more card access is approved before the last decision, Ionic checks the request again. - Block: the request fails with
422 limit_exceeded, and no one can approve it.
422 currency_not_allowed. With no limits set, the business still
approves every request.
Owners create, change, and archive limits, and admins can view them. Each
party sees the other’s limits but can change only its own. Archiving is
permanent; create a new limit to set rules again.
Wait for approval
Subscribe tospend_intent.updated with your platform’s
connected-account webhooks. Verify the signature,
skip event IDs you’ve already processed, and match the business and spend
intent to your job. Ionic sends events for your agent’s requests only to your
platform.
Before checkout, retrieve the spend intent with GET /v1/spend_intents/{id}.
If webhooks aren’t available, poll that endpoint with backoff. Don’t poll the
claim endpoint. Stop the job if the status is blocked, declined,
canceled, or expired.
The owner has 24 hours to approve. After approval, claim before
claim_expires_at. The claim window defaults to five minutes, and a longer
window returns claim_window_unsupported.
Claim the card in your browser worker
When the worker reaches card entry, take the job’s lock and retrieve the spend intent again. Then callPOST /v1/spend_intents/{id}/claim with {}, a claim
Idempotency-Key stored with the job, and the same agent key and business.
The response contains card, billing_details, proxy, allowed_hosts,
browser_requirements, and expires_at:
- Set the browser’s HTTPS proxy to the returned host, port, username, and password.
- Trust the returned certificate authority, and keep TLS certificate and hostname checks on.
- If
browser_requirements.reload_payment_pageistrue, reload the payment page. - Enter the returned card number, expiry, holder name, and security code at
checkout.
cvcis empty when the checkout doesn’t need one.
allowed_hosts. Your browser
provider must support authenticated HTTPS proxies and a custom certificate
authority.
Keep the response in the worker’s memory only. Never put it in model prompts,
logs, analytics, screenshots, browser traces, recordings, or stored job data.
The card details stop working at expires_at. Treat the checkout page as
sensitive: some test checkouts show card values in the browser.
allowed_hosts controls where card details can be sent. Your worker must buy
only what the owner approved, at the approved amount, once.
Submit once and record the result
Before entering the card, record on the job that checkout may have started. A replacement worker must check that record after a crash, even if the lock has expired. Claiming again doesn’t make a second submission safe. Record the seller’s order ID, confirmation, charged amount, and receipt. Aclaimed status means the card details were delivered, not that the purchase
succeeded.
If the browser crashes, times out, or loses a response after submitting, mark
the purchase as uncertain. Check the seller’s order history before retrying or
asking for a new approval. Ionic can’t detect a duplicate order at the seller.
Requests and errors
EveryPOST takes a JSON body and an Idempotency-Key of 16 to 255 printable
ASCII characters with no spaces. Claim and cancel take {}. Store a separate
key for each setup, creation, claim, and cancellation, and retry with the same
key and body. Creating returns 201; retrying the same creation returns 200
with the existing object.
Spend errors include error.code, error.message, and error.retryable.
Authentication errors use the standard Ionic error format,
which has no retryable. Check the HTTP status as well as the code, and wait
for Retry-After when you’re rate limited or a claim is in progress.
Recover without creating another purchase
Retrying a claim with the same key returns the same card details and expiry,
while access is still valid.

