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

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

Request

Response

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

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

string
required
The cart’s ID.

Request Body

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

Request

Line Items

Add Line Item

Add a product variant to the cart.

Path Parameters

string
required
The cart’s ID.

Request Body

string
required
The product variant ID to add.
number
required
Quantity to add.
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

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

Request Body

number
required
New quantity for the line item.
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

string
First name.
string
Last name.
string
Company name.
string
required
Address line 1.
string
Address line 2.
string
required
City.
string
State or province.
string
required
Postal or ZIP code.
string
required
Two-letter ISO country code.
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

string
required
The shipping option ID.
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

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

string[]
required
Array of promotion codes to remove.

Customer Association

Update Customer

Associate the cart with a customer.

Request Body

string
The customer ID to associate.
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