TheDocumentation Index
Fetch the complete documentation index at: https://docs.tybritelabs.com/llms.txt
Use this file to discover all available pages before exploring further.
CartWishlistService class (accessed via client.cartWishlist) manages shopping carts for both authenticated and anonymous users, along with customer wishlists.
Overview
The cart and wishlist APIs support full variant tracking and a unified media gallery system. This enables customers to save specific product selections (color, size, etc.) with accurate pricing, real-time stock levels, and variant-specific images.Security Model
Cart and wishlist endpoints accept publishable keys (storefronts run in browsers), so a leaked publishable key alone is not enough to access another customer’s cart. When the request claims acustomer_id (query or body), the gateway requires an xAuthToken header — the customer’s session JWT from client.authentication.login or verifyOtp. The resolved customer must match the claimed customer_id, otherwise the gateway returns 403 forbidden. Anonymous (session-only) carts skip this check and rely on the secrecy of X-Session-Id.
All wishlist endpoints (and
mergeCart) always require xAuthToken because they are inherently customer-scoped. Only cart reads/writes that omit customer_id and rely solely on xSessionId may proceed unauthenticated.Cart Management
getCart
Retrieve the current contents of a cart. This method supports both logged-in customers and anonymous guest sessions.
addToCart
Add a specific product variant to the cart. If the same variant already exists, its quantity will be incremented.
variant_id is required to specify the exact product selection. For products without variants, use the default variant ID.updateCartItem
Update variables for a specific item already in the cart, such as changing the quantity.
clearCart
Remove all items from the cart in a single operation.
removeCartItem
Remove a specific item from the cart.
mergeCart
Combine an anonymous guest cart with a customer’s permanent cart. Carts are matched by both product_id and variant_id to prevent merging different variants of the same product.
mergeCart always requires xAuthToken — it links a guest session to a customer record, so the gateway must verify the caller actually owns that customer.Wishlist Management
All wishlist endpoints require
xAuthToken. Wishlists are inherently customer-scoped — there is no anonymous mode. The JWT must resolve to the same customer referenced by customer_id.getWishlist
Retrieve a customer’s saved items, including variant and media details.
addToWishlist
Save a specific product variant for later. Wishlists require an authenticated customer_id.
removeFromWishlist
Remove an item from the customer’s wishlist.
moveWishlistToCart
An atomic operation that removes an item from the wishlist and adds it to the active cart. This operation preserves the variant_id and performs stock validation.
Response Objects
CartItem & WishlistItem
Both cart and wishlist items include structured data for optimized frontend rendering.
| Field | Type | Description |
|---|---|---|
id | uuid | Item UUID in the cart or wishlist. |
product_id | uuid | The parent product identifier. |
variant_id | uuid | The specific identifier for the selected variation. |
product_name | string | Name of the product. |
variant_name | string | Display name for the variant (e.g., “Space Gray”). |
variant_attributes | object | JSON attributes like color or size. |
product_sku | string | SKU for the specific variant. |
thumbnail_url | string | Primary image URL, prioritizing variant media. |
media | array | Full gallery of variant-aware images and videos. |
quantity | number | (Cart only) Number of items added. |
unit_price | number | (Cart only) Base price per unit. |
selling_price | number | (Cart only) Actual price including active sales. |
total_price | number | (Cart only) unit_price × quantity. |
product_price | number | (Wishlist only) Current price of the variant. |
stock_available | number | Real-time stock count for the variant. |
has_variants | boolean | Whether the product supports variation selection. |
created_at | string | Timestamp of when the item was added. |
Core Logic
Stock Validation
Stock checks are enforced against the specific variant during all cart operations. If the requested quantity exceedsstock_available, the API returns an insufficient_stock error code along with the current available count.
Pricing Logic
Prices are calculated at the variant level using theselling_price field. This ensures that different variations (e.g., larger sizes or premium colors) are priced accurately and that active promotions are automatically applied.
Frontend Patterns
Variant Selection & Add to Cart
When a user selects a variant and adds it to their cart, branch on whether you have a stored customer session:Pro Tip: Use
xSessionId for guest users. Tybrite will persist this guest cart until it is either merged via mergeCart (which requires xAuthToken) or cleared.Response Codes
| Code | Meaning |
|---|---|
200 | Success on reads, updates, clearCart, and mergeCart. |
201 | Success on addToWishlist — a new wishlist item was created. |
400 | insufficient_stock, missing required fields, or invalid body. |
401 | Missing or invalid xAuthToken. |
403 | The customer token does not match the customer_id in the request. |
404 | Variant, wishlist item, or cart item not found. |
409 | Item already in wishlist (on addToWishlist). |

