---
title: Generate a Quote or Invoice from Twenty
description: Automatically create invoices in external tools when deals close.
---
Automatically send deal data to your invoicing system (Stripe, QuickBooks, Xero, etc.) when an opportunity is won.
## Workflow Structure
1. **Trigger**: Record is Updated (Opportunity)
2. **Filter**: Stage = Closed Won
3. **Search Record**: Get Company details
4. **Code** (optional): Format payload
5. **HTTP Request**: Send to invoicing system
## Step 1: Set Up the Trigger
1. Create a new workflow
2. Select **Record is Updated** trigger
3. Choose **Opportunity** as the object
## Step 2: Filter for Closed Won
Add a **Filter** action to only continue when the deal is won:
| Setting | Value |
|---------|-------|
| **Field** | Stage |
| **Condition** | Equals |
| **Value** | `CLOSED_WON` (or your stage name) |
The trigger fires on any Opportunity update. The Filter ensures the workflow only continues when the stage changes to Closed Won.
## Step 3: Get Company Details
The Opportunity record may not include all Company fields you need for the invoice. Add a **Search Record** action:
| Setting | Value |
|---------|-------|
| **Object** | Company |
| **Match by** | ID equals `{{trigger.object.companyId}}` |
This retrieves the full Company record with billing address, tax ID, etc.
## Step 4: Format the Payload (Optional)
If your invoicing system expects a specific format, add a **Code** action:
```javascript
export const main = async (params: {
opportunity: any;
company: any;
}): Promise