> For the complete documentation index, see [llms.txt](https://docs.riff.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.riff.ai/playbooks/procurement/match-purchase-orders.md).

# Match purchase orders to invoices

**Best fit:** Agent **ERP systems:** Infor LN / M3, SAP S/4HANA, Oracle ERP Cloud, Microsoft Dynamics 365 **Time to build:** \~30 minutes

***

## What you're building

A Riff agent that performs three-way matching — purchase order to goods receipt to supplier invoice — and flags discrepancies before they reach the payment run. Your accounts payable team stops reviewing every invoice manually; they review only the ones the agent can't resolve automatically.

***

## What you need

* Riff workspace with your ERP connected
* Read access to purchase orders, goods receipts, and incoming invoices
* Write access to add notes or hold invoices for review
* Defined tolerance thresholds (e.g. accept price variance up to 2%, quantity variance up to 5%)

***

## Step 1: Define the matching rules

Write down your matching logic before you brief the agent:

* **Matching criteria**: PO number on invoice + matching line items + quantity within tolerance
* **Price tolerance**: e.g. invoice price must be within 2% of PO price
* **Quantity tolerance**: e.g. invoice quantity must match GR quantity within 5%
* **What to do on match**: approve for payment (or flag for scheduled payment run)
* **What to do on mismatch**: hold invoice, add note with discrepancy detail, alert AP team

***

## Step 2: Create the agent

1. Click **+ New** → **Agent**
2. Name it — e.g. "PO Matching Agent"
3. In the **Profile** tab:

> You process incoming supplier invoices in \[ERP]. For each invoice, you check it against the corresponding purchase order and goods receipt (three-way match). If the invoice price is within 2% of the PO price and the quantity matches the GR within 5%, you approve the invoice for the next payment run. If the discrepancy is outside tolerance, you hold the invoice and add a note explaining the specific mismatch. You then alert the AP controller with a summary of held invoices.

***

## Step 3: Connect your ERP

Each ERP handles GR/IR differently:

* **SAP S/4HANA**: GR/IR clearing account (transaction MR11), Logistics Invoice Verification (MIRO)
* **Infor LN**: Purchase order receipts matched against purchase invoices in the PO module
* **Oracle ERP Cloud**: Receipt accounting and payables matching via the Financial Orchestrator
* **Dynamics 365**: Invoice matching in Accounts Payable → Vendor invoices

Connect your ERP in the **Integrations** tab and test that the agent can read invoices, POs, and GRs.

***

## Step 4: Set the trigger

* **Schedule**: run after your ERP's daily invoice processing batch (e.g. daily at 19:00)
* **Real-time**: add an integration event trigger if your ERP supports invoice-received webhooks

***

## Step 5: Test with a sample

1. In the **Chat** tab: `Show me the five most recent invoices and their matching status`
2. Pick one matched and one unmatched invoice
3. `Run a three-way match on invoice INV-XXXXX` — confirm the output is correct
4. Check that discrepancies are flagged and notes are added correctly

***

## What good looks like

* AP team only touches invoices with genuine discrepancies
* Every matched and held invoice has a note in your ERP explaining why
* Held invoices are cleared (or escalated) before the payment run
* The agent's Activity log is the audit trail — every match decision is logged

***

## Variations

**If invoices arrive by email (PDF):** Add an email trigger. The agent reads the PDF, extracts invoice data, and runs the match.

**If your ERP auto-books GRs at a time lag:** Add a buffer (e.g. don't match invoices arriving within 24 hours of the PO — wait for the GR to land).

**If you have multiple legal entities:** Brief the agent with entity-specific tolerances and route escalations to the correct AP controller per entity.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.riff.ai/playbooks/procurement/match-purchase-orders.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
