Cart
Access via client.cart.
The SDK manages the cartAccessToken internally after create() or loadShared(). You don't need to handle it manually — it is stored on the client instance and sent as x-cart-token on every subsequent cart request.
Methods
create(params?)
Create a new empty cart. Stores the returned cartAccessToken internally.
const cart = await client.cart.create()
// → StorefrontCart (includes cartAccessToken on first call)
For B2B flows, pass a businessUnitId:
const cart = await client.cart.create({ businessUnitId: 'bunit-id' })
get(cartId)
Load an existing cart. Requires the cart access token to already be set on the client.
const cart = await client.cart.get(cart.id)
previewShared(cartId, token) / redeemShared(cartId, token)
POS-shared carts use a two-step flow. No x-cart-token is needed for either step — the signed share token (?t= from the share link) is the proof.
previewShared is read-only and repeatable: it returns a trimmed proposal (line items, totals, salesperson) without customer PII and without consuming the link. redeemShared is the takeover: the customer claims the cart, a fresh cart access token is issued and stored on the client, and the link is spent — a second redeem returns 409 CART_NOT_SHARED.
// On the /cart/:cartId/shared?t=<token> page:
const proposal = await client.cart.previewShared(cartId, token) // safe to repeat
// When the customer clicks "Go to checkout":
const cart = await client.cart.redeemShared(cartId, token)
// Token is now set — redirect to /checkout
addItem(cartId, item)
const cart = await client.cart.addItem(cart.id, {
sku: 'CHAIR-OAK-001',
quantity: 2,
})
removeItem(cartId, lineItemId)
const cart = await client.cart.removeItem(cart.id, lineItem.id)
setCustomer(cartId, customer)
const cart = await client.cart.setCustomer(cart.id, {
email: 'customer@example.com',
name: 'Anna Svensson',
phone: '+46701234567',
})
setCustomerType(cartId, type)
Switch between 'private' and 'business' (B2B).
const cart = await client.cart.setCustomerType(cart.id, 'business')
setShipping(cartId, shipping)
const cart = await client.cart.setShipping(cart.id, {
optionId: 'shipping-option-id',
address: { ... },
})
applyCode(cartId, code) / removeCode(cartId, code)
Unified code field — handles discount codes, gift cards, and store credits automatically.
const cart = await client.cart.applyCode(cart.id, 'SUMMER20')
const cart = await client.cart.removeCode(cart.id, 'SUMMER20')
complete(cartId, params)
Complete a cart using a custom payment method (store credit only, etc.).
const order = await client.cart.complete(cart.id, { paymentMethod: 'store-credit' })
Key types
interface StorefrontCart {
id: string
status: 'open' | 'shared' | 'awaiting-customer' | 'completed' | 'archived'
lineItems: CartLineItem[]
totalAmountIncVat: number
remainingAmount: number
currencyCode: string
customer?: CartCustomer
shippingDetails?: CartShippingDetails
cartAccessToken?: string // only present on create() / redeemShared()
}