{
  "id": "P0XlrZL5Px9uJq2c",
  "name": "Autonomous Revenue Tax Agent Filing System",
  "tags": [],
  "nodes": [
    {
      "id": "4e9d2153-fff7-47ed-a147-c9fb0f6ba976",
      "name": "Daily Revenue Collection Schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        48,
        592
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 2
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "008f91ff-ef26-4662-ab0a-4a02d20855dc",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        272,
        592
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "startDate",
              "type": "string",
              "value": "={{ $now.minus({ days: 1 }).startOf(\"day\").toISO() }}"
            },
            {
              "id": "id-2",
              "name": "endDate",
              "type": "string",
              "value": "={{ $now.minus({ days: 1 }).endOf(\"day\").toISO() }}"
            },
            {
              "id": "id-3",
              "name": "taxApiUrl",
              "type": "string",
              "value": "<__PLACEHOLDER_VALUE__Tax API endpoint URL__>"
            },
            {
              "id": "id-4",
              "name": "taxApiEnabled",
              "type": "string",
              "value": "<__PLACEHOLDER_VALUE__true or false for API availability__>"
            },
            {
              "id": "id-5",
              "name": "taxAgentEmail",
              "type": "string",
              "value": "<__PLACEHOLDER_VALUE__Tax agent email address__>"
            },
            {
              "id": "id-6",
              "name": "archiveFolderId",
              "type": "string",
              "value": "<__PLACEHOLDER_VALUE__Google Drive folder ID for archives__>"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "11e3761c-0758-4a29-a920-69f6517dc3aa",
      "name": "Get Stripe Transactions",
      "type": "n8n-nodes-base.stripe",
      "position": [
        496,
        384
      ],
      "parameters": {
        "limit": 100,
        "resource": "charge",
        "operation": "getAll"
      },
      "typeVersion": 1
    },
    {
      "id": "083910ec-522c-4a5c-873e-07479578d9f6",
      "name": "Get PayPal Transactions",
      "type": "n8n-nodes-base.payPal",
      "position": [
        496,
        560
      ],
      "parameters": {
        "operation": "get",
        "payoutBatchId": "={{ $('Workflow Configuration').first().json.payoutBatchId }}"
      },
      "typeVersion": 1
    },
    {
      "id": "87a214ac-4981-4780-a311-6a0cc6d55e39",
      "name": "Get Shopify Orders",
      "type": "n8n-nodes-base.shopify",
      "position": [
        496,
        720
      ],
      "parameters": {
        "limit": 100,
        "options": {
          "createdAtMax": "={{ $('Workflow Configuration').first().json.endDate }}",
          "createdAtMin": "={{ $('Workflow Configuration').first().json.startDate }}"
        },
        "operation": "getAll"
      },
      "typeVersion": 1
    },
    {
      "id": "f100403c-1244-4777-a37a-05c6c406b232",
      "name": "Get Bank Feed Data",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        496,
        880
      ],
      "parameters": {
        "url": "<__PLACEHOLDER_VALUE__Bank feed API endpoint__>",
        "options": {},
        "sendQuery": true,
        "authentication": "predefinedCredentialType",
        "queryParameters": {
          "parameters": [
            {
              "name": "start_date",
              "value": "={{ $('Workflow Configuration').first().json.startDate }}"
            },
            {
              "name": "end_date",
              "value": "={{ $('Workflow Configuration').first().json.endDate }}"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "6b94add5-1a55-439e-9cb2-bc0a20bfae83",
      "name": "Merge All Revenue Sources",
      "type": "n8n-nodes-base.merge",
      "position": [
        768,
        560
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition",
        "numberInputs": 4
      },
      "typeVersion": 3.2
    },
    {
      "id": "27426f0f-9d22-4f97-9e76-a863243d3bcf",
      "name": "Normalize Revenue Data",
      "type": "n8n-nodes-base.set",
      "position": [
        944,
        592
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "transactionId",
              "type": "string",
              "value": "={{ $json.id || $json.transaction_id || $json.order_id }}"
            },
            {
              "id": "id-2",
              "name": "amount",
              "type": "number",
              "value": "={{ $json.amount || $json.total || $json.value }}"
            },
            {
              "id": "id-3",
              "name": "currency",
              "type": "string",
              "value": "={{ $json.currency || \"USD\" }}"
            },
            {
              "id": "id-4",
              "name": "date",
              "type": "string",
              "value": "={{ $json.created || $json.created_at || $json.date }}"
            },
            {
              "id": "id-5",
              "name": "description",
              "type": "string",
              "value": "={{ $json.description || $json.memo || $json.name || \"\" }}"
            },
            {
              "id": "id-6",
              "name": "source",
              "type": "string",
              "value": "={{ $json.source || $runIndex === 0 ? \"Stripe\" : $runIndex === 1 ? \"PayPal\" : $runIndex === 2 ? \"Shopify\" : \"Bank\" }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "bbaa1802-2a41-4f43-9213-dc1843dcdfab",
      "name": "AI Income Categorizer",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1168,
        592
      ],
      "parameters": {
        "text": "=Transaction: {{ $json.description }}, Amount: {{ $json.amount }} {{ $json.currency }}, Source: {{ $json.source }}",
        "options": {
          "systemMessage": "You are a tax categorization specialist. Analyze each transaction and categorize it into the appropriate tax category.\n\nCategories:\n- product_sales: Revenue from selling physical or digital products\n- service_revenue: Revenue from providing services\n- interest_income: Interest earned from bank accounts or investments\n- rental_income: Income from property rentals\n- other_income: Any other type of income\n\nFor each transaction, determine:\n1. The primary tax category\n2. A specific subcategory\n3. Whether it is taxable\n4. Your confidence level (0-1)\n\nBe precise and consistent in your categorization."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3.1
    },
    {
      "id": "746c406b-ecf3-49c3-8d70-ac6d8db5e74a",
      "name": "OpenAI GPT-4",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1184,
        816
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "gpt-4o"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "a1fb3c02-0072-412d-b293-c9df532a8d28",
      "name": "Structured Category Output",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1312,
        816
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"category\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"Tax category: product_sales, service_revenue, interest_income, rental_income, other_income\"\n\t\t},\n\t\t\"subcategory\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"Specific subcategory within the main category\"\n\t\t},\n\t\t\"taxable\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"description\": \"Whether this income is taxable\"\n\t\t},\n\t\t\"confidence\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"description\": \"Confidence score from 0 to 1\"\n\t\t}\n\t}\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "1abd80b4-d2b0-49cb-8da9-53339039a742",
      "name": "Calculate Category Totals",
      "type": "n8n-nodes-base.summarize",
      "position": [
        1440,
        592
      ],
      "parameters": {
        "options": {},
        "fieldsToSplitBy": "category",
        "fieldsToSummarize": {
          "values": [
            {
              "field": "amount",
              "aggregation": "sum"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "cacbdc51-1467-4e29-9f4b-8c08dc1e0808",
      "name": "Format Tax Submission Data",
      "type": "n8n-nodes-base.code",
      "position": [
        1664,
        592
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\nconst timestamp = new Date().toISOString();\nconst startDate = $('Workflow Configuration').first().json.startDate;\nconst endDate = $('Workflow Configuration').first().json.endDate;\n\n// Create CSV format\nconst csvHeaders = 'Category,Total Amount,Currency,Period Start,Period End';\nconst csvRows = items.map(item => \n  `${item.json.category},${item.json.amount},USD,${startDate},${endDate}`\n);\nconst csvData = [csvHeaders, ...csvRows].join('\\n');\n\n// Create XML format\nconst xmlData = `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<TaxSubmission>\n  <Period>\n    <StartDate>${startDate}</StartDate>\n    <EndDate>${endDate}</EndDate>\n  </Period>\n  <Revenue>\n${items.map(item => `    <Category>\n      <Name>${item.json.category}</Name>\n      <Amount>${item.json.amount}</Amount>\n      <Currency>USD</Currency>\n    </Category>`).join('\\n')}\n  </Revenue>\n  <Timestamp>${timestamp}</Timestamp>\n</TaxSubmission>`;\n\n// Create JSON payload\nconst jsonPayload = {\n  period: {\n    startDate: startDate,\n    endDate: endDate\n  },\n  revenue: items.map(item => ({\n    category: item.json.category,\n    amount: item.json.amount,\n    currency: 'USD'\n  })),\n  timestamp: timestamp\n};\n\nreturn [{\n  json: {\n    csv: csvData,\n    xml: xmlData,\n    jsonPayload: jsonPayload,\n    timestamp: timestamp,\n    totalRevenue: items.reduce((sum, item) => sum + item.json.amount, 0)\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "a069b307-fced-47a5-9bfd-efe5bc2720a5",
      "name": "Check API Availability",
      "type": "n8n-nodes-base.if",
      "position": [
        1888,
        592
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "id-1",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $('Workflow Configuration').first().json.taxApiEnabled }}",
              "rightValue": "true"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "5b6a6125-6112-4823-941c-cd4ee3924b62",
      "name": "Submit to Tax API",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2112,
        496
      ],
      "parameters": {
        "url": "={{ $('Workflow Configuration').first().json.taxApiUrl }}",
        "method": "POST",
        "options": {},
        "jsonBody": "={{ $json.jsonPayload }}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "4d2c8770-ebf6-49f1-91bf-41d1f62d627f",
      "name": "Email to Tax Agent",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2112,
        688
      ],
      "parameters": {
        "sendTo": "={{ $('Workflow Configuration').first().json.taxAgentEmail }}",
        "message": "=<h2>Tax Filing Submission</h2>\n<p>Please find attached the revenue data for the period:</p>\n<ul>\n<li><strong>Period:</strong> {{ $('Workflow Configuration').first().json.startDate }} to {{ $('Workflow Configuration').first().json.endDate }}</li>\n<li><strong>Total Revenue:</strong> ${{ $json.totalRevenue }}</li>\n<li><strong>Timestamp:</strong> {{ $json.timestamp }}</li>\n</ul>\n<p>The submission data is attached in CSV, XML, and JSON formats.</p>",
        "options": {
          "attachmentsUi": {
            "attachmentsBinary": [
              {
                "property": "csv"
              },
              {
                "property": "xml"
              },
              {
                "property": "json"
              }
            ]
          }
        },
        "subject": "=Tax Filing Submission - {{ $json.timestamp }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "36bc14d9-acbe-4377-8b29-9ecef822f24e",
      "name": "Archive to Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        2528,
        640
      ],
      "parameters": {
        "name": "={{ 'tax_archive_' + $('Format Tax Submission Data').first().json.timestamp + '.json' }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Workflow Configuration').first().json.archiveFolderId }}"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "5e6d5e80-57cf-463a-926a-bf42500dabfc",
      "name": "Merge Submission Paths",
      "type": "n8n-nodes-base.merge",
      "position": [
        2336,
        592
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "6046612d-e4f2-485b-b2b4-73442ea8c942",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1248,
        -96
      ],
      "parameters": {
        "color": 3,
        "width": 576,
        "height": 336,
        "content": "## Prerequisites\nStripe, PayPal, Shopify, or bank feed accounts; OpenAI API key; Gmail account .\n\n## Use Cases\nAccounting firms automating quarterly tax prep for multiple clients\n\n## Customization\nModify revenue sources, adjust GPT-4 prompts for specific tax  \n\n## Benefits\nEliminates manual tax calculations, reduces forecasting errors"
      },
      "typeVersion": 1
    },
    {
      "id": "ca7c7a9d-3106-455a-906f-dbf332569c82",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        736,
        -80
      ],
      "parameters": {
        "width": 496,
        "content": "## Setup Steps\n1. Connect Stripe, PayPal, Shopify credentials via n8n authentication.\n2. Configure OpenAI GPT-4 API key for structured tax analysis.\n3. Connect Gmail account for report distribution and Google Sheets.\n4. Set monthly trigger schedule and customize tax category rules."
      },
      "typeVersion": 1
    },
    {
      "id": "b09554e1-c0c4-4e1d-ad18-f97976440686",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -16,
        -80
      ],
      "parameters": {
        "width": 720,
        "height": 256,
        "content": "## How It Works\nThis workflow automates monthly revenue aggregation from multiple financial sources, including Stripe, PayPal, Shopify, and bank feeds, while delivering intelligent tax forecasting through GPT-4\u2013based structured analysis. It systematically retrieves revenue data, consolidates disparate datasets into a unified view, and applies GPT-4 to predict upcoming tax obligations with greater accuracy. The system then generates clearly formatted, audit-ready reports and automatically distributes tax projections to designated agents via Gmail, while securely storing all outputs in Google Sheets to maintain traceable audit trails. Designed for tax professionals, accounting firms, and finance teams, it enables accurate predictive tax planning and supports a proactive compliance strategy without the need for manual calculations or spreadsheet-driven analysis."
      },
      "typeVersion": 1
    },
    {
      "id": "566dc00b-c09a-45ae-a488-919d389fe9d4",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1824,
        272
      ],
      "parameters": {
        "color": 7,
        "width": 864,
        "height": 640,
        "content": "## Generate & Distribute\nWhat: Creates formatted reports, sends via Gmail to agents.\nWhy: Ensures real-time access, compliance documentation, and audit readiness."
      },
      "typeVersion": 1
    },
    {
      "id": "57f8bc54-5382-4338-98dc-bac5d14792ae",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1136,
        272
      ],
      "parameters": {
        "color": 7,
        "width": 672,
        "height": 768,
        "content": "## AI Tax Analysis\nWhat: Applies OpenAI GPT-4 structured analysis to categorize income and forecast tax obligations.\nWhy: Delivers intelligent, context-aware tax projections beyond basic calculations."
      },
      "typeVersion": 1
    },
    {
      "id": "a2bc1401-8b00-4033-8257-ed08a37bbe4a",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        720,
        272
      ],
      "parameters": {
        "color": 7,
        "width": 384,
        "height": 784,
        "content": "## Normalize & Merge\nWhat: Consolidates multi-source data into unified records.\nWhy: Enables accurate analysis by eliminating  inconsistencies."
      },
      "typeVersion": 1
    },
    {
      "id": "f81cbfd7-20df-4056-9508-f5907cf45945",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        16,
        272
      ],
      "parameters": {
        "color": 7,
        "width": 672,
        "height": 784,
        "content": "## Fetch Revenue Data\nWhat: Collects transactions from Stripe, PayPal, Shopify, and bank feeds simultaneously.\nWhy: Provides comprehensive revenue visibility across all income.\n "
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "2d461e8b-3b75-4748-bfec-1f68654ed1b1",
  "connections": {
    "OpenAI GPT-4": {
      "ai_languageModel": [
        [
          {
            "node": "AI Income Categorizer",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Submit to Tax API": {
      "main": [
        [
          {
            "node": "Merge Submission Paths",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email to Tax Agent": {
      "main": [
        [
          {
            "node": "Merge Submission Paths",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Get Bank Feed Data": {
      "main": [
        [
          {
            "node": "Merge All Revenue Sources",
            "type": "main",
            "index": 3
          }
        ]
      ]
    },
    "Get Shopify Orders": {
      "main": [
        [
          {
            "node": "Merge All Revenue Sources",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "AI Income Categorizer": {
      "main": [
        [
          {
            "node": "Calculate Category Totals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check API Availability": {
      "main": [
        [
          {
            "node": "Submit to Tax API",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Email to Tax Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Submission Paths": {
      "main": [
        [
          {
            "node": "Archive to Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Revenue Data": {
      "main": [
        [
          {
            "node": "AI Income Categorizer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Configuration": {
      "main": [
        [
          {
            "node": "Get Stripe Transactions",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get PayPal Transactions",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get Shopify Orders",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get Bank Feed Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get PayPal Transactions": {
      "main": [
        [
          {
            "node": "Merge All Revenue Sources",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Get Stripe Transactions": {
      "main": [
        [
          {
            "node": "Merge All Revenue Sources",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Category Totals": {
      "main": [
        [
          {
            "node": "Format Tax Submission Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge All Revenue Sources": {
      "main": [
        [
          {
            "node": "Normalize Revenue Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Tax Submission Data": {
      "main": [
        [
          {
            "node": "Check API Availability",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Category Output": {
      "ai_outputParser": [
        [
          {
            "node": "AI Income Categorizer",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Daily Revenue Collection Schedule": {
      "main": [
        [
          {
            "node": "Workflow Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}