8
n8n 中文网amn8n.com

在两个应用之间同步新数据

中级

这是一个Sales, Engineering领域的自动化工作流,包含 9 个节点。主要使用 Code, Filter, GoogleSheets, ManualTrigger, PostgresTrigger 等节点。 在两个应用之间同步新数据

前置要求
  • Google Sheets API 凭证
  • PostgreSQL 数据库连接信息
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "nodes": [
    {
      "id": "678e86bc-2755-4c79-97d6-fa4da1ed9ff9",
      "name": "Postgres 触发器",
      "type": "n8n-nodes-base.postgresTrigger",
      "disabled": true,
      "position": [
        500,
        480
      ],
      "parameters": {
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "computed",
          "cachedResultName": "computed"
        },
        "firesOn": "UPDATE",
        "tableName": {
          "__rl": true,
          "mode": "list",
          "value": "users",
          "cachedResultName": "users"
        },
        "additionalFields": {}
      },
      "credentials": {
        "postgres": {
          "id": "8",
          "name": "Postgres Product Analytics"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "accecdfc-283c-4119-9b23-4cf44bc5e68c",
      "name": "过滤器",
      "type": "n8n-nodes-base.filter",
      "notes": "Filter out @n8n.io emails",
      "position": [
        980,
        540
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.email }}",
              "value2": "n8n.io",
              "operation": "notContains"
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 1
    },
    {
      "id": "d16d7ae7-0c60-48f0-97fe-c7618cab73d3",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        380
      ],
      "parameters": {
        "width": 424,
        "height": 559,
        "content": "## 👋 如何使用此模板"
      },
      "typeVersion": 1
    },
    {
      "id": "8bc7439e-d814-4960-8b75-fc77805f74c7",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        460,
        380
      ],
      "parameters": {
        "width": 344,
        "height": 562,
        "content": "### 1. 触发步骤监听新事件"
      },
      "typeVersion": 1
    },
    {
      "id": "63b2bc4c-8e33-4432-af4b-4595b2012ce1",
      "name": "便签 6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        840,
        460
      ],
      "parameters": {
        "width": 462,
        "height": 407,
        "content": "### 2. 过滤和转换您的数据"
      },
      "typeVersion": 1
    },
    {
      "id": "448e2c49-aa75-405b-ba51-3acbce0fb758",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1340,
        460
      ],
      "parameters": {
        "width": 342.52886836027733,
        "height": 407.43618112665195,
        "content": "### 3. 将用户保存在 Google Sheets 中"
      },
      "typeVersion": 1
    },
    {
      "id": "c0ee182d-4c31-488b-a547-5f2d2ba8786e",
      "name": "点击 \"Execute Node\" 时",
      "type": "n8n-nodes-base.manualTrigger",
      "notes": "For testing the workflow",
      "position": [
        500,
        680
      ],
      "parameters": {},
      "notesInFlow": true,
      "typeVersion": 1
    },
    {
      "id": "87f2a11e-f704-4c9e-ac8b-ee1f057cd347",
      "name": "代码",
      "type": "n8n-nodes-base.code",
      "notes": "Mock Data",
      "position": [
        680,
        680
      ],
      "parameters": {
        "jsCode": "return [\n  {\n    \"id\": 1,\n    \"username\": \"max_mustermann\",\n    \"email\": \"max_mustermann@acme.com\",\n    \"company_size\": \"500-999\",\n    \"role\": \"Sales\",\n    \"users\": 50\n  }\n]"
      },
      "notesInFlow": true,
      "typeVersion": 1
    },
    {
      "id": "0992077f-b6d3-47d2-94d2-c612dfbf5062",
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "notes": "Add to \"Users to contact\"",
      "position": [
        1400,
        540
      ],
      "parameters": {
        "columns": {
          "value": {
            "id": "={{ $json.id }}",
            "email": "={{ $json.email }}",
            "username": "={{ $json.username }}"
          },
          "schema": [
            {
              "id": "id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "id",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "username",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "username",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "contacted",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "contacted",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "id"
          ]
        },
        "options": {
          "cellFormat": "USER_ENTERED"
        },
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gVfyernVtgYXD-oPboxOSJYQ-HEfAguEryZ7gTtK0V8/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1gVfyernVtgYXD-oPboxOSJYQ-HEfAguEryZ7gTtK0V8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gVfyernVtgYXD-oPboxOSJYQ-HEfAguEryZ7gTtK0V8/edit?usp=drivesdk",
          "cachedResultName": "Qualified leads to contact"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "9",
          "name": "Google Sheets account"
        }
      },
      "notesInFlow": true,
      "typeVersion": 4
    }
  ],
  "connections": {
    "Code": {
      "main": [
        [
          {
            "node": "Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Trigger": {
      "main": [
        [
          {
            "node": "Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On clicking \"Execute Node\"": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 销售, 工程

需要付费吗?

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

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

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

作者
n8n Team

n8n Team

@n8n-team

Meet the official n8n team. We specialize in building workflows that transform intricate tasks into seamless operations.

外部链接
在 n8n.io 查看

分享此工作流