Docs
Firmly Agentic Commerce
Set theme to dark (⇧+D)

Clear Cart

DELETE https://api.firmly.work/api/v2/domains/{domain}/cart/line-items

​​ Overview

The Clear Cart endpoint removes all line items from the cart. The response is the fresh cart state as returned by the merchant after the operation completes.

  • Line items are removed. Shipments are rebuilt against the (now empty) line items, so the response typically returns line_items: [] and shipments: [].
  • Session continuity. The Firmly session, device_id, and the underlying merchant cart identifier remain active — subsequent calls keep working without re-authenticating.
  • Everything else is merchant-defined. What happens to shipping_info, coupons, billing_info, selected fulfillment / shipping methods, applied promotions, and addon selections depends entirely on the merchant platform — some reset these along with line items, others retain them tied to the customer profile. See the Response section below for the field-by-field breakdown.

​​ Authentication

  • x-firmly-authorization (string, required) — Device access token from Browser Session

​​ Path Parameters

  • domain (string, required) — Domain of the merchant website (e.g., staging.luma.gift)

​​ Response

Returns the cart state after line items are removed — same schema as Get Cart. In the typical case line_items and shipments are empty and totals are zero, but the rest of the cart reflects whatever the merchant returns post-clear.

​​ Guaranteed by Firmly

  • line_items — emptied
  • cart_id, session, and device binding — unchanged

​​ Merchant-defined

  • shipping_info, billing_info — some merchants keep the customer’s address; others reset it
  • coupons / promotion state — some merchants clear applied codes when the cart empties
  • shipping_method / shipping_method_options — fulfillment selection often resets to defaults
  • addons.selections — typically clears (offers and selections are tied to line items)
  • payment_handle, payment_method_options — usually reset

​​ Code Examples


curl --request DELETE \
--url https://api.firmly.work/api/v2/domains/staging.luma.gift/cart/line-items \
--header 'x-firmly-authorization: YOUR_TOKEN'

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);

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
$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);
?>

​​ Response Example


{
"cart_id": "a5600193-2c13-3356-d063-711da63b7cd7",
"platform_id": "example_commerce",
"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": "$"
},
"schema_version": "2.0"
}

​​ Error Responses

Errors return a JSON body with code, error, and description. Program against the error value — descriptions are human-readable and may change.

400 — MissingAuthHeader

The x-firmly-authorization header is missing or empty.


{
"code": 400,
"error": "MissingAuthHeader",
"description": "x-firmly-authorization header is missing or invalid."
}
400 — InvalidToken

The authorization token is not a valid JWT structure.


{
"code": 400,
"error": "InvalidToken",
"description": "Jwt token is invalid."
}
400 — InvalidAPIToken

The API token (server-to-server secret) is invalid or has been revoked.


{
"code": 400,
"error": "InvalidAPIToken",
"description": "API token is invalid."
}
400 — BadRequest

Server-to-server auth was attempted but the required headers (x-firmly-authorization plus x-firmly-device-id) are missing or malformed.


{
"code": 400,
"error": "BadRequest",
"description": "Bad request."
}
401 — Unauthorized

The authorization token was rejected.


{
"code": 401,
"error": "Unauthorized",
"description": "Unauthorized."
}
401 — InvalidJWTToken

The device JWT signature does not verify, or required claims are missing.


{
"code": 401,
"error": "InvalidJWTToken",
"description": "Jwt token is invalid."
}
404 — PartnerNotFound

The appid claim on the device JWT does not map to a known partner / tenant — typically a token from a different environment.


{
"code": 404,
"error": "PartnerNotFound",
"description": "Partner not found."
}
404 — DomainNotFound

The {domain} path parameter does not match any merchant configured with Firmly, or the merchant has been disabled. Verify the domain string (case-sensitive, no protocol or trailing slash).


{
"code": 404,
"error": "DomainNotFound",
"description": "This domain was not found in firmly servers."
}
404 — CartNotFound

No cart exists for this device on this domain. There is nothing to clear.


{
"code": 404,
"error": "CartNotFound",
"description": "Cart was not found."
}
404 — ProductNotFound

The fallback clear path (used when an adapter does not implement a native clearCart) iterates over line items and removes them one by one. This error surfaces if one of those removals cannot be mapped back to a merchant product — typically a stale cart whose contents diverged from the merchant view.


{
"code": 404,
"error": "ProductNotFound",
"description": "Product not found."
}
412 — OperationNotSupported

The merchant’s platform does not support this operation. Check with Firmly whether this endpoint is available for the merchant.


{
"code": 412,
"error": "OperationNotSupported",
"description": "This operation is not supported for this store."
}