Skip to content

How to Build an Agent-Ready Ecommerce API

How to design ecommerce APIs AI agents can use safely: products, inventory, pricing, cart, checkout, orders and returns, with schemas, auth and idempotency.

01

Quick answer

An agent-ready ecommerce API exposes the commerce capabilities an AI agent needs (products, inventory, pricing, cart, checkout, orders, fulfillment, cancellation and returns) in a form agents can use without guessing: typed schemas, explicit status enums, actionable errors, delegated authorization per shopper, idempotent writes, rate limits per agent, cursor pagination and signed webhooks.

Build the capabilities once behind your own API and keep your business rules there. Then expose them to agents through REST, an MCP server and commerce protocol adapters (ACP, UCP) as the channels you sell through require.

02

Why a generic API is not enough

Most ecommerce APIs were built for your own storefront and apps, which know your quirks. Agents do not. They read field names and descriptions literally, retry on timeouts, call from many platforms at once and act on behalf of shoppers who are not looking at your site. A missing idempotency key becomes a double order; a vague status becomes a wrong promise to a customer. The general case is covered in APIs for AI agents; this article is the ecommerce-specific design.

03

Example architecture

Agent-ready ecommerce API (diagram)
      Agent platforms / assistants / your own agent
           │ ACP          │ UCP           │ MCP tools
   ┌───────┴──────┬───────┴───────┬───────┴───────┐
   │ ACP adapter  │ UCP adapter   │ MCP server    │  thin channel
   └───────┬──────┴───────┬───────┴───────┬───────┘  adapters
           ▼              ▼               ▼
   ┌───────────────────────────────────────────────┐
   │ AGENT GATEWAY: auth · signatures · rate limits │
   │ idempotency store · audit · channel tagging    │
   └───────────────────────┬───────────────────────┘
                           ▼
   ┌───────────────────────────────────────────────┐
   │ COMMERCE API (single source of business rules) │
   │ products · inventory · pricing · cart ·        │
   │ checkout · orders · fulfillment · returns      │
   └───────┬──────────┬──────────┬─────────┬───────┘
           ▼          ▼          ▼         ▼
         PIM       OMS/WMS     PSP     tax / shipping
   webhooks ◀── order + fulfillment events (signed) ──▶ agents
04

Endpoints

ResourceExample operationsAgent-specific notes
Productssearch, get product, get variantsReturn per-variant IDs, options, media, policies; filters as typed params
Inventoryget availability by variant and locationStatus enum plus quantity bands if exact counts are sensitive; as-of time
Pricingquote(items, destination, discounts)Totals from the same engine as checkout; currency and tax treatment explicit
Cartcreate, add, update, removeValidate on every change; return warnings (low stock, price change)
Checkoutcreate session, update, get, complete, cancelAuthoritative totals; statuses; escalation URL; idempotency
Ordersget order, list for shopperStatus enum; line-level states; links for the shopper
Fulfillmentget shipments, tracking eventsCarrier, tracking number, event timeline
Cancellationcheck cancellable, cancel order or lineReturn what can still be cancelled and the refund amount before acting
Returnscheck eligibility, create return, get return statusPolicy evaluated server-side; label and instructions in response
05

Schemas and machine-readable states

Use explicit types, enums and units everywhere: amounts in minor units with currency codes, timestamps in ISO 8601 with time zones, statuses from closed lists. Describe every field in plain language in your OpenAPI or tool schema, because agents read descriptions. Keep IDs stable across feed, cart, checkout and order, so an item an agent found can be bought and then tracked. Return state with every write so the agent never has to guess what happened.

