Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ALEJ4NDRO2025/urban-store/llms.txt

Use this file to discover all available pages before exploring further.

The /api/cart/ endpoint provides all four standard cart operations under a single URL. All methods require a valid Bearer token; the user’s cart is identified by the email field extracted from the JWT payload. A cart document is created automatically in MongoDB on first access — you never need to explicitly initialize one. Authentication required for all methods:
Authorization: Bearer <token>

GET /api/cart/

Retrieve the authenticated user’s current cart, including all items and computed totals. If the user has no existing cart, an empty one is created and returned.

Response Fields

user_id
string
The email address extracted from the user’s JWT, used as the cart’s unique identifier.
items
array of objects
All items currently in the cart. See item fields below.
items[].product_slug
string
Slug of the product this item refers to.
items[].product_name
string
Display name of the product at the time it was added.
items[].quantity
integer
Number of units of this specific variant in the cart.
items[].selected_size
string
The size chosen for this item (e.g. "M").
items[].selected_color
string
The color chosen for this item (e.g. "negro").
items[].price_at_time
number
Price per unit captured when the item was added to the cart.
items[].image
string
Cloudinary URL of the product image snapshot for display in the cart UI.
total
number
Sum of price_at_time × quantity for all items.
item_count
integer
Sum of quantities across all items.

Example

curl https://urban-store-api.example.com/api/cart/ \
  -H "Authorization: Bearer <token>"
200 OK:
{
  "user_id": "user@example.com",
  "items": [
    {
      "product_slug": "urban-classic-tee",
      "product_name": "Urban Classic Tee",
      "quantity": 2,
      "selected_size": "M",
      "selected_color": "negro",
      "price_at_time": 49.99,
      "image": "https://res.cloudinary.com/urban-store/image/upload/v1/products/classic-tee-1.jpg"
    }
  ],
  "total": 99.98,
  "item_count": 2
}

POST /api/cart/ — Add Item

Add a product variant to the cart. If the same combination of product_slug, selected_size, and selected_color already exists in the cart, the existing item’s quantity is incremented by the requested amount instead of creating a duplicate entry.

Request Body

product_slug
string
required
Slug of the product to add to the cart.
price_at_time
number
required
Current unit price. Captured and stored with the item so the cart total reflects the price at the moment of addition.
product_name
string
Display name of the product. Stored for rendering the cart without an additional product lookup.
quantity
integer
Number of units to add. Defaults to 1.
selected_size
string
The size variant being added (e.g. "M"). Defaults to an empty string if omitted.
selected_color
string
The color variant being added (e.g. "negro"). Defaults to an empty string if omitted.
image
string
Cloudinary URL of the product image for display in the cart UI. Defaults to an empty string if omitted.

Response

  • 201 Created — a new item was appended to the cart.
  • 200 OK — an existing matching item had its quantity incremented.
Both statuses return the full updated cart object (same shape as GET /api/cart/).

Example

curl -X POST https://urban-store-api.example.com/api/cart/ \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "product_slug": "urban-classic-tee",
    "product_name": "Urban Classic Tee",
    "price_at_time": 49.99,
    "quantity": 1,
    "selected_size": "M",
    "selected_color": "negro",
    "image": "https://res.cloudinary.com/urban-store/image/upload/v1/products/classic-tee-1.jpg"
  }'

PUT /api/cart/ — Update Quantity

Set the exact quantity of a specific cart item identified by its product_slug, selected_size, and selected_color. If the provided quantity is 0 or negative, the item is automatically removed from the cart.

Request Body

product_slug
string
required
Slug of the product whose quantity to update.
selected_size
string
required
Size of the item to target. Must match the value stored in the cart.
selected_color
string
required
Color of the item to target. Must match the value stored in the cart.
quantity
integer
required
New quantity. Set to 0 or any negative value to remove the item entirely.

Response

200 OK — returns the full updated cart object.

Example

curl -X PUT https://urban-store-api.example.com/api/cart/ \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "product_slug": "urban-classic-tee",
    "selected_size": "M",
    "selected_color": "negro",
    "quantity": 3
  }'

DELETE /api/cart/ — Remove Item

Remove a specific item from the cart, regardless of its current quantity. The item is identified by the combination of product_slug, selected_size, and selected_color.

Request Body

product_slug
string
required
Slug of the product to remove.
selected_size
string
required
Size of the item to remove. Must match the value stored in the cart.
selected_color
string
required
Color of the item to remove. Must match the value stored in the cart.

Response

200 OK — returns the full updated cart object with the item removed.

Example

curl -X DELETE https://urban-store-api.example.com/api/cart/ \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "product_slug": "urban-classic-tee",
    "selected_size": "M",
    "selected_color": "negro"
  }'

Build docs developers (and LLMs) love