{
  "name": "Automatically create invoices from Gmail labels with GPT-4O + QuickBooks",
  "nodes": [
    {
      "id": "5f0e5680-7bb4-4c96-b427-233f0fd35d9a",
      "name": "Add Client to QBO",
      "type": "n8n-nodes-base.quickbooks",
      "position": [
        540,
        500
      ]
    },
    {
      "id": "8d3af3f2-77ab-4788-8a92-2efc7be5ca42",
      "name": "Get Messages w/ Invoice Needed Label",
      "type": "n8n-nodes-base.gmail",
      "position": [
        220,
        20
      ]
    },
    {
      "id": "c76c499b-fd1b-440e-be22-3737a223c02c",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        60,
        720
      ]
    },
    {
      "id": "6ef8c67e-c5ba-4dc0-97e9-eebfc1a47db0",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        280,
        720
      ]
    },
    {
      "id": "8e74cb95-64fa-4969-88ef-782631a1dbe9",
      "name": "Find Existing Customer",
      "type": "n8n-nodes-base.quickbooks",
      "position": [
        800,
        500
      ]
    },
    {
      "id": "4c7cb8d6-97d2-49a7-9307-9faeb04b2573",
      "name": "Create A New Invoice",
      "type": "n8n-nodes-base.quickbooks",
      "position": [
        1060,
        520
      ]
    },
    {
      "id": "1df01733-3f95-478f-bc2e-2eba2d3da4a9",
      "name": "Download Invoice",
      "type": "n8n-nodes-base.quickbooks",
      "position": [
        640,
        940
      ]
    },
    {
      "id": "6ca60364-5d5b-45e0-9d73-63c34b20c47d",
      "name": "Write Draft Reply to Client",
      "type": "n8n-nodes-base.gmail",
      "position": [
        920,
        940
      ]
    },
    {
      "id": "f5c6f49d-5e21-48ae-bc4e-750cd4d5bd4a",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -40,
        20
      ]
    },
    {
      "id": "c01cc24c-99cd-4c16-80db-db71a6362859",
      "name": "AI Agent: Extract Customer & Invoice Details",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        60,
        500
      ]
    },
    {
      "id": "60aeb85f-b6ef-4c47-bb88-d2431a95f7f2",
      "name": "Remove Invoice Needed Label",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1180,
        940
      ]
    },
    {
      "id": "13d90021-d6b4-464c-bbf4-d2866e4452b8",
      "name": "Sticky Note",
      "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 us"
      }
    },
    {
      "id": "124c54fc-301d-48dc-8569-083ae9350cbf",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -100,
        -160
      ],
      "parameters": {
        "width": null,
        "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"
      }
    },
    {
      "id": "3657dde0-5110-4ea8-95bc-0301e9da5045",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        -160
      ],
      "parameters": {
        "width": null,
        "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."
      }
    },
    {
      "id": "4d6af4d6-99a3-418b-9e05-7364ae71df30",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        420,
        -160
      ],
      "parameters": {
        "width": null,
        "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."
      }
    },
    {
      "id": "1adecc9c-446b-4f4d-a9dd-c333773ca0e3",
      "name": "Combine all Messages in a Thread",
      "type": "n8n-nodes-base.code",
      "position": [
        480,
        40
      ]
    },
    {
      "id": "276e3175-c11a-4ae9-94ab-9703e20b89bf",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        20,
        300
      ],
      "parameters": {
        "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."
      }
    },
    {
      "id": "de08bb58-b868-4c70-80b9-b63c5f607856",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        480,
        300
      ],
      "parameters": {
        "width": null,
        "height": 380,
        "content": "## Add Client to QBO\nTries to add a new customer to QuickBooks"
      }
    },
    {
      "id": "3344c904-9c17-4cf0-9d15-bbf1ce4d856d",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        740,
        300
      ],
      "parameters": {
        "width": null,
        "height": 380,
        "content": "## Find Existing Customer\nSearches your QuickBooks account for a customer with the same display name"
      }
    },
    {
      "id": "88e1b763-ca25-4e0e-8881-d03d32003f14",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1000,
        300
      ],
      "parameters": {
        "width": null,
        "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"
      }
    },
    {
      "id": "cb087959-e777-4749-b734-d31ed64c09c1",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        600,
        760
      ],
      "parameters": {
        "width": null,
        "height": 360,
        "content": "## Download Invoice\nPulls the PDF version of the invoice from QBO so it can be attached to your email reply."
      }
    },
    {
      "id": "b7a83ee4-678a-4477-9b54-a21dd6099412",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        860,
        760
      ],
      "parameters": {
        "width": null,
        "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."
      }
    },
    {
      "id": "4faa7895-c3dd-4607-9f55-35ee5e19728e",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1120,
        760
      ],
      "parameters": {
        "width": null,
        "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."
      }
    }
  ],
  "connections": {
    "Download Invoice": {
      "main": [
        [
          {
            "node": "Write Draft Reply to Client",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get Messages w/ Invoice Needed Label",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Client to QBO": {
      "main": [
        [
          {
            "node": "Find Existing Customer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent: Extract Customer & Invoice Details",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Create A New Invoice": {
      "main": [
        [
          {
            "node": "Download Invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find Existing Customer": {
      "main": [
        [
          {
            "node": "Create A New Invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent: Extract Customer & Invoice Details",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Write Draft Reply to Client": {
      "main": [
        [
          {
            "node": "Remove Invoice Needed Label",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Combine all Messages in a Thread": {
      "main": [
        [
          {
            "node": "AI Agent: Extract Customer & Invoice Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Messages w/ Invoice Needed Label": {
      "main": [
        [
          {
            "node": "Combine all Messages in a Thread",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent: Extract Customer & Invoice Details": {
      "main": [
        [
          {
            "node": "Add Client to QBO",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}