> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stateset.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Clear Cart

> Remove all items from a cart

<Note>
  This endpoint removes all items from a cart while preserving the cart itself, customer information, and applied settings. Useful for "Clear Cart" functionality.
</Note>

## Authentication

This endpoint requires a valid API key with `carts:write` permissions.

```bash theme={null}
Authorization: Bearer YOUR_API_KEY
```

## Path Parameters

<ParamField path="id" type="string" required>
  The unique identifier of the cart to clear
</ParamField>

## Request Body

<ParamField body="preserve_coupons" type="boolean" default="false">
  Keep applied coupon codes
</ParamField>

<ParamField body="reason" type="string">
  Reason for clearing the cart (for analytics)
</ParamField>

### Response

Returns the cleared cart object.

<RequestExample>
  ```bash cURL theme={null}
  curl --location --request POST 'https://api.stateset.com/v1/carts/cart_0901f083-aa1c-43c5-af5c-0a9d2fc64e30/clear' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --data-raw '{
      "preserve_coupons": false,
      "reason": "customer_requested"
  }'
  ```

  ```javascript Node.js theme={null}
  const cart = await stateset.carts.clear(
    'cart_0901f083-aa1c-43c5-af5c-0a9d2fc64e30',
    {
      preserve_coupons: false,
      reason: "customer_requested"
    }
  );
  ```

  ```python Python theme={null}
  cart = stateset.carts.clear(
    'cart_0901f083-aa1c-43c5-af5c-0a9d2fc64e30',
    preserve_coupons=False,
    reason="customer_requested"
  )
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "id": "cart_0901f083-aa1c-43c5-af5c-0a9d2fc64e30",
    "object": "cart",
    "customer_id": "cust_abc123",
    "session_id": "sess_xyz789",
    "channel": "web",
    "currency": "USD",
    "locale": "en-US",
    "status": "active",
    "items": [],
    "item_count": 0,
    "unique_item_count": 0,
    "subtotal": 0,
    "tax_amount": 0,
    "shipping_amount": 0,
    "discount_amount": 0,
    "total": 0,
    "shipping_address": {
      "city": "San Francisco",
      "state": "CA",
      "postal_code": "94105",
      "country": "US"
    },
    "applied_coupons": [],
    "applied_promotions": [],
    "expires_at": "2024-07-20T10:00:00Z",
    "created_at": "2024-06-20T10:00:00Z",
    "updated_at": "2024-06-20T17:30:00Z",
    "last_activity": "2024-06-20T17:30:00Z",
    "cleared_at": "2024-06-20T17:30:00Z",
    "metadata": {
      "clear_reason": "customer_requested",
      "items_cleared": 3
    },
    "messages": [
      {
        "type": "info",
        "message": "Cart has been cleared"
      }
    ]
  }
  ```
</ResponseExample>
