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

# Execution and approval

> Turn a recommendation into an order, approve it under maker-checker rules, write it back to the ERP, and read the evidence behind it.

Turn a recommendation into an executable order governed by a maker-checker state machine, then write it back to the source ERP. Separation of duties is enforced server-side: the approver must be a different organization admin than the proposer. Every transition is audited.

## With an API key

Every call here takes an API key. A key acts for the person who created it: that person is recorded as the proposer or approver, so a key cannot approve an order its creator proposed, and it can do no more than its creator can today. A key whose creator has left the organization stops working here.

Proposing, changing a proposed order's quantity and cancelling need the `execute` scope. Approving, rejecting, executing and verifying need the `approve` scope, which only an organization admin can put on a key. Reading the execution rules (`get_policies`) needs `read`.

| Method | Path | Scope | What it does |
| - | - | - | - |
| `GET` | `/v1/recommendations` | `read` | Recommendations from every agent with their status, newest first |
| `GET` | `/v1/recommendations/:id` | `read` | One recommendation |
| `POST` | `/v1/recommendations/:id/approve` | `execute` | Approve a recommendation. Takes no body |
| `POST` | `/v1/recommendations/:id/dismiss` | `execute` | Dismiss a recommendation. Takes no body |
| `GET` | `/v1/orders` | `read` | Orders in the approval loop with payload, policy decision, proposer and approver |
| `GET` | `/v1/orders/:id` | `read` | One order |
| `POST` | `/v1/orders/actions` | by action | Act in the approval loop |

List proposed recommendations:

```bash theme={null}
curl "https://api.insightchain.ai/v1/recommendations?status=proposed&limit=50" \
  -H "Authorization: Bearer YOUR_API_KEY"
# → { "object": "list",
#     "data": [ { "id": "…", "kind": "rebalance", "item": { "external_id": "…" }, … } ],
#     "has_more": true, "next_cursor": "…" }
```

## Actions

`POST /v1/orders/actions` takes an `action` in its body:

| Action | Who | What it does |
| - | - | - |
| `propose` | Any organization member (the maker) | Turns a recommendation into a proposed order; with `quantity` and `quantity_reason`, at the planner's quantity instead of the recommended one |
| `edit_quantity` | The maker or an organization admin | Changes the quantity of an order still waiting for approval. Whoever changes it becomes the maker, so the approver is always someone else |
| `approve` | An organization admin who is not the maker | Approves the order |
| `reject` | An organization admin who is not the maker | Rejects the order |
| `cancel` | The maker or an admin | Cancels a proposed or approved order |
| `execute` | An organization admin | Runs an approved order: live ERP write-back, dry-run, or manual |
| `verify` | An organization admin | Verifies an order; the answer's `verification` has the outcome (`verified`, `differences` or `not_verified`) and any differences |
| `get_policies` | Any key with `read` | Returns the execution rules (`policies`), the order kinds and the connections that can be written to |

## Lifecycle

```text theme={null}
proposed ──approve──▶ approved ──execute──▶ executing ──▶ executed
   │                    │                                  ├─▶ partially_applied
   │                    │                                  └─▶ failed
   └─reject──▶ rejected └─cancel──▶ canceled
```

## Examples

Propose (maker):

```bash theme={null}
curl -X POST "https://api.insightchain.ai/v1/orders/actions" \
  -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" \
  -d '{ "action": "propose", "recommendation_id": "RECOMMENDATION_ID" }'
```

Change the quantity before approval:

```bash theme={null}
# at propose: the recommended quantity is kept on the order's snapshot
curl -X POST "https://api.insightchain.ai/v1/orders/actions" \
  -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" \
  -d '{ "action": "propose", "recommendation_id": "RECOMMENDATION_ID", "quantity": 36, "quantity_reason": "Window display next week" }'
# on an order that waits for approval
curl -X POST "https://api.insightchain.ai/v1/orders/actions" \
  -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" \
  -d '{ "action": "edit_quantity", "order_id": "ORDER_ID", "quantity": 36, "reason": "Window display next week" }'
# → { "order": { "status": "proposed", "quantity": 36, "previous_quantity": 24, "amount": 180 } }
# 422 with "code" when the order's own constraints refuse it: not_a_multiple, below_minimum_order, above_maximum.
# A changed quantity is never approved by a rule: a person other than the one who set it approves.
```

Approve then execute (a different admin):

```bash theme={null}
# approve
curl -X POST "https://api.insightchain.ai/v1/orders/actions" \
  -H "Authorization: Bearer YOUR_APPROVE_KEY" -H "Content-Type: application/json" \
  -d '{ "action": "approve", "order_id": "ORDER_ID" }'
# execute (writes to the ERP when write-back is enabled; else dry-run/manual)
curl -X POST "https://api.insightchain.ai/v1/orders/actions" \
  -H "Authorization: Bearer YOUR_APPROVE_KEY" -H "Content-Type: application/json" \
  -d '{ "action": "execute", "order_id": "ORDER_ID" }'
# → { "order": { "status": "executed", "mode": "live", "external_ref": "4500000123" } }
```

Send an `Idempotency-Key` header to retry any of these safely; see [Conventions](/docs/conventions.md#idempotency-key).

## Explanations

`POST /v1/explanations` returns the evidence behind a recommendation: the driving signal, the demand figures, cost and benefit, a confidence with its reason, and data lineage. The answer also carries a plain-English `narrative`. With `use_ai` set to `true` the narrative is written by AI from the same evidence; otherwise it comes from a template, and `narrative_source` says which you got. Takes an API key with the `read` scope.

```bash theme={null}
curl -X POST "https://api.insightchain.ai/v1/explanations" \
  -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" \
  -d '{ "recommendation_id": "RECOMMENDATION_ID", "use_ai": false }'
```

Response: `200 OK`.

```json theme={null}
{
  "evidence": {
    "headline": "Move 40 Classic Polo from DC-East to Store-42",
    "drivers": [ { "label": "Destination days of cover", "value": "2.1 days" }, … ],
    "cost_benefit": [ { "label": "Inventory value moved", "value": "$800" }, … ],
    "confidence": "High",
    "confidence_reason": "priority score 82; data is current",
    "lineage": [ { "label": "Data as of", "value": "2026-07-12" }, … ]
  },
  "narrative": "Move 40 Classic Polo from DC-East to Store-42. Why: …",
  "narrative_source": "template"
}
```


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