8
n8n 中文网amn8n.com

个人支出追踪器

中级

这是一个Personal Productivity领域的自动化工作流,包含 15 个节点。主要使用 Cron, Webhook, Function, GoogleSheets, RespondToWebhook 等节点。 使用Webhooks和Google Sheets自动化追踪器管理个人支出

前置要求
  • HTTP Webhook 端点(n8n 会自动生成)
  • Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "E1CD2pH99IVoXnwp",
  "meta": {
    "instanceId": "922f87b0adfedb3ae09541ddf50e19d9af2c8cfac1d8da5d9cd4cdfe64d30bee",
    "templateCredsSetupCompleted": true
  },
  "name": "个人支出追踪器",
  "tags": [],
  "nodes": [
    {
      "id": "0dc9105c-6579-4bde-b831-b993ac6e1a54",
      "name": "支出输入 Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        240,
        100
      ],
      "webhookId": "expense-tracker-api",
      "parameters": {
        "path": "add-expense",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 1
    },
    {
      "id": "17662aeb-97d6-468e-b1d1-2b82a44dfbb9",
      "name": "验证并格式化支出数据",
      "type": "n8n-nodes-base.function",
      "position": [
        540,
        100
      ],
      "parameters": {
        "functionCode": "// Validate and format expense data\nconst body = $input.first().json.body || {};\n\nconst expense = {\n  date: body.date || new Date().toISOString().split('T')[0],\n  category: body.category || 'Other',\n  description: body.description || 'No description',\n  amount: parseFloat(body.amount) || 0,\n  payment_method: body.payment_method || 'Cash'\n};\n\n// Validate amount\nif (expense.amount <= 0) {\n  throw new Error('Amount must be greater than 0');\n}\n\n// Validate category\nconst validCategories = ['Food', 'Transport', 'Shopping', 'Bills', 'Entertainment', 'Health', 'Other'];\nif (!validCategories.includes(expense.category)) {\n  expense.category = 'Other';\n}\n\n// Format amount to 2 decimal places\nexpense.amount = Math.round(expense.amount * 100) / 100;\n\nreturn { json: expense };"
      },
      "typeVersion": 1
    },
    {
      "id": "0a4044a1-f23e-4c5a-9383-425f0fb5cf9e",
      "name": "保存支出到 Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        840,
        100
      ],
      "parameters": {
        "options": {
          "cellFormat": "USER_ENTERED"
        },
        "operation": "append",
        "sheetName": "Expenses",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "REPLACE_WITH_YOUR_SPREADSHEET_ID"
        }
      },
      "typeVersion": 4
    },
    {
      "id": "84af3396-544e-41fe-a8ae-5f27f912bf77",
      "name": "计算月度汇总",
      "type": "n8n-nodes-base.function",
      "position": [
        1140,
        100
      ],
      "parameters": {
        "functionCode": "// Calculate summary for current expense\nconst currentExpense = $('Validate and Format Expense Data').first().json;\nconst currentDate = new Date(currentExpense.date);\nconst currentMonth = currentDate.getMonth() + 1;\nconst currentYear = currentDate.getFullYear();\n\n// Create response with expense details and summary\nconst summary = {\n  expense_added: currentExpense,\n  monthly_summary: {\n    month: currentMonth,\n    year: currentYear,\n    category: currentExpense.category,\n    amount_added: currentExpense.amount,\n    date_updated: new Date().toISOString()\n  },\n  success: true,\n  message: `Expense of $${currentExpense.amount} for ${currentExpense.category} has been recorded successfully.`\n};\n\nreturn { json: summary };"
      },
      "typeVersion": 1
    },
    {
      "id": "71a8e380-dc27-4cdb-a4e7-388347a38939",
      "name": "发送成功响应",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1440,
        100
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "638d6c11-fcdc-4aa7-a785-6a23dad63e06",
      "name": "发送错误响应",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        540,
        260
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "026567d0-aef6-49a8-9100-22cbac0bccae",
      "name": "每日汇总计划",
      "type": "n8n-nodes-base.cron",
      "position": [
        240,
        400
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "483b47d5-4b82-4e5b-9d79-fb1c2337d90a",
      "name": "从表格读取今日支出",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        540,
        400
      ],
      "parameters": {
        "options": {},
        "sheetName": "Expenses",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "REPLACE_WITH_YOUR_SPREADSHEET_ID"
        }
      },
      "typeVersion": 4
    },
    {
      "id": "f166a60d-06f0-4852-88e2-c4a05fbf39c9",
      "name": "计算每日总额",
      "type": "n8n-nodes-base.function",
      "position": [
        840,
        400
      ],
      "parameters": {
        "functionCode": "// Filter and calculate today's expenses\nconst today = new Date().toISOString().split('T')[0];\nconst allExpenses = $input.all()[0].json || [];\n\n// Filter expenses for today\nconst todayExpenses = allExpenses.filter(expense => {\n  return expense.date === today;\n});\n\n// Calculate total and by category\nconst categoryTotals = {};\nlet totalToday = 0;\n\ntodayExpenses.forEach(expense => {\n  const amount = parseFloat(expense.amount || 0);\n  totalToday += amount;\n  \n  if (!categoryTotals[expense.category]) {\n    categoryTotals[expense.category] = 0;\n  }\n  categoryTotals[expense.category] += amount;\n});\n\nreturn {\n  json: {\n    date: today,\n    total_expenses: Math.round(totalToday * 100) / 100,\n    expense_count: todayExpenses.length,\n    category_breakdown: categoryTotals,\n    expenses: todayExpenses\n  }\n};"
      },
      "typeVersion": 1
    },
    {
      "id": "b395295d-2f98-41cf-9ea3-37aa8ba09e83",
      "name": "主工作流说明",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -320,
        -100
      ],
      "parameters": {
        "color": 4,
        "width": 450,
        "height": 1180,
        "content": "# 💰 个人支出追踪器 API"
      },
      "typeVersion": 1
    },
    {
      "id": "49605945-3d4d-497c-83f9-2518ebc4e1e9",
      "name": "步骤 1 - API 输入",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        200,
        -220
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 280,
        "content": "## 步骤 1:API 输入"
      },
      "typeVersion": 1
    },
    {
      "id": "c02af8e8-6b84-4226-81cb-558bda710a91",
      "name": "步骤 2 - 数据验证",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        500,
        -200
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 260,
        "content": "## 步骤 2:数据验证"
      },
      "typeVersion": 1
    },
    {
      "id": "0ab3f049-da8f-48f0-9715-3fd5382310b8",
      "name": "步骤 3 - Google Sheets 存储",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        -220
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 280,
        "content": "## 步骤 3:Google Sheets 存储"
      },
      "typeVersion": 1
    },
    {
      "id": "f68eeb78-bf5c-43e6-8ac2-20745b3aa54f",
      "name": "步骤 4 - API 响应",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1140,
        -200
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 260,
        "content": "## 步骤 4:API 响应"
      },
      "typeVersion": 1
    },
    {
      "id": "d1a9d5fa-b4d8-492f-b3ed-9d8789194da3",
      "name": "每日汇总自动化",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1120,
        280
      ],
      "parameters": {
        "color": 6,
        "width": 500,
        "height": 250,
        "content": "## 📊 自动化每日汇总"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "aedb5fd0-8999-486c-af50-b440d70e1926",
  "connections": {
    "Expense Input Webhook": {
      "main": [
        [
          {
            "node": "Validate and Format Expense Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily Summary Schedule": {
      "main": [
        [
          {
            "node": "Read Today's Expenses from Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Monthly Summary": {
      "main": [
        [
          {
            "node": "Send Success Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Expense to Google Sheets": {
      "main": [
        [
          {
            "node": "Calculate Monthly Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Today's Expenses from Sheet": {
      "main": [
        [
          {
            "node": "Calculate Daily Total",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate and Format Expense Data": {
      "main": [
        [
          {
            "node": "Save Expense to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 个人效率

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量15
分类1
节点类型6
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

外部链接
在 n8n.io 查看

分享此工作流