Gmailのラベルを使用してGPT-4O+QuickBooksで自動のにインボイスを作成する
上級
これはInvoice Processing, AI Summarization分野の自動化ワークフローで、23個のノードを含みます。主にCode, Gmail, Quickbooks, Agent, ScheduleTriggerなどのノードを使用。 GmailのタグからGPT-4O + QuickBooksを使って自動のに請求書を作成
前提条件
- •Googleアカウント + Gmail API認証情報
- •OpenAI API Key
ワークフロープレビュー
ノード接続関係を可視化、ズームとパンをサポート
ワークフローをエクスポート
以下のJSON設定をn8nにインポートして、このワークフローを使用できます
{
"meta": {
"instanceId": "d6e2f2f655b1125bbcac14a4cac6d2e46c7a150e927f85fc96fdca1a6dc39e0e",
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "5f0e5680-7bb4-4c96-b427-233f0fd35d9a",
"name": "顧客をQBOに追加",
"type": "n8n-nodes-base.quickbooks",
"onError": "continueRegularOutput",
"position": [
540,
500
],
"parameters": {
"operation": "create",
"displayName": "={{ $json.output.company_name ? $json.output.company_name : $json.output.client_full_name }}",
"additionalFields": {
"BillAddr": {
"details": {
"City": "={{ $json.output.city }}",
"Line1": "={{ $json.output.address_line_1 }}",
"PostalCode": "={{ $json.output.postal_code }}",
"CountrySubDivisionCode": "CA"
}
},
"GivenName": "={{ $json.output.client_first_name }}",
"FamilyName": "={{ $json.output.client_last_name }}",
"CompanyName": "={{ $json.output.company_name ? $json.output.company_name : \"\" }}",
"PrimaryPhone": "={{ $json.output.client_phone }}",
"PrimaryEmailAddr": "={{ $json.output.client_email }}"
}
},
"credentials": {
"quickBooksOAuth2Api": {
"id": "6ufAa1KkttZDj17m",
"name": "QuickBooks Online account"
}
},
"typeVersion": 1
},
{
"id": "8d3af3f2-77ab-4788-8a92-2efc7be5ca42",
"name": "「請求書必要」ラベル付きメッセージを取得",
"type": "n8n-nodes-base.gmail",
"position": [
220,
20
],
"webhookId": "1cb550a2-0c63-45a3-baa5-c04cd8d03f68",
"parameters": {
"simple": false,
"filters": {
"labelIds": [
"Label_6581962793477761592"
]
},
"options": {},
"operation": "getAll",
"returnAll": true
},
"credentials": {
"gmailOAuth2": {
"id": "YVZiLPppXZw84rIU",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "c76c499b-fd1b-440e-be22-3737a223c02c",
"name": "OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
60,
720
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4o-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "XqsFFpRk48U68Fou",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "6ef8c67e-c5ba-4dc0-97e9-eebfc1a47db0",
"name": "Structured Output Parser",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
280,
720
],
"parameters": {
"schemaType": "manual",
"inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"client_first_name\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n \"client_last_name\": {\n \t\t\t\"type\": \"string\"\n \t\t},\n \"client_full_name\": {\n \t\t\t\"type\": \"string\"\n \t\t},\n \"company_name\": {\n \t\t\t\"type\": \"string\"\n \t\t},\n \"client_email\": {\n \t\t\t\"type\": \"string\"\n \t\t},\n \"client_phone\": {\n \t\t\t\"type\": \"string\"\n \t\t},\n \"address_line_1\": {\n \t\t\t\"type\": \"string\"\n \t\t},\n \"city\": {\n \t\t\t\"type\": \"string\"\n \t\t},\n \"province\": {\n \t\t\t\"type\": \"string\"\n \t\t},\n \"postal_code\": {\n \t\t\t\"type\": \"string\"\n \t\t},\n \"invoiceAmount\": {\n \t\t\t\"type\": \"double\"\n \t\t},\n \"invoiceDescription\": {\n \t\t\t\"type\": \"text\"\n \t\t}\n\t}\n}"
},
"typeVersion": 1.2
},
{
"id": "8e74cb95-64fa-4969-88ef-782631a1dbe9",
"name": "既存顧客を検索",
"type": "n8n-nodes-base.quickbooks",
"position": [
800,
500
],
"parameters": {
"limit": 1,
"filters": {
"query": "=WHERE DisplayName = '{{ $('AI Agent: Extract Customer & Invoice Details').item.json.output.company_name ? $('AI Agent: Extract Customer & Invoice Details').item.json.output.company_name : $('AI Agent: Extract Customer & Invoice Details').item.json.output.client_full_name }}'"
},
"operation": "getAll"
},
"credentials": {
"quickBooksOAuth2Api": {
"id": "6ufAa1KkttZDj17m",
"name": "QuickBooks Online account"
}
},
"typeVersion": 1
},
{
"id": "4c7cb8d6-97d2-49a7-9307-9faeb04b2573",
"name": "新規請求書を作成",
"type": "n8n-nodes-base.quickbooks",
"position": [
1060,
520
],
"parameters": {
"Line": [
{
"Amount": "={{ $('AI Agent: Extract Customer & Invoice Details').item.json.output.invoiceAmount }}",
"itemId": "13",
"DetailType": "SalesItemLineDetail",
"TaxCodeRef": "5",
"Description": "={{ $('AI Agent: Extract Customer & Invoice Details').item.json.output.invoiceDescription }}"
}
],
"resource": "invoice",
"operation": "create",
"CustomerRef": "={{ $json.Id ? $json.Id : $('Add Client to QBO').item.json.Id }}",
"additionalFields": {
"DueDate": "={{ $now }}"
}
},
"credentials": {
"quickBooksOAuth2Api": {
"id": "6ufAa1KkttZDj17m",
"name": "QuickBooks Online account"
}
},
"typeVersion": 1
},
{
"id": "1df01733-3f95-478f-bc2e-2eba2d3da4a9",
"name": "請求書をダウンロード",
"type": "n8n-nodes-base.quickbooks",
"position": [
640,
940
],
"parameters": {
"download": true,
"fileName": "=Invoice - {{ $json.CustomerRef.name ? $json.CustomerRef.name : $json.TxnDate }}.pdf",
"resource": "invoice",
"invoiceId": "={{ $json.Id }}",
"binaryProperty": "invoice"
},
"credentials": {
"quickBooksOAuth2Api": {
"id": "6ufAa1KkttZDj17m",
"name": "QuickBooks Online account"
}
},
"typeVersion": 1
},
{
"id": "6ca60364-5d5b-45e0-9d73-63c34b20c47d",
"name": "クライアントへの下書き返信を作成",
"type": "n8n-nodes-base.gmail",
"position": [
920,
940
],
"webhookId": "433b7c52-32b5-4bac-8d88-9b0cc63da43b",
"parameters": {
"message": "=<p>Hello {{ $('AI Agent: Extract Customer & Invoice Details').item.json.output.client_first_name }},</p>\n<p>Please see attached for your invoice:</p>\n<p>Best,<br>An Efficient Person</p>",
"options": {
"threadId": "={{ $('Combine all Messages in a Thread').item.json.threadId }}",
"attachmentsUi": {
"attachmentsBinary": [
{
"property": "invoice"
}
]
}
},
"subject": "=",
"resource": "draft",
"emailType": "html"
},
"credentials": {
"gmailOAuth2": {
"id": "YVZiLPppXZw84rIU",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "f5c6f49d-5e21-48ae-bc4e-750cd4d5bd4a",
"name": "スケジュールトリガー",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
-40,
20
],
"parameters": {
"rule": {
"interval": [
{
"field": "hours"
}
]
}
},
"typeVersion": 1.2
},
{
"id": "c01cc24c-99cd-4c16-80db-db71a6362859",
"name": "AIエージェント:顧客・請求書詳細を抽出",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
60,
500
],
"parameters": {
"options": {
"systemMessage": "You are a helpful assistant who needs to create an invoice based on the email(s) provided. Please extract the necessary details to create an invoice:\n- Customer name and/or company name (if provided) (Required)\n- The amount of the invoice before taxes (Required)\n- The description of the product/service being purchased\n- Billing Address\n- client phone number\n- client email address\n- "
},
"hasOutputParser": true
},
"typeVersion": 1.9
},
{
"id": "60aeb85f-b6ef-4c47-bb88-d2431a95f7f2",
"name": "「請求書必要」ラベルを削除",
"type": "n8n-nodes-base.gmail",
"position": [
1180,
940
],
"webhookId": "406d3985-d16c-421e-b6a8-5e36b5df7db8",
"parameters": {
"labelIds": [
"Label_6581962793477761592"
],
"resource": "thread",
"threadId": "={{ $json.message.threadId }}",
"operation": "removeLabels"
},
"credentials": {
"gmailOAuth2": {
"id": "YVZiLPppXZw84rIU",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "13d90021-d6b4-464c-bbf4-d2866e4452b8",
"name": "付箋",
"type": "n8n-nodes-base.stickyNote",
"position": [
-800,
-280
],
"parameters": {
"width": 660,
"height": 1700,
"content": "## Automatically Create and Draft Invoices from Labeled Emails Using AI + QuickBooks\n\n## What It Does\nThis workflow reads Gmail threads labeled `Invoice Needed`, extracts invoice and client details using an AI agent, and creates a draft invoice in QuickBooks Online. It then downloads the invoice as a PDF and drafts a reply email with the invoice attached — all automatically.\n\nPerfect for freelancers, agencies, or small businesses looking to streamline client billing from email.\n\n## Prerequisites\nTo use this workflow, you’ll need:\n\n- A Gmail OAuth2 credential\n- A QuickBooks OAuth2 credential\n- An OpenAI credential (for AI-powered data extraction)\n\n## How to Label Threads\n- In Gmail, apply the label `Invoice Needed` to any email thread that contains details for an invoice request.\n- The workflow will process only those threads.\n\n## How It Works\n1. **Trigger:** The workflow runs on a schedule (e.g., every hour)\n2. **Fetch Emails:** Gmail node pulls all threads with the `Invoice Needed` label\n3. **Group Messages:** Emails in each thread are grouped together\n4. **AI Extraction:** An OpenAI-powered agent extracts client info, billing address, invoice amount, and description\n5. **Add a New Client:** This node will attempt to create a new client in QuickBooks\n6. **Find Existing Client** If the client already exists, this node will find the client's id\n7. **Create Invoice:** An invoice is created based on the extracted details\n8. **Download PDF:** The invoice is saved as a PDF\n9. **Draft Reply:** A Gmail draft is created with a template message and the invoice attached\n10. **Remove Label:** The processed thread is untagged to avoid duplicates\n\n## Example Use Cases\n- Automatically generate invoices from client emails\n- Use AI to extract invoice data without manual input\n- Ensure consistent and timely billing\n- Create a paper trail with attached PDFs in replies\n- Free up your inbox by processing and clearing labeled threads\n\n## How to Use\n- Set your schedule (e.g., every hour or more often if needed)\n- Select a product in the `Create A New Invoice` node\n- Ask the client to provide invoice details if needed (company name, billing address)\n- Add the `Invoice Needed` label to threads manually, via a Gmail filter or via another workflow\n- Review and send the drafted replies in Gmail\n- Optionally, add your branding or custom template to the email message\n\n## Optimization Instructions:\n- For larger companies with frequent invoice requests, consider shortening the interval between workflow runs. This helps prevent the system from processing too many labeled threads at once, ensuring smoother performance and faster response times.\n\n## Customization Options\n- Add line multiple items based on the product or service purchased instead of a single invoice row\n- Add conditional logic to skip certain threads\n- Auto-send emails instead of saving drafts (after testing)\n- Use custom prompts to extract additional fields\n\n## Why It's Useful\nThis workflow eliminates the manual labor of crafting invoices from scratch by automating the entire process—from email to invoice. It reduces the need to switch between multiple apps, since you no longer have to open QuickBooks Online to create an invoice. By streamlining your billing workflow, it saves time, minimizes errors, and lets you stay focused on your actual work while still keeping full control over outgoing communications."
},
"typeVersion": 1
},
{
"id": "124c54fc-301d-48dc-8569-083ae9350cbf",
"name": "付箋1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-100,
-160
],
"parameters": {
"color": 7,
"height": 360,
"content": "## Schedule\nThis node determines how often the workflow should check for newly labeled emails. Adjust this to control how responsive or resource-efficient your automation is.\n\n"
},
"typeVersion": 1
},
{
"id": "3657dde0-5110-4ea8-95bc-0301e9da5045",
"name": "付箋2",
"type": "n8n-nodes-base.stickyNote",
"position": [
160,
-160
],
"parameters": {
"color": 7,
"height": 360,
"content": "## Gmail\nConnects to Gmail and pulls email threads that have the \"Invoice Needed\" label. This is the trigger for creating a new invoice."
},
"typeVersion": 1
},
{
"id": "4d6af4d6-99a3-418b-9e05-7364ae71df30",
"name": "付箋3",
"type": "n8n-nodes-base.stickyNote",
"position": [
420,
-160
],
"parameters": {
"color": 7,
"height": 360,
"content": "## Combine All Messages\nGroups together all messages within a thread so AI can see the full conversation context — crucial for extracting accurate invoice details."
},
"typeVersion": 1
},
{
"id": "1adecc9c-446b-4f4d-a9dd-c333773ca0e3",
"name": "スレッド内全メッセージを結合",
"type": "n8n-nodes-base.code",
"position": [
480,
40
],
"parameters": {
"jsCode": "const threads = {};\n\nfor (const item of items) {\n const msg = item.json;\n const threadId = msg.threadId;\n\n if (!threads[threadId]) {\n threads[threadId] = [];\n }\n\n // Add To and From Addresses\n let finalMessage = \"From: \" + msg.headers.from;\n finalMessage += \"To: \" + msg.headers.to;\n finalMessage += \"Message: \" + msg.textAsHtml\n\n threads[threadId].push(finalMessage);\n}\n\nreturn Object.keys(threads).map(threadId => ({\n json: {\n threadId,\n chatInput: threads[threadId],\n }\n}));\n"
},
"typeVersion": 2
},
{
"id": "276e3175-c11a-4ae9-94ab-9703e20b89bf",
"name": "付箋4",
"type": "n8n-nodes-base.stickyNote",
"position": [
20,
300
],
"parameters": {
"color": 7,
"width": 440,
"height": 560,
"content": "## AI Agent: Extract Customer & Invoice Details\nUses OpenAI to read the email content and extract structured invoice data like name, company, amount, description, and contact info."
},
"typeVersion": 1
},
{
"id": "de08bb58-b868-4c70-80b9-b63c5f607856",
"name": "付箋5",
"type": "n8n-nodes-base.stickyNote",
"position": [
480,
300
],
"parameters": {
"color": 7,
"height": 380,
"content": "## Add Client to QBO\nTries to add a new customer to QuickBooks"
},
"typeVersion": 1
},
{
"id": "3344c904-9c17-4cf0-9d15-bbf1ce4d856d",
"name": "付箋6",
"type": "n8n-nodes-base.stickyNote",
"position": [
740,
300
],
"parameters": {
"color": 7,
"height": 380,
"content": "## Find Existing Customer\nSearches your QuickBooks account for a customer with the same display name"
},
"typeVersion": 1
},
{
"id": "88e1b763-ca25-4e0e-8881-d03d32003f14",
"name": "付箋7",
"type": "n8n-nodes-base.stickyNote",
"position": [
1000,
300
],
"parameters": {
"color": 7,
"height": 380,
"content": "## Create A New Invoice\nBuilds a draft invoice in QBO using the client info and line item details (amount + description) from the AI extraction. Please select a Product or Service to Sell\n"
},
"typeVersion": 1
},
{
"id": "cb087959-e777-4749-b734-d31ed64c09c1",
"name": "付箋8",
"type": "n8n-nodes-base.stickyNote",
"position": [
600,
760
],
"parameters": {
"color": 7,
"height": 360,
"content": "## Download Invoice\nPulls the PDF version of the invoice from QBO so it can be attached to your email reply."
},
"typeVersion": 1
},
{
"id": "b7a83ee4-678a-4477-9b54-a21dd6099412",
"name": "付箋9",
"type": "n8n-nodes-base.stickyNote",
"position": [
860,
760
],
"parameters": {
"color": 7,
"height": 360,
"content": "## Write Draft Reply to Client\nCreates a draft email reply to the original thread in Gmail with the invoice attached — ready for you to review and send."
},
"typeVersion": 1
},
{
"id": "4faa7895-c3dd-4607-9f55-35ee5e19728e",
"name": "付箋10",
"type": "n8n-nodes-base.stickyNote",
"position": [
1120,
760
],
"parameters": {
"color": 7,
"height": 360,
"content": "## Remove Invoice Needed Label\nRemoves the \"Invoice Needed\" label from the email thread to mark it as processed and avoid double-handling."
},
"typeVersion": 1
}
],
"pinData": {},
"connections": {
"1df01733-3f95-478f-bc2e-2eba2d3da4a9": {
"main": [
[
{
"node": "6ca60364-5d5b-45e0-9d73-63c34b20c47d",
"type": "main",
"index": 0
}
]
]
},
"f5c6f49d-5e21-48ae-bc4e-750cd4d5bd4a": {
"main": [
[
{
"node": "8d3af3f2-77ab-4788-8a92-2efc7be5ca42",
"type": "main",
"index": 0
}
]
]
},
"5f0e5680-7bb4-4c96-b427-233f0fd35d9a": {
"main": [
[
{
"node": "8e74cb95-64fa-4969-88ef-782631a1dbe9",
"type": "main",
"index": 0
}
]
]
},
"c76c499b-fd1b-440e-be22-3737a223c02c": {
"ai_languageModel": [
[
{
"node": "c01cc24c-99cd-4c16-80db-db71a6362859",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"4c7cb8d6-97d2-49a7-9307-9faeb04b2573": {
"main": [
[
{
"node": "1df01733-3f95-478f-bc2e-2eba2d3da4a9",
"type": "main",
"index": 0
}
]
]
},
"8e74cb95-64fa-4969-88ef-782631a1dbe9": {
"main": [
[
{
"node": "4c7cb8d6-97d2-49a7-9307-9faeb04b2573",
"type": "main",
"index": 0
}
]
]
},
"6ef8c67e-c5ba-4dc0-97e9-eebfc1a47db0": {
"ai_outputParser": [
[
{
"node": "c01cc24c-99cd-4c16-80db-db71a6362859",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"6ca60364-5d5b-45e0-9d73-63c34b20c47d": {
"main": [
[
{
"node": "60aeb85f-b6ef-4c47-bb88-d2431a95f7f2",
"type": "main",
"index": 0
}
]
]
},
"1adecc9c-446b-4f4d-a9dd-c333773ca0e3": {
"main": [
[
{
"node": "c01cc24c-99cd-4c16-80db-db71a6362859",
"type": "main",
"index": 0
}
]
]
},
"8d3af3f2-77ab-4788-8a92-2efc7be5ca42": {
"main": [
[
{
"node": "1adecc9c-446b-4f4d-a9dd-c333773ca0e3",
"type": "main",
"index": 0
}
]
]
},
"c01cc24c-99cd-4c16-80db-db71a6362859": {
"main": [
[
{
"node": "5f0e5680-7bb4-4c96-b427-233f0fd35d9a",
"type": "main",
"index": 0
}
]
]
}
}
}よくある質問
このワークフローの使い方は?
上記のJSON設定コードをコピーし、n8nインスタンスで新しいワークフローを作成して「JSONからインポート」を選択、設定を貼り付けて認証情報を必要に応じて変更してください。
このワークフローはどんな場面に適していますか?
上級 - 請求書処理, AI要約
有料ですか?
このワークフローは完全無料です。ただし、ワークフローで使用するサードパーティサービス(OpenAI APIなど)は別途料金が発生する場合があります。
関連ワークフロー
AI による Gmail 領収書の自動保存
AIによる Gメール領収書の自動保存機能:Google スプレッドシート・Google ドライブへ
Set
Gmail
Merge
+
Set
Gmail
Merge
14 ノードMatt Chong
請求書処理
請求書リマインダー:GmailからTasksへ
Gmail と Google Tasks を使用して請求書を自動のに検出し、リマインダーを作成します
If
Gmail
Google Tasks
+
If
Gmail
Google Tasks
13 ノードMatt Chong
請求書処理
Gmailへn8nによる送信タイムリミットの通知
AIベースのn8nリリースノート要約通知(Gmail経由でGPT-5-Miniを使用)
Set
Code
Html
+
Set
Code
Html
16 ノードJeff Huera
個人の生産性
23 顧客生涯価値(CLV)を分析する
Bright Data MCPを使ってGPT-4で高値顧客を分析し、特定する
If
Set
Code
+
If
Set
Code
20 ノードYaron Been
市場調査
分析ゾーンごとのパフォーマンス
Bright Data MCP と GPT-4o を使用して営業エリアのパフォーマンスを分析する
Set
Code
Gmail
+
Set
Code
Gmail
17 ノードYaron Been
顧客管理
16 競合企業価格を監視
Bright Data MCP と Google Sheets に基づく自動化された競合他社の価格設定モニタリング
Set
Code
Gmail
+
Set
Code
Gmail
18 ノードYaron Been
市場調査