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

# Manage a Store Cart

> Add, remove, and list the items in a user's cart at a merchant, then check out later

An agent checkout can change a user's cart at a merchant without buying. Your agent can add items over several days, tell the user what is in the cart, and check out when the user is ready.

<video className="w-full rounded-xl" autoPlay muted loop playsInline src="https://mintcdn.com/crossmint/eLFFFOlQTcnBWJ-s/images/agents/checkouts/cart-later.mp4?fit=max&auto=format&n=eLFFFOlQTcnBWJ-s&q=85&s=f05a5183467e0d1fbe84a62553fb4f7c" data-path="images/agents/checkouts/cart-later.mp4" />

The API has no cart endpoint. You write the cart change in the `task`, and a browser profile keeps the cart at the merchant for the next checkout.

## Prerequisites

* **Agent Checkouts integration** — complete the [quickstart](/agents/agent-checkouts-quickstart).
* **Browser profile** — create one for the user. See [Sign In to Stores](/agents/checkouts/merchant-sessions). Many merchants keep the cart only for a signed-in user.
* **Server key** — a production key with `agent-checkouts.create`, `agent-checkouts.read`, `agent-checkouts.update`, and `agent-checkouts.cancel`.

## Change the Cart

<Steps>
  <Step title="Start a checkout that only changes the cart">
    Write the change in the task, and tell the checkout not to pay. Start at the product page to add an item. Start at the merchant's cart page to remove items, to empty the cart, or to list it.

    <CodeGroup>
      ```bash cURL theme={null}
      curl --fail-with-body --request POST "https://www.crossmint.com/api/unstable/agent-checkouts" \
          --header "X-API-KEY: YOUR_SERVER_API_KEY" \
          --header "x-crossmint-user-id: YOUR_USER_ID" \
          --header "Content-Type: application/json" \
          --data '{
              "request": {
                  "startUrl": "https://shop.example.com/products/wool-socks",
                  "task": "Add one pair of wool socks in grey, size L, to the cart. Only change the cart. Do not check out and do not pay. When you are done, list what is in the cart, with the prices and the cart total."
              },
              "browser": { "profileId": "YOUR_BROWSER_PROFILE_ID" },
              "constraints": { "maxCost": { "amount": "100.00", "currency": "USD" } }
          }'
      ```

      ```typescript Node.js theme={null}
      const response = await fetch("https://www.crossmint.com/api/unstable/agent-checkouts", {
          method: "POST",
          headers: {
              "Content-Type": "application/json",
              "X-API-KEY": process.env.CROSSMINT_SERVER_API_KEY!,
              "x-crossmint-user-id": "YOUR_USER_ID",
          },
          body: JSON.stringify({
              request: {
                  startUrl: "https://shop.example.com/products/wool-socks",
                  task: "Add one pair of wool socks in grey, size L, to the cart. Only change the cart. Do not check out and do not pay. When you are done, list what is in the cart, with the prices and the cart total.",
              },
              browser: { profileId: "YOUR_BROWSER_PROFILE_ID" },
              constraints: { maxCost: { amount: "100.00", currency: "USD" } },
          }),
      });
      if (!response.ok) {
          throw new Error(`Could not start checkout: ${response.status}`);
      }
      const { runId } = await response.json();
      ```

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

      import requests

      response = requests.post(
          "https://www.crossmint.com/api/unstable/agent-checkouts",
          headers={
              "X-API-KEY": os.environ["CROSSMINT_SERVER_API_KEY"],
              "x-crossmint-user-id": "YOUR_USER_ID",
          },
          json={
              "request": {
                  "startUrl": "https://shop.example.com/products/wool-socks",
                  "task": (
                      "Add one pair of wool socks in grey, size L, to the cart. "
                      "Only change the cart. Do not check out and do not pay. "
                      "When you are done, list what is in the cart, "
                      "with the prices and the cart total."
                  ),
              },
              "browser": {"profileId": "YOUR_BROWSER_PROFILE_ID"},
              "constraints": {"maxCost": {"amount": "100.00", "currency": "USD"}},
          },
      )
      response.raise_for_status()
      run_id = response.json()["runId"]
      ```
    </CodeGroup>

    `constraints.maxCost` is required. Set it to a value that is higher than the cart total.
  </Step>

  <Step title="Answer questions and stop any payment request">
    [Follow the checkout](/agents/checkouts/follow-run) and answer its questions, such as a size or a sign-in. See [Answer Questions](/agents/checkouts/buyer-inputs).

    If a payment request arrives, do not answer it. Cancel the checkout with `POST /api/unstable/agent-checkouts/{runId}/cancel`.
  </Step>

  <Step title="Show the cart to the user">
    When the checkout ends, read `result.summary`. It lists the items in the cart, with the prices and the total. Show it to your user.
  </Step>
</Steps>

## Check Out Later

When the user is ready to buy, start a normal checkout with the same `browser.profileId`. Start at the merchant's cart page, with a task such as "Check out the items in the cart. Use standard shipping." Then answer the payment request with an order intent. See [Pay for a Checkout](/agents/checkouts/payments).

## Common Gotchas

<AccordionGroup>
  <Accordion title="The cart is empty on the next checkout">
    The checkout ran without a browser profile, or the merchant keeps the cart only for a signed-in user. Attach the same `browser.profileId` to each checkout, and sign in once. Some merchants also clear a cart after some time.
  </Accordion>

  <Accordion title="Each cart change is a checkout">
    Crossmint bills each checkout that starts. Group several changes in one task when you can, for example "Add the socks and remove the hat".
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={3}>
  <Card title="Buy Several Items in One Order" icon="cart-shopping" href="/agents/checkouts/use-cases/buy-several-items">
    Buy a full cart with one payment
  </Card>

  <Card title="Buy When the Price Drops" icon="arrow-trend-down" href="/agents/checkouts/use-cases/buy-when-the-price-drops">
    Check out later, when the price is right
  </Card>

  <Card title="Create a Checkout" icon="brackets-curly" href="/api-reference/agent-checkouts/create-agent-checkout">
    Review the complete create request schema
  </Card>
</CardGroup>
