Open a cart for a shopper to fill
Opens an empty cart for a shopper to fill, and answers it with its new id.
POST /v1/commerce/cart
| Address | https://api.hanzo.ai/v1/commerce/cart |
| Method | POST |
| Operation | openCart |
| Auth | Authorization: Bearer $HANZO_API_KEY |
Opens an empty cart for a shopper to fill, and answers it with its new id.
This is the first step of a sale: hold the id, add items to it with setCartItem, then hand it to checkout. Every field of the request is optional — an empty body opens a perfectly good anonymous cart — and the fields exist only to pre-fill what is already known about the shopper.
The STORE defaults to the org's own default storefront, so a merchant selling through one storefront never has to name it. The CURRENCY defaults to usd; note that checkout overrides it with the store's own currency when the sale is authorized, so a currency set here is a hint rather than a commitment.
The cart is created in the CALLER'S OWN org namespace, taken from the validated principal and never from the body, so a cart can never be opened on another tenant's books.
A named handler, not a closure, so zipdoc can lift this prose into the registry.
Request
4 fields, body application/json (required).
| Field | In | Type | Required | Description |
|---|---|---|---|---|
currency | body | string | — | Currency is the ISO 4217 code the cart is priced in, lower-cased. |
email | body | string | — | Email is the shopper's address, for a cart that belongs to someone who has not signed in. It is what a guest checkout and an abandoned-cart follow-up key on. |
store | body | string | — | Store is the storefront this cart is being filled on. |
user | body | string | — | User is the id of the signed-in shopper this cart belongs to, when there is one. |
Response
| Status | Body | Meaning |
|---|---|---|
201 | Cart | created |
201 body — 23 fields.
| Field | In | Type | Always | Description |
|---|---|---|---|---|
createdAt | body | string | — | CreatedAt is when the cart was opened, RFC3339. |
currency | body | string | — | Currency is the ISO 4217 code every amount below is denominated in. |
discountCents | body | integer | — | DiscountCents is what coupons and promotions took off, in whole cents. |
email | body | string | — | Email is the shopper's address, when the cart carries one. |
id | body | string | — | ID is the cart's id — what every other cart op addresses it by, and what a storefront persists against the browser session. |
items | body | CartItem[] | — | Items are the cart's lines, in the order they were added. |
items[].free | body | boolean | — | Free reports a line that costs nothing because a coupon or a promotion made it so, rather than because its price is zero. |
items[].id | body | string | — | ID is the line's identity — the variant id when the line is a variant, otherwise the product id. |
items[].kind | body | string | — | Kind is "variant" when this line is a specific sellable variant and "product" when it is the product itself. |
items[].name | body | string | — | Name is the item's display name, cached onto the line when it was added so a cart renders without a second read. |
items[].priceCents | body | integer | — | PriceCents is the unit price in whole cents, cached at the moment the line was added. |
items[].quantity | body | integer | — | Quantity is how many units of this item the cart holds. |
items[].sku | body | string | — | SKU is the line's stock-keeping unit — the variant's when it has one, otherwise the product's. |
lineTotalCents | body | integer | — | LineTotalCents is the sum of the lines before any discount, in whole cents. |
order | body | string | — | Order is the order this cart became, once checkout completed it. |
shippingCents | body | integer | — | ShippingCents is the shipping charge, in whole cents. |
status | body | string | — | Status is "active" for a cart still being filled, "ordered" once checkout turned it into an order, and "discarded" when the shopper abandoned it. |
store | body | string | — | Store is the storefront the cart is being filled on. |
subtotalCents | body | integer | — | SubtotalCents is LineTotalCents less DiscountCents, in whole cents. |
taxCents | body | integer | — | TaxCents is the sales tax, in whole cents. |
totalCents | body | integer | — | TotalCents is what the shopper pays: subtotal plus shipping plus tax, in whole cents. |
updatedAt | body | string | — | UpdatedAt is when the cart was last amended, RFC3339. |
user | body | string | — | User is the signed-in shopper this cart belongs to, empty for a guest cart. |
Failure carries the platform error shape — see Errors.
Examples
hanzo has no subcommand for this operation — the CLI serves only what cloud's live route table confirms. Use HTTP or an SDK.
import { Configuration, CommerceApi } from 'hanzoai';
const api = new CommerceApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.openCart({ currency: "<currency>", email: "<email>" });from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import CommerceApi
client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = CommerceApi(client).open_cart(currency="<currency>", email="<email>")cfg := cloud.NewConfiguration()
cfg.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("HANZO_API_KEY"))
client := cloud.NewAPIClient(cfg)
resp, _, err := client.CommerceAPI.OpenCart(context.Background()).Execute()
if err != nil {
return err
}use hanzo_cloud::apis::{configuration::Configuration, commerce_api};
let mut cfg = Configuration::new();
cfg.bearer_access_token = std::env::var("HANZO_API_KEY").ok();
let result = commerce_api::open_cart(&cfg, Default::default()).await?;import ai.hanzo.cloud.ApiClient;
import ai.hanzo.cloud.api.CommerceApi;
ApiClient client = new ApiClient();
client.setRequestInterceptor(b -> b.header("Authorization", "Bearer " + System.getenv("HANZO_API_KEY")));
var result = new CommerceApi(client).openCart();curl -X POST https://api.hanzo.ai/v1/commerce/cart \
-H "Authorization: Bearer $HANZO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"currency": "<currency>",
"email": "<email>"
}'Tool commerce, op openCart — POST the JSON-RPC envelope to https://api.hanzo.ai/v1/mcp.
curl -X POST https://api.hanzo.ai/v1/mcp \
-H "Authorization: Bearer $HANZO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "commerce",
"arguments": {
"op": "openCart",
"input": {
"currency": "<currency>",
"email": "<email>"
}
}
}
}'How is this guide?