CartWishlistService class (accessed via client.cartWishlist) manages shopping carts for both authenticated and anonymous users, along with customer wishlists.
Overview
Cart and wishlist entries are held against a specific variant rather than a product, so a saved selection carries its own colour and size, its own price, its current stock level, and the images belonging to that variant.Sandbox isolation: Cart and wishlist items created with a
tybrite_pk_test_* or tybrite_sk_test_* key are stored in the sandbox environment and are never visible to production keys. Every response, including error responses, includes a Tybrite-Environment: sandbox | production header confirming which environment resolved.Security Model
Cart and wishlist endpoints accept publishable keys, so a leaked publishable key alone is not enough to access another customer’s cart. When the request claims acustomer_id (query or body), Galactic Core requires a customer identity — supply either xAuthToken (the customer’s session JWT from client.authentication.login or verifyOtp) or xExternalAuth (a bring-your-own-auth signed assertion, if your store runs its own identity provider); provide one, not both. The resolved customer must match the claimed customer_id, otherwise the request 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 a customer identity (xAuthToken or xExternalAuth) because they are inherently customer-scoped. Only cart reads/writes that omit customer_id and rely solely on xSessionId may proceed unauthenticated.Carts on a marketplace
With a marketplace key, the cart methods (getCart, clearCart, addToCart, updateCartItem, removeCartItem) hold a shopper’s session cart at one merchant, named by storeId — which is required there and must be an active merchant in the marketplace (400 when it is missing, 404 when it is not active). A marketplace cart is held by xSessionId; a customer_id answers 400. The cart is recorded as the marketplace’s and is never visible to the merchant’s own storefront. mergeCart and the wishlist methods answer 403 on a marketplace key. The whole basket is checked out with client.marketplace.marketplaceCheckout.
Cart Management
getCart
Retrieve the current contents of a cart. This method supports both logged-in customers and anonymous guest sessions.
Response (200)
See Response Objects below for the full
CartItem shape, including the media[] gallery.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 Galactic Core 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.
Response (200)
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 (200)
Back in Stock
notifyWhenAvailable
Ask to be emailed once when a sold-out variant is available again. The email address is the only identity needed, so the call works for an anonymous visitor and a signed-in customer alike; pass customer_id with the customer’s xAuthToken (or xExternalAuth) to attach the request to a customer record.
The request is not marketing consent. It subscribes the address to nothing and produces exactly one message, sent when the variant’s stock goes from nothing to something; the shopper can ask again afterwards. Galactic Core sends the message in the store’s name; a store with Klaviyo connected sends it from its own Klaviyo flow instead. The merchant can switch the message off.
Response
Checkout recovery
A guest’s email address and cart can be recorded at the first step of checkout, so that a store follows up when the checkout is left unfinished.captureCheckoutContact records the address with the shopper’s own answer to the marketing box; the store emits a checkout.abandoned event after its waiting period and, when the shopper agreed, sends one reminder email with a link back to the cart. recoverCheckoutCart returns the cart behind that link. Both methods work with a publishable key and need no customer credential.
captureCheckoutContact
Record a guest’s contact details at checkout.
Records the email address a guest enters at the first step of checkout, with the cart they are buying and
whether they agreed to hear from the store. The store uses it to follow up when the checkout is left
unfinished: a checkout.abandoned event carrying the address is emitted after the store’s waiting period,
and, when marketing_consent is true, the store can send the shopper one reminder email containing a link
back to their cart.
Send the cart as cart_id (the cart’s X-Session-Id) or as lines. Calling again for the same address and
cart updates the one record, so the storefront can call it each time the details change. The response is the
same for a new and a repeated record.
marketing_consent is required and must be exactly what the shopper chose: an unticked box is false.
A box that is ticked in advance is not consent. A later call with false withdraws it.
recovery_url is the storefront page the reminder link opens, and must be on one of the store’s own storefront
addresses (https, no port; a test key may also use http and localhost). Any other address is refused with
400 (recovery_url_not_allowed). The reminder appends a cart_recovery query parameter to it; pass that value
to POST /v1/cart/checkout-recover to restore the cart.
Auth / key type: publishable key (tybrite_pk_*) or secret key (tybrite_sk_*). No customer credential
is needed. Test keys write test records, which never send email.
Rate limits: 60 requests per hour per IP address and 20 per hour per email address, each within one store.
Response
POST /v1/cart/checkout-contact
recoverCheckoutCart
Restore the cart behind a recovery link.
Returns the items of the cart a reminder email linked to, priced from the store’s current catalogue. Pass the
cart_recovery query parameter of the page the shopper arrived on as token. The storefront re-adds the
returned items with POST /v1/cart/items.
The token is the only credential. A token that is unknown, expired (30 days) or issued to another store
answers the same 404. The response carries no email address or name.
Auth / key type: publishable key (tybrite_pk_*) or secret key (tybrite_sk_*). Test keys read test records.
Rate limits: 60 requests per hour per IP address, within one store.
Response
POST /v1/cart/checkout-recover
Response Objects
CartItem & WishlistItem
Both cart and wishlist items include structured data for optimized frontend rendering.
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
Each variant is priced independently, so different variations (for example larger sizes or premium colors) carry their own price. A cart line’sunit_price is the variant’s online sale price when it has one, and its online price otherwise; a variant with no online price is charged its in-store price. The same price is what getProduct returns as the variant’s sale_price (when present) or price, and it is the starting point for checkout: dynamic pricing, promotions and discounts apply on top of it.
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.
