Cart
Cart APIs for guest and authenticated checkout entry, line-item changes, and cart credential lifecycle.
Module role in sales flow
cart is the first checkout module for both guest and authenticated users.
- Use
createwhen you want an explicit initial cart payload (variants, coupon, and optional form/booking attributes). - Use
addItemfor quick add-to-cart UX. If no cart exists, SDK creates it automatically. - After cart is ready, continue with
invoices.create()to move into checkout.
V2 contract notes
cart.get()always sends required queryidentifierfrom stored cart credentials.- Only send
schedulerBookingAttributeswhen all required booking fields are present. updateItemacceptscount = 0to remove the target line-item.
Attribute map (form vs booking)
| Field | Scope | What it is for |
|---|---|---|
variants[].formAttributes in cart.create | Product line item | Product-specific dynamic form values for that variant (for example engraving text, custom options). |
input.formAttributes in cart.create | Cart add request | Additional dynamic form payload accepted by checkout cart endpoint. |
attributes.formAttributes in cart.addItemWithAttributes | Product line item | Same as above, but for a single add-item action. |
attributes.schedulerBookingAttributes in cart.addItemWithAttributes | Booking product only | Booking/scheduling payload (eventEntityId, startDateTimeLocal, endDateTimeLocal, timezone). |
input.formAttributes in invoices.addForm | Invoice/checkout level | Checkout-level form values (not product customization, not booking time). |
Methods
Get
Use: cart.get(options?).
| Parameter | Type | Required | Description |
|---|---|---|---|
options | RequestOptions | Optional | Per-request controls. |
Returns: SazitoResponse<Cart>.
const cartRes = await client.cart.get();
if (cartRes.error?.type === 'validation') {
// No stored cart yet, create one or call addItem.
}Create
Use: cart.create(input, options?).
| Field | Type | Required | Description |
|---|---|---|---|
input.variants | AddToCartInput[] | Required | Variants to initialize cart with. |
input.coupon | string | Optional | Initial coupon. |
input.formAttributes | Record<string, any> | Optional | Dynamic form values. |
input.schedulerBookingAttributes | SchedulerBookingAttributes | Optional | Booking attributes for scheduler products. |
options | RequestOptions | Optional | Per-request controls. |
const cartRes = await client.cart.create({
variants: [
{ id: 12001, count: 2 },
{ id: 12009, count: 1, formAttributes: { engraving: 'SAZITO' } },
],
coupon: 'WELCOME10',
});Add Item
Use: cart.addItem(variantId, count, formAttributes?, options?).
| Parameter | Type | Required | Description |
|---|---|---|---|
variantId | number | Required | Variant ID. |
count | number | Required | Quantity to add. |
formAttributes | Record<string, any> | Optional | Product dynamic form attributes (not booking schedule). |
options | RequestOptions | Optional | Per-request controls. |
const cartRes = await client.cart.addItem(12001, 1);Add Item With Attributes
Use: cart.addItemWithAttributes(variantId, count, attributes?, options?).
addItemWithAttributes is the explicit add-to-cart API when you need to pass
attributes object(s) in a structured way.
- Use
addItemfor simple quantity-only add. - Use
addItemWithAttributeswhen the product requires form answers, booking time fields, or both. - It can create the cart automatically if no cart exists yet.
| Field | Type | Required | Description |
|---|---|---|---|
variantId | number | Required | Variant ID. |
count | number | Required | Quantity to add. |
attributes.formAttributes | Record<string, any> | Optional | Product form answers attached to the added line item. |
attributes.schedulerBookingAttributes | SchedulerBookingAttributes | Optional | Booking-only schedule payload for reservable/schedulable products. |
attributes.coupon | string | Optional | Coupon token for this add-to-cart request. |
options | RequestOptions | Optional | Per-request controls. |
const cartRes = await client.cart.addItemWithAttributes(14022, 1, {
formAttributes: { participantName: 'John Doe' },
schedulerBookingAttributes: {
eventEntityId: 987,
startDateTimeLocal: '2026-03-10T10:00:00',
endDateTimeLocal: '2026-03-10T11:00:00',
timezone: 'Asia/Tehran',
},
});Update Item
Use: cart.updateItem(cartProductId, variantId, count, formAttributes?, options?).
| Parameter | Type | Required | Description |
|---|---|---|---|
cartProductId | number | string | Required | Existing cart-product row ID. |
variantId | number | Required | Variant ID being updated. |
count | number | Required | New quantity (0 removes that cart row). |
formAttributes | Record<string, any> | Optional | Updated dynamic form attributes. |
options | RequestOptions | Optional | Per-request controls. |
const cart = await client.cart.get();
const first = cart.data?.items[0];
if (first) {
await client.cart.updateItem(first.id, first.productVariantId, 3);
}Update Item With Attributes
Use: cart.updateItemWithAttributes(cartProductId, variantId, count, attributes?, options?).
| Field | Type | Required | Description |
|---|---|---|---|
cartProductId | number | string | Required | Cart-product row ID. |
variantId | number | Required | Variant ID being updated. |
count | number | Required | New quantity (0 removes row). |
attributes.formAttributes | Record<string, any> | Optional | Updated dynamic form values. |
attributes.coupon | string | Optional | Replace active coupon on this request. |
attributes.deleteCoupon | boolean | Optional | Set true to remove active coupon. |
options | RequestOptions | Optional | Per-request controls. |
await client.cart.updateItemWithAttributes('12', 12001, 0, {
deleteCoupon: true,
});Remove Item
Use: cart.removeItem(cartProductId, variantId, options?).
| Parameter | Type | Required | Description |
|---|---|---|---|
cartProductId | number | string | Required | Existing cart-product row ID. |
variantId | number | Required | Variant ID to remove. |
options | RequestOptions | Optional | Per-request controls. |
const cart = await client.cart.get();
const first = cart.data?.items[0];
if (first) {
await client.cart.removeItem(first.id, first.productVariantId);
}Clear Cart
Use: cart.clearCart().
Clears persisted cart credentials only.
client.cart.clearCart();Cart fields
| Field | Type | Required | Description |
|---|---|---|---|
id | number | Required | Backend response field. Cart API requests always use the internal ID 0; callers use identifier for cart identity. |
identifier | string | Required | Guest cart identifier. |
items | CartProduct[] | Required | Cart line items. |
netTotal | number | Required | Net total from backend checkout pricing. |
grossTotal | number | Optional | Gross total (when present in backend response). |
needsShipping | boolean | Required | Whether shipping step is required. |
minBasketLimitViolated | boolean | Required | Minimum basket status flag. |
deleteCoupon | boolean | Optional | Coupon deletion flag from backend. |
Known errors
| Type | When it happens |
|---|---|
validation | Missing cart credentials for get/updateItem/removeItem. |
Examples
// app/lib/sazito-client.ts
import { createSazitoClient } from '@sazito/client-sdk';
export const sazito = createSazitoClient({
domain: process.env.NEXT_PUBLIC_SAZITO_DOMAIN!,
});// app/[lang]/(home)/page.tsx
'use client';
import { useEffect, useState } from 'react';
import { sazito } from '@/app/lib/sazito-client';
export default function Example() {
const [data, setData] = useState<any>(null);
useEffect(() => {
sazito.cart.addItem(12001, 1).then((res) => setData(res.data ?? null));
}, []);
return <pre>{JSON.stringify(data, null, 2)}</pre>;
}Type Details
The following tables are generated from SDK TypeScript types and include nested object fields.
CreateCartInput
Source: src/types/cart.ts
| Field | Type | Required |
|---|---|---|
coupon | string | Optional |
variants | AddToCartInput[] | Required |
formAttributes | Record<string, FormAttributeValue> | Optional |
schedulerBookingAttributes | SchedulerBookingAttributes | Optional |
AddToCartInput
Source: src/types/cart.ts
| Field | Type | Required |
|---|---|---|
id | number | Required |
count | number | Required |
formAttributes | Record<string, FormAttributeValue> | Optional |
Cart
Source: src/types/cart.ts
| Field | Type | Required |
|---|---|---|
id | number | Required |
identifier | string | Required |
items | CartProduct[] | Required |
netTotal | number | Required |
grossTotal | number | Optional |
needsShipping | boolean | Required |
minBasketLimitViolated | boolean | Required |
deleteCoupon | boolean | Optional |
CartProduct
Source: src/types/cart.ts
| Field | Type | Required |
|---|---|---|
id | number | Required |
productVariantId | number | Required |
quantity | number | Required |
unitPrice | number | Required |
lineTotal | number | Required |
product | CheckoutProductSnapshot | Required |
formAttributes | Record<string, FormAttributeValue> | Optional |
formFields | Record<string, any> | Optional |
bookingAttributes | SchedulerBookingAttributes | Optional |