Home > widget-integration > CartAPI > add

CartAPI.add() method

Add single product to cart

Signature:

add(id: string | number, quantity?: number, sellingPlanId?: string | null, properties?: Record<string, unknown>): Promise<Response>;

Parameters

Parameter

Type

Description

id

string | number

Product variant ID

quantity

number

(Optional) Quantity to add (default: 1)

sellingPlanId

string | null

(Optional) Optional selling plan ID for subscriptions

properties

Record<string, unknown>

(Optional) Optional custom properties for line item

Returns:

Promise<Response>

Promise resolving to Response object

Exceptions

Error if cart addition fails

Example

// Add regular product
await cartAPI.add('12345', 2);

// Add with subscription
await cartAPI.add('12345', 1, 'selling_plan_123');

// Add with custom properties
await cartAPI.add('12345', 1, null, { gift_message: 'Happy Birthday!' });