Skip to main content
Migrate to Polaris

Version 2025-07 is the last API version to support React-based UI components. Later versions use web components, native UI elements with built-in accessibility, better performance, and consistent styling with Shopify's design system. Check out the upgrade guide to upgrade your extension.

Cart API

The Cart API provides comprehensive access to POS cart management functionality, enabling extensions to read cart state, modify line items, apply discounts, manage customer information, and handle cart properties through a subscribable interface that delivers real-time updates. The API supports both individual and bulk operations for efficient cart manipulation.

  • Real-time monitoring: Monitor cart changes to update extension UI in real-time.
  • Custom discounts: Apply discounts at cart and line item levels with percentage or fixed amounts.
  • Product management: Add products programmatically with oversell protection.
  • Staff attribution: Implement staff attribution to track which team members are responsible for sales.

The Cart API object provides access to cart management functionality and real-time cart state monitoring. Access the following properties on the API object to read cart state, modify line items, apply discounts, manage customer information, and handle cart properties.

Anchor to addAddress
addAddress
(address: ) => Promise<void>
required

Add a new address to the customer associated with the cart. The customer must be present in the cart before adding addresses with enhanced address validation and formatting.

Anchor to addCartCodeDiscount
addCartCodeDiscount
(code: string) => Promise<void>
required

Apply a discount code to the cart. The system will validate the code and apply the appropriate discount if the code is valid and applicable to the current cart contents with improved error messaging.

Anchor to addCartProperties
addCartProperties
(properties: Record<string, string>) => Promise<void>
required

Add custom key-value properties to the cart for storing metadata, tracking information, or integration data. Properties are merged with existing cart properties with enhanced validation and conflict resolution.

Anchor to addCustomSale
addCustomSale
(customSale: ) => Promise<string>
required

Add a custom sale item to the cart with specified quantity, title, price, and taxable status. Returns the UUID of the created line item for future operations and property management.

Anchor to addLineItem
addLineItem
(variantId: number, quantity: number) => Promise<string>
required

Add a product variant to the cart by its numeric ID with the specified quantity. Returns the UUID of the newly added line item, or an empty string if the user dismissed an oversell guard modal. Throws an error if POS fails to add the line item due to validation or system errors.

Anchor to addLineItemProperties
addLineItemProperties
(uuid: string, properties: Record<string, string>) => Promise<void>
required

Add custom properties to a specific line item using its UUID. Properties are merged with existing line item properties for metadata storage and tracking with enhanced validation.

Anchor to applyCartDiscount
applyCartDiscount
(type: , title: string, amount?: string) => Promise<void>
required

Apply a cart-level discount with the specified type ('Percentage', 'FixedAmount', or 'Code'), title, and optional amount. For discount codes, omit the amount parameter. Enhanced validation ensures proper discount application.

Anchor to bulkAddLineItemProperties
bulkAddLineItemProperties
(lineItemProperties: []) => Promise<void>
required

Add properties to multiple line items simultaneously using an array of inputs containing line item UUIDs and their respective properties for efficient bulk operations with enhanced validation and error reporting.

Anchor to bulkCartUpdate
bulkCartUpdate
(cartState: ) => Promise<>
required

Perform a bulk update of the entire cart state including note, discounts, customer, line items, and properties. Returns the updated cart object after the operation completes with enhanced validation and error handling.

Anchor to bulkSetLineItemDiscounts
bulkSetLineItemDiscounts
(lineItemDiscounts: []) => Promise<void>
required

Apply discounts to multiple line items simultaneously. Each input specifies the line item UUID and discount details for efficient bulk discount operations with enhanced validation and allocation tracking.

Anchor to clearCart
clearCart
() => Promise<void>
required

Remove all line items and reset the cart to an empty state. This action can't be undone and will clear all cart contents including line items, discounts, properties, and selling plans.

Anchor to deleteAddress
deleteAddress
(addressId: number) => Promise<void>
required

Delete an existing address from the customer using the address ID. The customer must be present in the cart to perform this operation with improved error handling for invalid address IDs.

Anchor to removeAllDiscounts
removeAllDiscounts
(disableAutomaticDiscounts: boolean) => Promise<void>
required

Remove all discounts from both the cart and individual line items. Set disableAutomaticDiscounts to true to prevent automatic discounts from being reapplied after removal with enhanced discount allocation handling.

Anchor to removeCartDiscount
removeCartDiscount
() => Promise<void>
required

Remove the current cart-level discount. This only affects cart-level discounts and does not impact line item discounts or automatic discount eligibility.

Anchor to removeCartProperties
removeCartProperties
(keys: string[]) => Promise<void>
required

Remove specific cart properties by their keys. Only the specified property keys will be removed while other properties remain intact with improved error handling for non-existent keys.

