# Create discard

URL: https://docs.hanzo.ai/docs/openapi/commerce/discardcart

> Discards a cart the shopper abandoned, and answers it in its final state.

`POST /v1/commerce/cart/{id}/discard`

> [Commerce →](https://docs.hanzo.ai/docs/openapi/commerce) · [All API references →](https://docs.hanzo.ai/docs/openapi) · [Get started →](https://docs.hanzo.ai/docs/guides)

|               |                                                      |
| ------------- | ---------------------------------------------------- |
| **Address**   | `https://api.hanzo.ai/v1/commerce/cart/{id}/discard` |
| **Method**    | `POST`                                               |
| **Operation** | `discardCart`                                        |
| **Auth**      | `Authorization: Bearer $HANZO_API_KEY`               |

Discards a cart the shopper abandoned, and answers it in its final state.

A discarded cart is CLOSED, not deleted: the row stays, so abandoned-basket
reporting and any follow-up that keys on it still have something to read. It
stops being a cart anything will check out, which is the point — it is how a
storefront says "this basket is over" without destroying the evidence that it
existed.

Discarding is idempotent: a cart already discarded answers its stored state
rather than failing, so a retry is safe.

The cart is resolved inside the caller's own org namespace, so another tenant's
id answers 404.

A named handler, not a closure, so zipdoc can lift this prose into the registry.

## Request

1 field.

| Field | In   | Type   | Required | Description                                        |
| ----- | ---- | ------ | -------- | -------------------------------------------------- |
| `id`  | path | string | yes      | ID is the cart's id, as the open call answered it. |

## Response

| Status    | Body            | Meaning |
| --------- | --------------- | ------- |
| `200`     | Cart            | ok      |
| `default` | problem-details | refused |

`200` body — 23 fields.

| Field                | In   | Type            | Always | Description                                                                                                                                       |
| -------------------- | ---- | --------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `createdAt`          | body | string          | —      | CreatedAt is when the cart was opened, RFC3339.                                                                                                   |
| `currency`           | body | string          | —      | Currency is the ISO 4217 code every amount below is denominated in.                                                                               |
| `discountCents`      | body | integer (int64) | —      | DiscountCents is what coupons and promotions took off, in whole cents.                                                                            |
| `email`              | body | string          | —      | Email is the shopper's address, when the cart carries one.                                                                                        |
| `id`                 | body | string          | —      | ID is the cart's id — what every other cart op addresses it by, and what a storefront persists against the browser session.                       |
| `items`              | body | CartItem\[]     | —      | Items are the cart's lines, in the order they were added.                                                                                         |
| `items[].free`       | body | boolean         | —      | Free reports a line that costs nothing because a coupon or a promotion made it so, rather than because its price is zero.                         |
| `items[].id`         | body | string          | —      | ID is the line's identity — the variant id when the line is a variant, otherwise the product id.                                                  |
| `items[].kind`       | body | string          | —      | Kind is "variant" when this line is a specific sellable variant and "product" when it is the product itself.                                      |
| `items[].name`       | body | string          | —      | Name is the item's display name, cached onto the line when it was added so a cart renders without a second read.                                  |
| `items[].priceCents` | body | integer (int64) | —      | PriceCents is the unit price in whole cents, cached at the moment the line was added.                                                             |
| `items[].quantity`   | body | integer (int64) | —      | Quantity is how many units of this item the cart holds.                                                                                           |
| `items[].sku`        | body | string          | —      | SKU is the line's stock-keeping unit — the variant's when it has one, otherwise the product's.                                                    |
| `lineTotalCents`     | body | integer (int64) | —      | LineTotalCents is the sum of the lines before any discount, in whole cents.                                                                       |
| `order`              | body | string          | —      | Order is the order this cart became, once checkout completed it.                                                                                  |
| `shippingCents`      | body | integer (int64) | —      | ShippingCents is the shipping charge, in whole cents.                                                                                             |
| `status`             | body | string          | —      | Status is "active" for a cart still being filled, "ordered" once checkout turned it into an order, and "discarded" when the shopper abandoned it. |
| `store`              | body | string          | —      | Store is the storefront the cart is being filled on.                                                                                              |
| `subtotalCents`      | body | integer (int64) | —      | SubtotalCents is LineTotalCents less DiscountCents, in whole cents.                                                                               |
| `taxCents`           | body | integer (int64) | —      | TaxCents is the sales tax, in whole cents.                                                                                                        |
| `totalCents`         | body | integer (int64) | —      | TotalCents is what the shopper pays: subtotal plus shipping plus tax, in whole cents.                                                             |
| `updatedAt`          | body | string          | —      | UpdatedAt is when the cart was last amended, RFC3339.                                                                                             |
| `user`               | body | string          | —      | User is the signed-in shopper this cart belongs to, empty for a guest cart.                                                                       |

Failure carries the platform error shape — see [Errors](https://docs.hanzo.ai/docs/errors).

## Examples

**CLI**

```bash
hanzo commerce cart discard <id>
```

**SDK**

**.ts**

```ts
import { Configuration, CommerceApi } from 'hanzoai';

const api = new CommerceApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.discardCart({ id: 'id' });
```

**.py**

```python
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import CommerceApi

client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = CommerceApi(client).discard_cart(id='id')
```

**.go**

```go
cfg := hanzoai.NewConfiguration()
cfg.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("HANZO_API_KEY"))
client := hanzoai.NewAPIClient(cfg)

resp, _, err := client.CommerceAPI.DiscardCart(context.Background()).Execute()
if err != nil {
	return err
}
```

**.rs**

```rust
use hanzo_client::apis::{configuration::Configuration, commerce_api};

let mut cfg = Configuration::new();
cfg.bearer_access_token = std::env::var("HANZO_API_KEY").ok();

let result = commerce_api::discard_cart(&cfg, Default::default()).await?;
```

**.java**

```java
import ai.hanzo.cloud.ApiClient;
import ai.hanzo.cloud.api.CommerceApi;

ApiClient client = new ApiClient();
client.setBearerToken(System.getenv("HANZO_API_KEY"));

var result = new CommerceApi(client).discardCart();
```

**HTTP**

```bash
curl -X POST https://api.hanzo.ai/v1/commerce/cart/<id>/discard \
  -H "Authorization: Bearer $HANZO_API_KEY"
```

**MCP**

Tool `commerce`, op `discardCart` — POST the JSON-RPC envelope to `https://api.hanzo.ai/v1/mcp`.

```bash
curl -X POST https://api.hanzo.ai/v1/mcp \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "tools/call",
       "params": {
         "name": "commerce",
         "arguments": {
           "op": "discardCart",
           "input": {
             "id": "<id>"
           }
         }
       }
     }'
```

---

[Commerce API](https://docs.hanzo.ai/docs/openapi/commerce) · [All Hanzo APIs](https://docs.hanzo.ai/docs/openapi) · [Interactive reference](https://docs.hanzo.ai/docs/openapi/reference)