Order state in a response (illustrative)
{
  "order_id": "ord_55120",
  "status": "partially_shipped",
  "currency": "EUR",
  "total_minor": 42000,
  "lines": [
    { "line_id": "l1", "variant_id": "v_sofa_grey_3s",
      "status": "shipped", "cancellable": false,
      "returnable_until": "2026-11-02T23:59:59Z" },
    { "line_id": "l2", "variant_id": "v_cushion_set",
      "status": "processing", "cancellable": true }
  ],
  "shipments": [{ "carrier": "DHL", "tracking": "JD0142…",
                  "status": "in_transit" }],
  "updated_at": "2026-10-08T09:12:00Z"
}
06

Authentication and authorization

Separate three identities. The agent platform proves who it is with client credentials or signed requests (HTTP Message Signatures, RFC 9421, are used by UCP). The shopper delegates specific permissions to that platform through OAuth-style identity linking, so the agent can see this shopper's orders and nothing else. Payment authorization is separate again and handled through payment credentials, not API scopes. Scope tokens narrowly (read orders, create checkout, create return), make them revocable, and log every call with platform, shopper and scope. See AI agent identity and authentication and AI commerce payments.

07

Idempotency, rate limits and pagination

Idempotency: require an idempotency key on every write (cart changes, checkout completion, cancellation, return creation), store the result per key, and return the original result on replay; reject the same key with a different payload. Rate limits: apply per agent platform and per shopper, return 429 with Retry-After, and publish limits so platforms can plan. Pagination: use cursor-based pagination with stable ordering for search and order lists; offset pagination produces duplicates and gaps when data changes between pages.

08

Errors agents can recover from

Return a stable error type and code, a human-readable message, the field at fault, whether retrying can help and suggested alternatives: another variant in stock, the new price, the nearest available delivery date. Distinguish errors the agent can fix itself from those requiring the shopper (verification, policy acceptance) and return a URL where the shopper can complete them. See agent UX for the general pattern.

09

Webhooks

Agents should not poll your order system. Emit signed webhooks for order created, payment captured, shipped, delivered, cancelled, return created, refund issued. Include event IDs and timestamps so receivers can deduplicate and order events, retry with backoff, and provide a way to fetch current state for reconciliation. Our guide to ecommerce webhooks covers delivery guarantees.

10

MCP tools on top

For assistants that use MCP, wrap the same API in a small set of task-shaped tools (search_products, check_availability, create_checkout, get_order_status, start_return) with descriptions written for models. Do not expose raw CRUD over every table. Keep consequential tools (complete checkout, cancel, return) behind shopper confirmation in the client and authorization on your server. See AI agent tool design.

11

Checklist

  • Capabilities defined once in a commerce API; protocols and MCP as thin adapters
  • Stable IDs shared by feed, cart, checkout and order
  • Typed schemas with descriptions, enums, units and examples
  • Platform authentication, shopper delegation and payment authorization kept separate
  • Idempotency on every write; conflict on key reuse with different payloads
  • Per-platform and per-shopper rate limits with Retry-After
  • Cursor pagination with stable ordering
  • Typed, recoverable errors with escalation URLs for shopper-only steps
  • Signed, deduplicable webhooks plus state lookup for reconciliation
  • Agent traffic tagged by channel in logs, orders and analytics

Building commerce APIs for AI agents?

ZSpace Labs designs and builds headless commerce APIs, MCP servers and checkout integrations. See full-stack development and Shopify development.

Start a Project
12

Conclusion

An agent-ready ecommerce API is a well-designed commerce API with stricter guarantees: explicit states, actionable errors, separated identities, idempotent writes, fair limits and reliable webhooks. Keep the rules in one place and adapt it to each protocol and assistant. For the checkout flow in detail, see agentic checkout; for the full picture, the agentic commerce stack.

FAQ

Common questions.

An ecommerce API designed so AI agents, as well as apps, can discover products, check stock and price, build carts, complete checkout and manage orders, cancellations and returns, with clear schemas, delegated authorization, idempotent writes, machine-readable states and signed webhooks.

Get in touch

Have a project in mind?

Whether you're building a new digital product, improving an existing website, or looking to automate part of your business — let's talk.