Anchor to removeCustomer
removeCustomer
() => Promise<void>
required

Remove the currently associated customer from the cart, converting it back to a guest cart without customer-specific benefits or information while preserving cart contents.

Anchor to removeLineItem
removeLineItem
(uuid: string) => Promise<void>
required

Remove a specific line item from the cart using its UUID. The line item will be completely removed from the cart along with any associated discounts, properties, or selling plans.

Anchor to removeLineItemDiscount
removeLineItemDiscount
(uuid: string) => Promise<void>
required

Remove all discounts from a specific line item identified by its UUID. This will clear any custom discounts applied to the line item while preserving discount allocation history.

Anchor to removeLineItemProperties
removeLineItemProperties
(uuid: string, keys: string[]) => Promise<void>
required

Remove specific properties from a line item by UUID and property keys. Only the specified keys will be removed while other properties remain intact with improved error handling.

Anchor to setAttributedStaff
setAttributedStaff
(staffId: number) => Promise<void>
required

Set the attributed staff member for all line items in the cart using the staff ID. Pass undefined to clear staff attribution from all line items with enhanced staff validation and tracking.

Anchor to setAttributedStaffToLineItem
setAttributedStaffToLineItem
(staffId: number, lineItemUuid: string) => Promise<void>
required

Set the attributed staff member for a specific line item using the staff ID and line item UUID. Pass undefined as staffId to clear attribution from the line item with improved validation and error handling.

Anchor to setCustomer
setCustomer
(customer: ) => Promise<void>
required

Associate a customer with the current cart using the customer object containing the customer ID. This enables customer-specific pricing, discounts, and checkout features with enhanced customer data validation.

Anchor to setLineItemDiscount
setLineItemDiscount
(uuid: string, type: , title: string, amount: string) => Promise<void>
required

Apply a discount to a specific line item using its UUID. Specify the discount type ('Percentage' or 'FixedAmount'), title, and amount value with improved discount allocation tracking.

Anchor to subscribable
subscribable
RemoteSubscribable<>
required

Subscribes to real-time cart state changes. Provides initial cart value and triggers callbacks on updates. Supports only one active subscription—use makeStatefulSubscribable for multiple subscribers.

Anchor to updateDefaultAddress
updateDefaultAddress
(addressId: number) => Promise<void>
required

Set a specific address as the default address for the customer using the address ID. The customer must be present in the cart to update the default address with enhanced validation.

Examples

import React from 'react';
import {
reactExtension,
useApi,
Tile
} from '@shopify/ui-extensions-react/point-of-sale';

const SmartGridTile = () => {
const api = useApi<'pos.home.tile.render'>();

return (
<Tile
title='My App'
subtitle='Call cart function'
enabled
onPress={() => api.cart.addCustomSale({
title: 'New product',
quantity: 1,
price: '10.00',
taxable: true,
})}
/>
);
};

export default reactExtension(
'pos.home.tile.render',
() => <SmartGridTile />
);

Prefix a property key with an underscore to hide it from POS. Any key starting with _, whether it's set with addLineItemProperties, bulkAddLineItemProperties, or addCartProperties, is hidden from every POS surface: the cart and checkout screens, the customer view that the buyer sees, printed and emailed receipts, and order and draft order details.

The underscore convention comes from the Ajax API. However, in POS, a __ prefix carries no extra meaning, so a key named __bookingId is hidden exactly as _bookingId is.

The value is still written to the order, and it stays visible in the Shopify admin, the GraphQL Admin API, and order webhooks. In Liquid, a private line item property is readable through line_item.properties, and a private cart property through order.attributes. Your extension also reads it back in full through api.cart.subscribable, and removes it by key with removeLineItemProperties or removeCartProperties.

Caution

Don't put sensitive data in a private property. Use it to keep internal data out of a staff member's and a buyer's way, not to keep that data confidential.

POS writes private properties of its own, so namespace your keys to avoid a collision. Keys beginning with _shopify are reserved, and a key like _myapp_bookingId is safe.


  • Validate operations before execution: Check cart editability and validate input data before performing cart operations to prevent errors and provide appropriate user feedback.
  • Use bulk operations for efficiency: When performing multiple related operations, use bulk methods like bulkCartUpdate, bulkSetLineItemDiscounts, and bulkAddLineItemProperties for better performance.
  • Handle errors gracefully: Implement proper error handling for all cart operations, as they may fail due to inventory constraints, validation errors, or business rule violations.

  • RemoteSubscribable supports only one subscription at a time. Use makeStatefulSubscribable if you need multiple components to subscribe to cart events simultaneously.
  • Cart operations may fail due to business rules, inventory constraints, or validation errors—always implement appropriate error handling.
  • Some operations require specific preconditions. For example, customer must be present for address operations.

Was this page helpful?