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

# Orders

> How an order is placed, the states it moves through, and what commit_unknown means.

An order exists once the shopper confirms a checkout. Your agent asks for the order with `complete_checkout`. The shopper places it.

## How an order is placed

1. Your agent calls `complete_checkout` with `thread_id`, `review_hash` and `total` from the latest checkout read.
2. AgentMall checks them against the stored review and returns `status: "awaiting_confirmation"` with a `confirm_url`.
3. Your agent shows the `confirm_url` to the shopper.
4. The shopper opens it, sees the items, totals, address, delivery and card, and clicks **Place order**.
5. AgentMall takes the order fee from your credit, submits the order to the merchant, and ends the thread.

The link works once. Steps 4 and 5 happen in the shopper's browser, so your agent does not get the result from `complete_checkout`. Once the merchant has answered, the thread ends and every call on it returns `thread_ended`. When the thread placed an order, the error carries its `order_id`. Pass that id to `get_order`. The message says `ordered` when the order was placed.

```json theme={null}
{
  "error": {
    "code": "thread_ended",
    "message": "This thread ended (ordered). Start a new thread.",
    "retry": "never",
    "order_id": "ord_…"
  }
}
```

The order is also listed on the console [Orders](https://console.getagentmall.com/orders) page. Each row links to `/orders/ord_…`.

To get a new link, call `complete_checkout` again. The new link replaces the old one.

## States

`get_order` returns `status`:

| `status` | Meaning | What to do |
| - | - | - |
| `pending` | The order is being submitted to the merchant | Read it again in a few seconds |
| `completed` | The merchant accepted the order | Done |
| `failed` | The merchant did not accept it. Nothing was placed. The fee was refunded | Start a new thread to try again |
| `unknown` | The order was submitted but no confirmation came back | Do not try again. See below |
| `canceled` | The merchant shows the order as cancelled | Done |

`merchant_status` is the status text from the merchant's order page, for example `Shipped`, when AgentMall could read it. `permalink_url` links to the order on the merchant site.

## Reading an order

```json theme={null}
{ "id": "ord_…" }
```

`get_order` takes the order id and no thread. On REST it is `GET /v1/orders/:id`. For a live order with a merchant order number, it opens the merchant's order page and returns the live status and totals. When the page has no total, or the order has no merchant number yet, it returns the stored order.

A test order (`test: true`) is returned as stored. The merchant is never opened.

| Code | What to do |
| - | - |
| `order_not_found` | No order with that id in your organization. Use the `order_id` from `thread_ended`. |
| `order_unreadable` | The order exists but its merchant page could not be read. Retry later. |
| `browser_unavailable` | No browser is free. Retry after `retry_after_seconds`. |

Order tracking (carrier and tracking number) is not available yet.

## `commit_unknown`

The order was submitted to the merchant and AgentMall did not see a confirmation. It may exist at the merchant.

* Do not create a new thread and order the same items. That can place the order twice.
* The thread has ended, so calls on it return `thread_ended` with the `order_id`.
* `get_order` shows `unknown` until AgentMall knows the outcome. The fee is not refunded while the outcome is unknown.

Tell the shopper the order may have gone through and to check their merchant account.

## Returns

Returns, refunds and cancellations are not available through AgentMall. The shopper handles them with the merchant directly.


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