Skip to main content
The cart webhook is called when the AI assistant performs a cart operation on behalf of the customer. Your endpoint receives the operation details and returns a success/failure response.

Request Format

Method: POST Headers: Body:

Common Fields

action
string
required
The cart operation: "add", "remove", "update_quantity", or "clear".
store_id
string
required
Store identifier.
session_id
string
required
Session/user identifier. Matches the userId from the widget config, or an auto-generated ID if none was provided. Use this to look up the correct cart.

Actions

Add

Add a product to the cart.
sku
string
required
Product SKU to add.
name
string
Product name (for convenience — you can ignore this and look up by SKU).
quantity
number
Quantity to add. Defaults to 1 if not provided.
price
number
Price as known by the AI (from the last products webhook call). You may use this or look up the current price yourself.

Remove

Remove a product from the cart.
sku
string
required
Product SKU to remove.

Update Quantity

Change the quantity of an existing cart item.
sku
string
required
Product SKU to update.
quantity
number
required
New quantity for the product.

Clear

Remove all items from the cart.
No additional fields required.

Response Format

Return a JSON object with ok (boolean) and an optional reason on failure:

Success

Failure

ok
boolean
required
Whether the operation succeeded.
reason
string
Human-readable reason for failure. The AI uses this to inform the customer and may suggest alternatives.

Common Rejection Reasons

You can use any string as the reason value. The AI reads the reason and responds contextually. Common, descriptive reasons work best — for example, "max_3_per_customer" would lead the AI to say something like “There’s a limit of 3 per customer for this product.”

Cart GET Endpoint

In addition to the POST webhook for operations, you can implement a GET endpoint to provide the initial cart state when a new conversation starts. Method: GET Query Parameters: Response:
items
array
required
Array of cart items.
sku
string
required
Product SKU.
name
string
required
Product name.
price
number
required
Unit price.
quantity
number
required
Quantity in cart.
unit
string
Unit of measure (e.g., "pcs", "kg"). Defaults to "PCS".
promo_price
number
Promotional price, if applicable.

Handler Examples


Best Practices

Always validate stock on add operations. The AI has price data from the last products webhook call, but stock may have changed since then.
Use your own authoritative price when adding items to the cart, not the price field from the webhook request. The price in the request is what VIZOCHOK received from your last products webhook call and may be slightly stale.
  • Idempotency: If the same add request arrives twice (due to retries), your handler should handle it gracefully — either add the quantity again or deduplicate.
  • Session mapping: The session_id maps to the userId from the SDK. If no userId was provided, VIZOCHOK generates one per WebSocket connection. Plan your cart storage accordingly.
  • Response time: Keep responses under 5 seconds (the default timeout). Cart operations should be fast since they are blocking the AI’s response to the customer.