{
  "id": "FQXQ6mbUbJJNK7OM",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "n8n invoice automation",
  "tags": [],
  "nodes": [
    {
      "id": "d4c53413-6435-4ec3-a671-63417350c0e0",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1472,
        672
      ],
      "parameters": {
        "width": 704,
        "height": 896,
        "content": "## n8n invoice automation\n\n### How it works\n\nThis workflow watches Gmail for incoming invoice emails, sends attached PDFs to Parseur for extraction, and retrieves the parsed invoice data. It checks Zoho Books to avoid duplicate bills, creates a new bill when needed, then downloads the original invoice PDF. Finally, it ensures a month folder exists in Google Drive and uploads the invoice PDF into the correct folder.\n\n### Setup steps\n\n- Connect Gmail credentials and configure the trigger search/filter so it only watches invoice emails with PDF attachments.\n- Configure Parseur credentials, mailbox/template, and API access so uploaded PDFs can be parsed and fetched successfully.\n- Set up Zoho Books API/OAuth credentials, including the correct organization ID and bill field mappings.\n- Connect Google Drive credentials and configure the parent Drive location where monthly invoice folders should be searched or created.\n- Verify HTTP request URLs, authentication headers, and expressions that reference Parseur document IDs, parsed JSON fields, bill IDs, and PDF download links.\n\n### Customization\n\nAdjust the duplicate-bill matching logic, the 25-second Parseur wait time, Zoho bill payload fields, monthly folder naming convention, and Gmail filters to fit the invoice formats and accounting process."
      },
      "typeVersion": 1
    },
    {
      "id": "b9aec606-a988-4303-bc8f-22c21a18abc1",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2256,
        880
      ],
      "parameters": {
        "color": 7,
        "width": 432,
        "height": 352,
        "content": "## Capture invoice emails\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "690818bc-f630-46f8-ab8f-447902eaf9ee",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2720,
        848
      ],
      "parameters": {
        "color": 7,
        "width": 688,
        "height": 352,
        "content": "## Retrieve parsed invoice\n\nWaits for Parseur to finish processing, fetches the Parseur document record, and retrieves the extracted invoice data as JSON."
      },
      "typeVersion": 1
    },
    {
      "id": "1229986c-4e20-40bf-a587-a414786a944e",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3440,
        768
      ],
      "parameters": {
        "color": 7,
        "width": 704,
        "height": 592,
        "content": "## Check bill status\n\nLooks up existing Zoho Books bills using the parsed invoice data, branches based on whether the bill is new, and stops processing duplicate bills."
      },
      "typeVersion": 1
    },
    {
      "id": "328bbeee-2eeb-459a-9efa-f904b413a5d4",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4176,
        656
      ],
      "parameters": {
        "color": 7,
        "width": 944,
        "height": 704,
        "content": "## Create bill and PDF\n\nCreates the bill in Zoho Books for new invoices, then downloads the original invoice PDF for archiving."
      },
      "typeVersion": 1
    },
    {
      "id": "912aeac7-9118-4d57-b4cb-4fbb362689a0",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5152,
        656
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 528,
        "content": "## Prepare folder result\n\nCreates the month folder when it is missing and merges the created-or-existing folder result into a single path for the upload step."
      },
      "typeVersion": 1
    },
    {
      "id": "ee8a44ce-33d5-4e34-8683-54fa22453834",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5600,
        640
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 544,
        "content": "## Upload invoice archive\n\nCombines the downloaded PDF with the resolved Drive folder data and uploads the invoice PDF to Google Drive."
      },
      "typeVersion": 1
    },
    {
      "id": "d4db6fa1-0959-4cb9-a32a-4c76f48bee68",
      "name": "When Invoice Email Received",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        2304,
        1008
      ],
      "parameters": {
        "simple": false,
        "filters": {
          "q": "has:attachment"
        },
        "options": {
          "downloadAttachments": true
        },
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "typeVersion": 1.4
    },
    {
      "id": "16814581-4fc7-408d-a4cf-523ebb1a105f",
      "name": "Upload PDF to Parseur App",
      "type": "n8n-nodes-parseur.parseur",
      "position": [
        2544,
        1008
      ],
      "parameters": {
        "parserId": 201709,
        "binaryPropertyName": "attachment_0"
      },
      "credentials": {},
      "typeVersion": 1
    },
    {
      "id": "afe41784-d811-4ad3-b3aa-c44a7424c46a",
      "name": "Wait 25 Seconds for Parsing",
      "type": "n8n-nodes-base.wait",
      "position": [
        2768,
        1024
      ],
      "parameters": {
        "amount": 25
      },
      "typeVersion": 1.1
    },
    {
      "id": "b835fea2-0f5a-457c-865e-cf0a3ab91743",
      "name": "Fetch Document from Parseur",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3024,
        1024
      ],
      "parameters": {
        "url": "=https://api.parseur.com/document/{{ $('Upload PDF to Parseur App').first().json.response.attachments[0].DocumentID }}",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.4
    },
    {
      "id": "8ec74496-7c55-4d79-b375-7c27466032d1",
      "name": "Retrieve Invoice Data JSON",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3264,
        1024
      ],
      "parameters": {
        "url": "={{ $('Fetch Document from Parseur').item.json.json_download_url }}",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.4
    },
    {
      "id": "9f1e2d11-96b3-416c-8d30-e6a8c9991ed0",
      "name": "Fetch Zoho Bill List",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3488,
        1024
      ],
      "parameters": {
        "url": "https://www.zohoapis.com/books/v3/bills",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "oAuth2Api",
        "queryParameters": {
          "parameters": [
            {
              "name": "organization_id",
              "value": "931704443"
            },
            {
              "name": "vendor_id",
              "value": "637567+1234567890"
            },
            {
              "name": "bill_number",
              "value": "={{ $json.invoice_number }}"
            }
          ]
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "eda2ff96-3258-4b34-a1ea-176499999146",
      "name": "Check if Bill is New",
      "type": "n8n-nodes-base.if",
      "position": [
        3728,
        1024
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "e54d200f-36eb-4a84-a16b-9c916a708efb",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.bills.length }}",
              "rightValue": "0"
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.3
    },
    {
      "id": "c16d2df4-33e9-4497-a5ec-1039a462fc13",
      "name": "Skip Duplicate Bill",
      "type": "n8n-nodes-base.noOp",
      "position": [
        3952,
        1184
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "7876dde0-97ea-4ccc-978c-749ec9984a9a",
      "name": "Create New Bill in Zoho",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        4240,
        864
      ],
      "parameters": {
        "url": "https://www.zohoapis.com/books/v3/bills?organization_id=931704443",
        "method": "POST",
        "options": {},
        "jsonBody": "={{\nJSON.stringify({\n  vendor_id: \"637567000000093117\",\n  bill_number: $('Retrieve Invoice Data JSON').first().json.invoice_number,\n  date: new Date($('Retrieve Invoice Data JSON').first().json.invoice_date).toISOString().split('T')[0],\n  due_date: new Date($('Retrieve Invoice Data JSON').first().json.due_date).toISOString().split('T')[0],\n  line_items: $('Retrieve Invoice Data JSON').first().json.line_items.map(item => ({\n    name: item.description,\n    rate: parseFloat(item.unit_price.replace('$','')),\n    quantity: parseFloat(item.qty),\n    account_id: \"637567000000000400\"\n  }))\n})\n}}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "oAuth2Api"
      },
      "typeVersion": 4.4
    },
    {
      "id": "bef1539c-3c44-4ef8-b50c-6ff79b46b21a",
      "name": "Download Original Invoice PDF",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        4544,
        1024
      ],
      "parameters": {
        "url": "={{ $('Fetch Document from Parseur').item.json.original_document_url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "9ec338d1-a7b8-416e-80a2-449b7effc511",
      "name": "Locate Monthly Folder in Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        4768,
        832
      ],
      "parameters": {
        "filter": {
          "whatToSearch": "folders"
        },
        "options": {},
        "resource": "fileFolder",
        "queryString": "=={{ new Date($('Retrieve Invoice Data JSON').item.json.invoice_date).toISOString().slice(0,7) }}"
      },
      "typeVersion": 3,
      "alwaysOutputData": true
    },
    {
      "id": "ee33ec00-70a4-4f06-bc83-11605cc5318f",
      "name": "Check Month Folder Existence",
      "type": "n8n-nodes-base.if",
      "position": [
        4976,
        832
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "5664220e-3048-44f8-8c6d-82aa4ab6cc71",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ Object.keys($json).length }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "826a539f-0ab7-4acf-b3b4-ee91c850b7a3",
      "name": "Create New Month Folder",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        5200,
        912
      ],
      "parameters": {
        "name": "={{ new Date($('Retrieve Invoice Data JSON').item.json.invoice_date).toISOString().slice(0,7) }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "root",
          "cachedResultName": "/ (Root folder)"
        },
        "resource": "folder"
      },
      "typeVersion": 3
    },
    {
      "id": "efb51732-7053-4994-91a3-6c64f17fa0d1",
      "name": "Merge Folder Results",
      "type": "n8n-nodes-base.merge",
      "position": [
        5424,
        832
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "7ac4851c-c8ca-4d04-b752-ddc89122d0d8",
      "name": "Merge PDF with Folder Data",
      "type": "n8n-nodes-base.merge",
      "position": [
        5648,
        1008
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3.2
    },
    {
      "id": "801260e7-0200-4a8f-8460-44c54017a199",
      "name": "Upload Invoice PDF to Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        5872,
        896
      ],
      "parameters": {
        "name": "={{ $('Retrieve Invoice Data JSON').item.json.invoice_number }}.pdf",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        }
      },
      "typeVersion": 3
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "b259812e-b086-4b23-93c5-1ed913ccb57f",
  "nodeGroups": [],
  "connections": {
    "Check if Bill is New": {
      "main": [
        [
          {
            "node": "Create New Bill in Zoho",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Skip Duplicate Bill",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Zoho Bill List": {
      "main": [
        [
          {
            "node": "Check if Bill is New",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Folder Results": {
      "main": [
        [
          {
            "node": "Merge PDF with Folder Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create New Bill in Zoho": {
      "main": [
        [
          {
            "node": "Download Original Invoice PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create New Month Folder": {
      "main": [
        [
          {
            "node": "Merge Folder Results",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Upload PDF to Parseur App": {
      "main": [
        [
          {
            "node": "Wait 25 Seconds for Parsing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge PDF with Folder Data": {
      "main": [
        [
          {
            "node": "Upload Invoice PDF to Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retrieve Invoice Data JSON": {
      "main": [
        [
          {
            "node": "Fetch Zoho Bill List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Document from Parseur": {
      "main": [
        [
          {
            "node": "Retrieve Invoice Data JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 25 Seconds for Parsing": {
      "main": [
        [
          {
            "node": "Fetch Document from Parseur",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Invoice Email Received": {
      "main": [
        [
          {
            "node": "Upload PDF to Parseur App",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Month Folder Existence": {
      "main": [
        [
          {
            "node": "Merge Folder Results",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create New Month Folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Original Invoice PDF": {
      "main": [
        [
          {
            "node": "Locate Monthly Folder in Drive",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge PDF with Folder Data",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Locate Monthly Folder in Drive": {
      "main": [
        [
          {
            "node": "Check Month Folder Existence",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}