Skip to main content

Overview

The Cart API enables customers to create shopping carts, add/remove items, apply promotions, and manage shipping information before completing checkout. Base Path: /store/carts Source: packages/medusa/src/api/store/carts/route.ts

Create Cart

Create a new shopping cart.

Request Body

region_id
string
The region where the cart is used. Determines available shipping options and tax rates.
sales_channel_id
string
The sales channel for the cart.
currency_code
string
Currency code for the cart (e.g., “usd”).
email
string
Customer’s email address.
metadata
object
Custom metadata key-value pairs.

Request

Response

cart
object
The created cart object.
Source: packages/medusa/src/api/store/carts/route.ts:13
If the customer is authenticated, the cart is automatically associated with their account via req.auth_context.actor_id (see line 22).

Get Cart

Retrieve a cart by ID.

Path Parameters

id
string
required
The cart’s ID.

Request

Response

Source: packages/medusa/src/api/store/carts/[id]/route.ts

Update Cart

Update cart details such as email or region.

Path Parameters

id
string
required
The cart’s ID.

Request Body

email
string
Update the customer’s email.
region_id
string
Change the cart’s region.
currency_code
string
Change the currency.
metadata
object
Update metadata.

Request

Line Items

Add Line Item

Add a product variant to the cart.

Path Parameters

id
string
required
The cart’s ID.

Request Body

variant_id
string
required
The product variant ID to add.
quantity
number
required
Quantity to add.
metadata
object
Custom metadata for the line item.

Request

Response

Source: packages/medusa/src/api/store/carts/[id]/line-items/route.ts

Update Line Item

Update the quantity of a line item.

Path Parameters

id
string
required
The cart’s ID.
line_id
string
required
The line item’s ID.

Request Body

quantity
number
required
New quantity for the line item.
metadata
object
Update metadata.

Request

Source: packages/medusa/src/api/store/carts/[id]/line-items/[line_id]/route.ts

Delete Line Item

Remove a line item from the cart.

Request

Addresses

Update Shipping Address

Set or update the shipping address.

Request Body

first_name
string
First name.
last_name
string
Last name.
company
string
Company name.
address_1
string
required
Address line 1.
address_2
string
Address line 2.
city
string
required
City.
province
string
State or province.
postal_code
string
required
Postal or ZIP code.
country_code
string
required
Two-letter ISO country code.
phone
string
Phone number.

Request

Update Billing Address

Set or update the billing address.
Accepts the same request body as shipping address.

Shipping Methods

Add Shipping Method

Select a shipping method for the cart.

Request Body

option_id
string
required
The shipping option ID.
data
object
Additional data required by the shipping provider.

Request

Response

Source: packages/medusa/src/api/store/carts/[id]/shipping-methods/route.ts

Promotions

Apply Promotion Code

Apply a promotion code to the cart.

Request Body

promo_codes
string[]
required
Array of promotion codes to apply.

Request

Response

Source: packages/medusa/src/api/store/carts/[id]/promotions/route.ts

Remove Promotion Code

Remove a promotion code from the cart.

Request Body

promo_codes
string[]
required
Array of promotion codes to remove.

Customer Association

Update Customer

Associate the cart with a customer.

Request Body

customer_id
string
The customer ID to associate.
email
string
Customer email if not registered.
Source: packages/medusa/src/api/store/carts/[id]/customer/route.ts

Calculate Taxes

Manually trigger tax calculation for the cart.
Source: packages/medusa/src/api/store/carts/[id]/taxes/route.ts
Taxes are usually calculated automatically when the shipping address is set or updated.

Next Steps

Checkout

Complete the cart and create an order

Products

Browse products to add to cart