Kibo Cart API Developer Guide
Cart And Checkout
Understand cart and checkout workflows
Cart Takeover
Configure cart takeover functionality
Share Cart Across Sites
Enable cross-site cart sharing
Quick Orders
Set up quick orders for B2B customers
Understanding Cart in Kibo
In Kibo, a Cart is more than just a list of products; it’s a transactional object that represents a shopper’s entire potential purchase. It holds the items, quantities, applied coupons, and calculated totals. Kibo’s philosophy is to treat the cart as a “draft” of an order that can exist for both guest and logged-in shoppers. When a guest with a cart logs in, Kibo intelligently merges their anonymous cart with any previous cart they had, creating a seamless shopping experience. The Cart API is part of the Storefront API group, meaning it’s designed to be called securely from a front-end application.How This Domain Fits Into Kibo
The Cart is the central hub of the shopping experience, connecting several key domains:- Catalog: The cart holds references to products (
productCode) from the catalog. It pulls in pricing and other details. - Promotions: The Cart API is where you apply coupon codes, and Kibo’s promotion engine calculates the discounts directly on the cart object.
- Customer: Carts can be associated with a customer account, allowing them to be persisted between sessions.
- Checkout: The cart is the direct input for creating a
Checkoutobject. The checkout process is essentially the act of gathering the remaining information (shipping, billing, payment) needed to convert the cart into an order. - Orders: Once the checkout is complete, the cart’s data is used to create a permanent
Orderrecord in Kibo.
Prerequisites
- Kibo Application Key
- Node.js 16+ with TypeScript
- Familiarity with REST APIs and front-end development concepts
What You’ll Learn
After completing this guide, you’ll understand:- How Kibo structures cart data for storefront interactions (based on official API specs)
- The key patterns for creating, managing, and converting a shopper’s cart
- Common workflows like adding items, applying coupons, and updating quantities
- How to avoid the most common beginner mistakes when working with carts
- How to transition a cart into the checkout and order phases of the e-commerce lifecycle
Kibo Cart Fundamentals
How Kibo Organizes Cart Data
The core object is theCart, which contains an array of CartItem objects.
Cart: The parent object. It has a uniqueid, atotal, a list of appliedcoupons, and other summary information. For guest shoppers, this cart is tracked via a cookie or session. For logged-in shoppers, it’s associated with theircustomerAccountId.CartItem: Represents a single line item in the cart. It contains aproductobject (with details likeproductCodeandname), thequantity, and atotalfor that line.
Key Kibo Patterns You’ll See Everywhere
Authentication Pattern: Storefront APIs, including the Cart API, are secured using OAuth 2.0 Bearer tokens. This applies to both application-level and shopper-level authentication.-
Application Authentication:
- When: Used for server-to-server requests or calls that are not on behalf of a specific, logged-in shopper (e.g., using explicit
cartIdAPIs). - How: Your application authenticates using its credentials (e.g., Client ID and Shared Secret) via an OAuth flow to obtain an application-level Bearer token.
- Usage: This token is passed in the request header:
Authorization: Bearer <application_token>.
- When: Used for server-to-server requests or calls that are not on behalf of a specific, logged-in shopper (e.g., using explicit
-
Shopper Authentication:
- When: Used for requests made in the context of a logged-in shopper, such as managing the
/currentcart. - How: The shopper logs in via the Customer Auth Ticket API (
POST /api/commerce/customer/authtickets), which returns ajwtAccessToken. - Usage: This shopper-specific JWT is passed in the request header:
Authorization: Bearer <shopper_jwtAccessToken>. The Kibo SDK, when configured with this token, handles this automatically.
- When: Used for requests made in the context of a logged-in shopper, such as managing the
addItemToCartByCartId, updateCartItemQuantityByCartId, applyCouponByCartId) are transactional. After you perform an action, the API returns the entire updated Cart object. This is a key pattern: you don’t need to re-fetch the cart after every change; the API response gives you the latest state, which you can use to update your UI.
Error Handling Approach:
If an operation fails (e.g., adding an out-of-stock item, applying an invalid coupon), the SDK will throw an error containing Kibo’s standard error object, including an errorCode and message.
API Documentation Reference:
Throughout this guide, we’ll reference specific endpoints. Find complete specs at:
/api-reference/cart/get-cart-summary
Common Cart Workflows
- Starting a Session: Creating a cart to get a
cartId. - Building the Cart: Adding products, updating quantities, and applying discounts using the
cartId. - Finalizing the Purchase: Converting the cart into a checkout or a direct order.
Add an Item to the Cart (Application Token / Explicit cartId)
This is the recommended approach for server-side integrations or when using a Kibo Application Token, where you need to explicitly manage the cart’s lifecycle.
When You Need This
You need this when a server-side process or application needs to create and manage a cart. This gives you direct control over which cart is being modified.API Documentation Reference
- Endpoint:
POST /api/commerce/carts/{cartId}/items - Method:
POST - API Docs:
/api-reference/cart/add-item-to-cart-by-cartid
Understanding the Kibo Approach
Using an explicit cart ID requires a two-step process. First, you must create a cart to get a uniquecartId (see the “Create a New Cart” example below). Then, you use that cartId for all subsequent operations, like adding an item.
Code Structure Walkthrough
Step-by-Step Implementation
Step 1: Setting Up the FoundationCartItem object. This object tells the API which product to add (via its productCode) and how many. For products with options (like color or size), we would also include an options array. The API will validate this information against the catalog, check inventory, and if successful, add it to the specified cart, returning the entire updated cart object.
Step 3: The Core Implementation
What Just Happened? (Code Explanation)
- The setup phase created a
Configurationobject using the publicappKey, which is the correct and secure way to authenticate storefront requests. - The API call was made using an instance of
CartApiand theaddItemToCartByCartIdmethod. This requires us to have acartIdbefore we can call it. ThiscartIdis typically retrieved from acreateCartcall (see ‘Create a New Cart’ example). - The response handling leverages Kibo’s pattern of returning the full, updated
Cartobject upon success, providing immediate access to the new total and item count without a follow-up request. - Kibo will populate the rest of the product information from the data in the Catalog.
Common Beginner Mistakes
Mistake 1: Forgetting to include product options for configurable products.Add an Item to the Cart (Shopper Token / /current APIs)
Kibo also provides session-based /current APIs. These are designed to be used with an authenticated shopper’s JSON Web Token (JWT).
When a shopper logs in, your application should exchange their credentials for a customer auth ticket.
- Auth Ticket API:
POST /api/commerce/customer/authtickets - API Docs:
/api-reference/storefrontauthticket/create-user-auth-ticket
jwtAccessToken. When you make subsequent API calls (like to the Cart API) and provide this token in the Authorization header, the Kibo platform gains the context of that specific shopper.
In this authenticated context, the /current keyword in API paths becomes a powerful shortcut. It automatically resolves to the cart associated with the logged-in shopper, eliminating the need to manually track a cartId on the client side.
Example: Add an Item to the Authenticated Shopper’s Cart
This workflow assumes you have already obtained and configured the Kibo SDK to use the shopper’saccessToken.
Here is the updated section, modified to use a client-side fetch example and simulate token retrieval.
API Documentation Reference
- Endpoint:
POST /api/commerce/carts/current/items - Method:
POST - API Docs:
/api-reference/cart/add-item-to-cart
Understanding the Kibo Approach
With an authenticated shopper token, Kibo’s/current/items endpoint is seamless. If a cart doesn’t exist for that shopper, Kibo automatically creates one and associates it with their account. If they already have a cart (perhaps from a previous session), Kibo adds the item to that existing cart.
You don’t need to manage the cartId manually; the shopper’s Authorization: Bearer <token> header provides all the necessary context for the Kibo platform to find and update the correct cart.
Code Implementation (Client-Side Fetch)
Key Takeaway
- Use explicit
cartIdAPIs (e.g.,createCart,addItemToCartByCartId) when authenticating with an Application Bearer Token (server-to-server, app-level context). - Use
/currentAPIs (e.g.,/api/commerce/carts/current/items) when authenticating with a Shopper JWT (client-side, logged-in shopper context).
Advanced Patterns & Multiple Examples
The following examples use the explicitcartId pattern, which is common for server-side management.
Pattern 1: Converting a Cart to a Checkout
Business Scenario: After a shopper has added items to their cart, they click the “Checkout” button. You need to transition them to the checkout process where they can enter shipping and payment information. Kibo’s Architecture Consideration: This is a handoff between two different domains. TheCart is the input used to create a new Order object. The OrderApi takes a cartId and creates a new, persistent checkout with its own unique ID. This new order object will contain all the items from the cart, plus new sections for shipping info, billing info, and payments.
More Real-World Examples
Example 2: Create a New Cart This is the first step for any workflow. You callcreateCart to get a new cart object and its ID.
cartId, you can retrieve it at any time.
Troubleshooting Your Cart Implementation
Reading Kibo Error Messages
VALIDATION_ERROR: The most common error. TheCartItemyou tried to add was invalid (e.g., missing options, invalidproductCode). The errormessagewill provide more details.PRODUCT_NOT_IN_CATALOG: The product is not assigned to the catalog used by the current site.NOT_STOCKED: You tried to add an item with no inventory, and the site is configured to block backorders.COUPON_INVALID: The coupon code does not exist, has expired, or is not applicable to the items in the cart.
Common Development Issues
Issue 1: ‘Cart not found’ or 404 error when managing items.- Why it happens: You are trying to use a
cartIdthat is invalid, expired, or doesn’t exist. This can happen if you don’t correctly store thecartIdafter your initialcreateCartcall. - How to fix it: Ensure your application state correctly captures and re-uses the
cartIdreturned from acreateCartcall. - API Reference: The
createCartmethod is the starting point. All other methods likeaddItemToCartByCartIddepend on its output.
- Why it happens: The promotion might have targeting rules. It could be limited to a specific customer segment, a minimum cart value, or specific products. The Storefront API enforces all these rules automatically.
- How to fix it: Check the promotion’s configuration in Kibo Admin. Make sure the cart’s contents and the shopper’s context (e.g., logged in or guest) meet all the discount’s requirements.
- API Reference:
/api-reference/cart/apply-coupon
Debugging Checklist
When your Cart implementation isn’t working:- Verify your
Configurationobject uses the publicappKey. - If using shopper-authenticated APIs, verify your
AuthorizationJWT is valid and not expired. - Check the browser’s network tab to see the API response. The error message is often very descriptive.
- Ensure the
productCodeyou’re adding is correct, active, and available on the storefront. - For configurable products, double-check that the
attributeFQNandvaluefor all required options are correct. - Use the
correlationIdfrom any error message when contacting Kibo support.

