Search Documentation
Search for a documentation page...
Carts API
REST API endpoints for managing shopping carts.
Add to Cart / Create Cart
Creates a new cart or updates an existing one. To create a new cart, omit cartId. To add to an existing cart, include it.
The endpoint supports two mutually exclusive modes: variant add (variantId + quantity) and bundle add (bundleId + selections).
Variant Add
Add a single product variant to the cart. Setting quantity to 0 removes the item.
| Field | Type | Required | Description |
|---|---|---|---|
variantId | string | Yes | Product variant UUID |
quantity | number | Yes | Quantity to apply (0 removes the item) |
mode | string | No | "add" (default) increments the existing line quantity; "set" replaces it atomically |
cartId | string | No | Existing cart UUID (omit to create new) |
subscriptionPlanId | string | No | Subscription plan ID for recurring items |
currency | string | No | Currency code for this cart (e.g. EUR). Validated against store's enabled currencies |
Bundle Add
Add a configured bundle as one line item. Get the available groups and choices from the bundle field on GET /api/v1/products/:idOrSlug for bundle-type products.
| Field | Type | Required | Description |
|---|---|---|---|
bundleId | string | Yes | Bundle product UUID |
selections | object[] | Yes | Customer choices (see below) |
cartId | string | No | Existing cart UUID (omit to create new) |
currency | string | No | Currency code for this cart |
Each entry in selections:
| Field | Type | Required | Description |
|---|---|---|---|
variantId | string | Yes | Chosen variant UUID |
groupId | string | Yes | The bundle group the choice belongs to |
quantity | number | Yes | Units chosen of this variant (positive integer) |
Always-included (forced) items may be omitted from selections — the server fills them in automatically. Choices are validated server-side against the bundle's groups (per-group count, allow-duplicates, stock).
A 400 response with details is returned when the selections are invalid (wrong group count, disallowed duplicates, etc.).
Re-adding a bundle: If the same bundle is already in the cart with identical selections, the line quantity increments by one (capped by constituent stock). If the same bundle is already in the cart with different selections, the API returns 409 Conflict with a bundle_conflict code — remove the existing bundle from the cart first to change its options.
Stock Overflow (409)
When the requested quantity exceeds the variant's available stock, the API returns 409 Conflict:
Available stock accounts for units reserved by other active carts when stock hold is enabled.
Response
Returns the complete cart with all line items:
Get Cart
Returns the full cart with all line items, product details, and computed totals.
Delete Cart
Permanently deletes a cart and all its line items.
Checkout Redirect
Redirects (HTTP 308) to the store's hosted checkout page for the given cart. Useful for headless integrations that need to hand off to the YNS checkout flow.
Apply Coupon to Cart
Applies a discount code to a cart. The coupon is validated against its date range, usage cap, product count requirements, and product/collection/category/brand scope before being applied.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
code | string | Yes | Coupon code to apply (case-sensitive, max 64 chars) |
Response (200)
Returns the full updated cart object with the coupon applied.
Validation Error (422)
When the coupon cannot be applied, a 422 is returned with a machine-readable reason:
| Reason | Description |
|---|---|
couponNotFound | No coupon with this code exists |
couponIsNotValidYet | The coupon's start date is in the future |
couponHasExpired | The coupon's end date has passed |
couponMaxUsesReached | The coupon has been redeemed the maximum number of times |
couponMinProductCountNotMet | The cart has fewer products than the coupon requires |
couponMaxProductCountExceeded | The cart has more products than the coupon allows |
couponIsNotApplicable | No cart items match the coupon's product/collection/category/brand scope |
Remove Coupon from Cart
Removes the applied coupon from a cart.
Response (200)
Remove Line Item
Removes a specific variant from the cart. Returns the updated cart.
Query Parameters
| Parameter | Type | Description |
|---|---|---|
subscriptionPlanId | string | Match subscription plan when removing |
For subscription items, include the subscriptionPlanId to identify the correct line item.