# Turn a won deal into a draft invoice

Create one Xero draft invoice from the products on a won Pipedrive deal. Finance reviews the customer, tax, currency, and payment terms in Xero before approving in Slack.

**Category** Revenue Operations  
**Tools** n8n, Pipedrive, Xero, Slack  
**Trigger** Authenticated POST from your won-deal relay  
**Package** [Workflow JSON](won-deal-draft-invoice.n8n.json) · [Test payloads](test-payloads.json) · [Validation report](validation-report.txt)

Import the JSON in n8n and run **Run with sample data**. The workflow imports inactive with **dryRun** enabled. The sample run uses fictional data and skips connected apps. Select credentials on the named nodes before testing live inputs.

## How it works

1. Verify the deal is won and read its enabled products. Map supported prices, quantities, percentage discounts, and the configured tax basis to Xero.
2. Check the trusted Xero contact ID and look for the deterministic invoice number. If it is new, create the draft and ask the designated finance reviewer to approve it in Slack.
3. With authorization enabled, recheck the deal and unchanged Xero draft before authorizing. With email enabled as well, confirm the primary contact email and send from Xero.

## How to use

1. In **Setup**, set the Pipedrive subdomain, Xero tenant UUID, revenue account code, tax type and basis, invoice prefix, terms in days, and finance reviewer Slack ID. Use a unique invoice prefix in that Xero organization. The finance owner should verify tax mappings in a demo organization.
2. Attach a **Header Auth** credential with **x-api-token** to the Pipedrive HTTP nodes. Attach **Xero OAuth2 API** to the Xero HTTP nodes. Use an integration account with access to invoices and contacts in the configured tenant.
3. Set up the Slack app for signed approvals using **Capture Who Responded**. Select the bot credential and signing secret on **Ask finance in Slack**.
4. Attach a separate inbound **Header Auth** credential to **Receive event**. Send **dealId** and the mapped **xeroContactId** from a trusted service. The webhook acknowledges receipt. The execution and Xero show the result.
5. In staging, disable dry run while leaving **authorizeAfterApproval** and **emailAfterAuthorization** false. Verify the draft before enabling either option. Only supported one-time items with one currency and one tax basis are included. Amount-based discounts and recurring products need manual handling.

## Test and operate

| Scenario | Expected result |
| --- | --- |
| A won deal has valid one-time products | One Xero draft with the expected lines and invoice number |
| The same deal event is replayed | Existing invoice is found and the flow stops |
| A different reviewer approves or the draft changes | Authorization is prevented |
| The contact has changed or additional email recipients | The email step stops and finance handles delivery manually |

If a write fails or the approval expires, look up the invoice number in Xero before rerunning. Reconcile the existing draft and approval there. Test Xero email delivery using an address you own.

[n8n source](https://n8n.io/workflows/20013-create-and-approve-xero-invoices-from-pipedrive-closed-won-deals-with-slack/) · [Xero invoices API](https://developer.xero.com/documentation/api/accounting/invoices) · [n8n Slack approvals](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.slack/approvals)
