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

# Automation examples

> Four complete automations, built step by step: what to pick in each field, and what a run does.

Each example lists what to set under **When**, each step with the values to pick, and what to give it under **Uses**. To build one, click **Automations**, then **+**, then **Start empty**, and follow the table. **Start empty** gives you step 1 as an empty AI step: where the table's step 1 is **Work something out**, fill in that step's brief rather than adding another. Add every other step with **Add a step**. Test it before you switch it on (see [Test before you switch on](https://docs.mercora.io/workflows/automations.md#test-before-you-switch-on)).

| Example | Shows how to |
| - | - |
| [Check an invoice against its contract](#check-an-invoice-against-its-contract) | Ask an AI step for a yes or no, act on it with **If**, and report a finding |
| [Fix an invoice's due date from its contract](#fix-an-invoices-due-date-from-its-contract) | Compare two values, and propose a change with **Update a record** |
| [Chase a missing B/L](#chase-a-missing-bl) | **Wait for** a document, then **Tell someone** if it never came |
| [Draft a hedge order when your ERP asks](#draft-a-hedge-order-when-your-erp-asks) | Take values from another system, **Find a record**, and get an approval |

## Check an invoice against its contract

Flags an invoice whose price, quantity or currency differ from its contract. An invoice that matches files nothing.

**When:** **When a document finishes processing**. **Types:** **Invoice**. **Wait for a trade match:** on.

| Step | Kind | Fill in |
| - | - | - |
| 1 | **Work something out** | **Brief:** "Compare this invoice with its trade's contract: price per unit, quantity and currency. Say whether they match and, if not, exactly what differs, with both values." |
| 2 | **If** | **Add a rule**. In **Pick a value**, type `Matches contract` and click **Ask step 1 for "matches contract"**. Test: **is no**. **Otherwise:** **Stop here, nothing to report**. |
| 3 | **Report a finding** | **Finding:** type `Invoice `, then **+ value** › **Invoice number** (from the document). In the next box type `differs:`, then **+ value**, type `What differs` and click **Ask step 1 for "what differs"**. |

On step 1, open **⋯** › **Add what happens if it fails** and pick **Ask someone**, so a failed comparison reaches you instead of ending the run.

**Uses:** **Read** on Trades, Contracts, Invoices & costs and Documents.

![The invoice check automation: When a document finishes processing, Invoice; steps Compare, If matches contract is no, Report a finding](https://mintcdn.com/placeholder-f4ffdeec/s6Fb5kGGc4sLUuXY/images/workflows/automations/example-invoice-check.png?fit=max\&auto=format\&n=s6Fb5kGGc4sLUuXY\&q=85\&s=a081a9aa04b4bfaa55259c16ed6d241f)

The invoice check: three steps.

**What a run does.** Supplier invoice KSS-INV-26-0288 from Kanchana Siam Sugar is matched to trade VCS-S-2026-0714. Step 1 reads it with purchase contract VCS-P-2026-0688 (27 MT at USD 528/MT) and hands back **matches contract**: yes. Step 2's rule doesn't hold, so the run stops there and files nothing. Had the invoice charged USD 540/MT, step 1 would hand back no, with what differs, and step 3 would put "Invoice KSS-INV-26-0288 differs: unit price USD 540/MT, contract USD 528/MT" in the Inbox.

## Fix an invoice's due date from its contract

Works out the due date from the contract's payment terms, and proposes it when the invoice says otherwise. Nothing changes until someone approves.

**When:** **When a document finishes processing**. **Types:** **Invoice**. **Wait for a trade match:** on.

| Step | Kind | Fill in |
| - | - | - |
| 1 | **Work something out** | **Brief:** "Read the payment terms on this invoice's contract and work out the due date they give for this invoice. Use the B/L date or invoice date the terms name, and write the date as YYYY-MM-DD." |
| 2 | **If** | **Add a rule**. In **Pick a value**, type `Due date` and click **Ask step 1 for "due date"**. Test: **is not**. Second value: **Due date** (from the document). **Otherwise:** **Stop here, nothing to report**. |
| 3 | **Update a record** | **Record type:** **Invoice**. **Record:** **The document** (from the document). Under **Fields to change**, type `due_date` and click **Add field**; for **Due date**, type `Due date` and click **Ask step 1 for "due date"**. **Approved by:** the owner. |

**Uses:** **Read** on Contracts and Documents; **Propose changes** on Invoices & costs.

![The due date automation: steps Read the payment terms, If due date is not due date, Update the invoice, Asks Alex Morgan first](https://mintcdn.com/placeholder-f4ffdeec/s6Fb5kGGc4sLUuXY/images/workflows/automations/example-due-date.png?fit=max\&auto=format\&n=s6Fb5kGGc4sLUuXY\&q=85\&s=b308f0e9ebe790ab88f67635886323ce)

Propose a due date only when it differs from the invoice's own.

**What a run does.** Step 1 reads the terms of contract VCS-P-2026-0688 and hands back a due date. If it's the date already on invoice KSS-INV-26-0288, the run stops. If not, step 3 puts the change in the Inbox: move the due date on KSS-INV-26-0288 to match the contract's terms. **Approve** makes it, **Edit** lets you change the date first, **Reject** changes nothing.

> [!TIP]
>
> **is** and **is not** compare text, ignoring capitals. Mercora keeps an invoice's due date as YYYY-MM-DD, and **Update a record** only accepts that form, so the brief asks for the date as YYYY-MM-DD: "13 Aug 2026" and "2026-08-13" are different text.

## Chase a missing B/L

Waits two weeks after a contract for its B/L, and tells you if it never reached the trade.

**When:** **When a document finishes processing**. **Types:** **Contract (Purchase or Sale)**. **Wait for a trade match:** on.

| Step | Kind | Fill in |
| - | - | - |
| 1 | **Wait for** | Add it, then delete the empty AI step above it (**⋯** › **Delete step**): an automation always keeps at least one step. **Wait for:** **A document to reach the trade**. **Document:** **Bill of Lading**. **On the trade:** **Its trade** (from the document; picked for you). **Up to:** `14` **days**, then **carry on without it**. |
| 2 | **If** | **Add a rule**. **Pick a value:** **The document** under **From step 1**. Test: **is empty**. **Otherwise:** **Stop here, nothing to report**. |
| 3 | **Tell someone** | **Tell:** the owner. **Note:** type `No B/L 14 days after this contract: `, then **+ value** › **Contract number** (from the document), then `. Chase the shipper.` |

**Uses:** these steps read no data themselves, so no area is needed.

![The missing B/L automation: Wait for a bill of lading on the trade up to 14 days, If the document is empty, Tell Alex Morgan](https://mintcdn.com/placeholder-f4ffdeec/s6Fb5kGGc4sLUuXY/images/workflows/automations/example-missing-bl.png?fit=max\&auto=format\&n=s6Fb5kGGc4sLUuXY\&q=85\&s=fb13421e8152e36bfb78a573047b0b29)

Wait, check, tell.

**What a run does.** Sales contract VCS-S-2026-0714 is matched to its trade, and step 1 starts waiting. When B/L RCLLCH2607841 reaches the trade, step 1 hands it on, step 2's rule doesn't hold, and the run ends quietly. If no B/L arrives within 14 days, step 1 carries on with no document, and step 3 leaves a note in your Inbox: "No B/L 14 days after this contract: VCS-S-2026-0714. Chase the shipper."

Only a B/L that reaches the trade after the run started counts. A trade whose B/L came in before its contract would get the note too, so use this where contracts come first.

## Draft a hedge order when your ERP asks

Your ERP sends a contract number and a number of lots. Mercora finds the contract, drafts the broker order, and waits for your approval.

**When:** **When another system calls**. Under **Fields it sends**, add `contract_number` (**Text**) and `lots` (**Number**). Once the steps and **Uses** are in place, name the automation and click **Save**: its address then shows under **When**, for your ERP to call.

| Step | Kind | Fill in |
| - | - | - |
| 1 | **Find a record** | Add it, then delete the empty AI step above it. **Record type:** **Contract**. **Reference:** **Contract number** (from the request). |
| 2 | **If** | **Add a rule**. **Pick a value:** **Its id** under **From step 1 · Find a record**. Test: **is not empty**. **Otherwise:** **Stop here, nothing to report**. |
| 3 | **Work something out** | **Brief:** "Draft the broker order to hedge this contract: the futures market and month that match its pricing, buy or sell, and the number of lots the request asks for." |
| 4 | **Ask someone to approve** | **What** the owner **approves:** keep "Approve what the step before drafted", or write your own. **Approved by:** the person who approves hedges. |
| 5 | **Tell someone** | **Note:** `Hedge order approved. Contract: `, **+ value** › **Contract number** (from the request), `, lots: `, **+ value** › **Lots** (from the request). |

**Uses:** **Read** on Contracts and Trades.

![The hedge order automation: When another system calls with contract\_number and lots; steps Find the contract, If its id is not empty, Draft the broker order, Alex Morgan approves, Tell Alex Morgan](https://mintcdn.com/placeholder-f4ffdeec/s6Fb5kGGc4sLUuXY/images/workflows/automations/example-api-request.png?fit=max\&auto=format\&n=s6Fb5kGGc4sLUuXY\&q=85\&s=7828f4f91dd4aec10ed09377d84ec3fa)

The ERP's request, from finding the contract to the approved order.

**What a run does.** The ERP calls the address with:

```json theme={"system"}
{ "external_id": "erp-hedge-4711", "input": { "contract_number": "VCS-S-2026-0714", "lots": 3 } }
```

Step 1 finds contract VCS-S-2026-0714. Step 3 drafts the order for 3 lots, and step 4 puts it in the approver's Inbox to approve, edit or reject. Once approved, step 5 leaves the note "Hedge order approved. Contract: VCS-S-2026-0714, lots: 3". If the ERP sends a contract number Mercora doesn't have, step 1 finds nothing, step 2 stops the run, and nothing is drafted.

## Next steps

* [Use values from earlier steps](https://docs.mercora.io/workflows/automation-values.md): every way a step can take a value.
* [Steps](https://docs.mercora.io/workflows/automation-steps.md): the fields of every step, including app actions that send the order on.


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