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

# Clear Cart

> Removes all line items from the cart, returning an empty cart

## Overview

The Clear Cart endpoint removes all items from the shopping cart while maintaining the session. This operation:

* **Complete Reset**: Removes all line items, shipments, and addon selections
* **Session Continuity**: Cart ID and authentication remain active
* **Preserved Settings**: Maintains shipping info, payment methods, and cart-level preferences
* **Zero Totals**: Returns empty cart with all monetary values reset to zero

## Authentication

> [card]
>
> **x-firmly-authorization** `string` *required*
>
> Device authentication token to identify and map the session

## Path Parameters

**domain** `string` *required*

Domain of the merchant website (e.g., `staging.luma.gift`)

## Response

Returns an empty shopping cart. All arrays are empty and monetary values are zero.

### What Gets Cleared:

* **Line Items**: All products removed from cart
* **Shipments**: All shipment groups deleted
* **Addons**: All addon selections removed (offers may remain available)
* **Totals**: All monetary totals reset to zero
* **Promo Codes**: Applied coupons are cleared

### What Gets Preserved:

* **Cart ID**: Session continues with same cart identifier
* **Shipping Info**: Customer address information retained
* **Payment Methods**: Available payment options maintained
* **Shipping Options**: Available shipping methods preserved
* **Session State**: Authentication and device binding remain active

## Code Examples

```bash cURL theme={null}
curl --request DELETE \
  --url https://api.firmly.work/api/v2/domains/staging.luma.gift/cart/line-items \
  --header 'x-firmly-authorization: YOUR_TOKEN'
```

```javascript JavaScript theme={null}
const response = await fetch('https://api.firmly.work/api/v2/domains/staging.luma.gift/cart/line-items', {
  method: 'DELETE',
  headers: {
    'x-firmly-authorization': 'YOUR_TOKEN'
  }
});

const emptyCart = await response.json();
console.log(emptyCart);
```

```python Python theme={null}
import requests

response = requests.delete(
    'https://api.firmly.work/api/v2/domains/staging.luma.gift/cart/line-items',
    headers={
        'x-firmly-authorization': 'YOUR_TOKEN'
    }
)

empty_cart = response.json()
print(empty_cart)
```

```php PHP theme={null}
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.firmly.work/api/v2/domains/staging.luma.gift/cart/line-items",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => "DELETE",
  CURLOPT_HTTPHEADER => [
    "x-firmly-authorization: YOUR_TOKEN"
  ],
]);

$response = curl_exec($curl);
curl_close($curl);

$emptyCart = json_decode($response, true);
print_r($emptyCart);
?>
```

```json theme={null}
{
  "cart_id": "cart_01H2XVBR8C8JS5MQSFPJ8HF9SA",
  "platform_id": "shopify",
  "shop_id": "staging.luma.gift",
  "display_name": "Luma Store",
  "cart_status": "active",
  "line_items": [],
  "shipments": [],
  "sub_total": {
    "currency": "USD",
    "value": 0,
    "number": 0,
    "symbol": "$"
  },
  "shipping_total": {
    "currency": "USD",
    "value": 0,
    "number": 0,
    "symbol": "$"
  },
  "tax_total": {
    "currency": "USD",
    "value": 0,
    "number": 0,
    "symbol": "$"
  },
  "total": {
    "currency": "USD",
    "value": 0,
    "number": 0,
    "symbol": "$"
  },
  "addons": {
    "offers": [],
    "selections": []
  },
  "addon_total": {
    "currency": "USD",
    "value": 0,
    "number": 0,
    "symbol": "$"
  },
  "shipping_info": {
    "first_name": "John",
    "last_name": "Doe",
    "email": "john.doe@staging.luma.gift",
    "phone": "555-123-4567",
    "company": "",
    "address_line_1": "123 Main Street",
    "address_line_2": "Apt 4B",
    "city": "Anytown",
    "state_code": "CA",
    "zip": "12345",
    "country_code": "US"
  },
  "payment_method_options": [
    {
      "type": "CreditCard",
      "wallet": "user"
    },
    {
      "type": "PayPal",
      "wallet": "paypal"
    }
  ],
  "coupons": [],
  "schema_version": "2.0"
}
```

## Error Responses

> [accordion] 400 Bad Request
>
> Missing or invalid authentication header
>
> ```json theme={null}
> {
>   "code": 400,
>   "error": "MissingAuthHeader",
>   "description": "x-firmly-authorization header is missing or invalid"
> }
> ```

> [accordion] 401 Unauthorized
>
> Invalid JWT token
>
> ```json theme={null}
> {
>   "code": 401,
>   "error": "InvalidJWTToken",
>   "description": "The JWT token is invalid"
> }
> ```

> [accordion] 404 Not Found
>
> Cart not found for the given domain
>
> ```json theme={null}
> {
>   "code": 404,
>   "error": "ErrorCartNotFound",
>   "description": "Cart was not found"
> }
> ```

## Use Cases

### Start Fresh

Customer wants to completely restart their shopping session:

```bash theme={null}
DELETE /api/v2/domains/staging.luma.gift/cart/line-items
# Returns empty cart, ready for new items
```

### Bulk Item Management

Before adding a new product set, clear existing items:

```bash theme={null}
# Step 1: Clear cart
DELETE /api/v2/domains/staging.luma.gift/cart/line-items

# Step 2: Add new items
POST /api/v2/domains/staging.luma.gift/cart/line-items
```

### Session Reset

After checkout completion or session timeout:

```bash theme={null}
DELETE /api/v2/domains/staging.luma.gift/cart/line-items
# Maintains session but clears all cart data
```

## Implementation Details

> [!NOTE]
>
> The clear cart operation removes all items from the cart while maintaining the session and cart identifier. Depending on the merchant's platform, this may either:
>
> * Use a native clear cart operation for optimal performance
> * Remove items individually to ensure compatibility
>
> Both approaches result in the same empty cart state.

## Related Endpoints

* [Get Cart](https://firmly.mintlify.site/api-reference/cart-management/get-cart.md) - View current cart state
* [Add Line Item](https://firmly.mintlify.site/api-reference/cart-management/add-line-item.md) - Add new items to cart
* [Update Line Item](https://firmly.mintlify.site/api-reference/cart-management/update-line-item.md) - Modify cart items


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.