{
  "id": "Q59diTWu6qw9qmTo",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Sync your Zoho contacts to Beex",
  "tags": [],
  "nodes": [
    {
      "id": "92b2057e-e458-4f30-9115-897bebe5570c",
      "name": "On Listen Event",
      "type": "n8n-nodes-base.webhook",
      "notes": "Zoho Webhook",
      "position": [
        -928,
        192
      ],
      "parameters": {
        "path": "98e20ba4-3a3a-4186-bf1a-1b51ee2075e0",
        "options": {},
        "httpMethod": "POST"
      },
      "notesInFlow": true,
      "typeVersion": 2.1
    },
    {
      "id": "0a2b0669-3996-4f64-930d-898504a15945",
      "name": "Set Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        -688,
        192
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "53baf435-10df-495d-990c-198bfa38f1a7",
              "name": "event",
              "type": "string",
              "value": "={{ $json.headers.event }}"
            },
            {
              "id": "c9d4c456-267c-4da4-8b99-5ad91e24f3f1",
              "name": "code",
              "type": "string",
              "value": "={{ $json.body.id }}"
            },
            {
              "id": "a0314695-11b1-4580-a4c2-36b82715c60d",
              "name": "name",
              "type": "string",
              "value": "={{ $json.body.name }}"
            },
            {
              "id": "250f6841-4d55-4489-8da0-470e7ca26e59",
              "name": "lastName",
              "type": "string",
              "value": "={{ $json.body.lastName }}"
            },
            {
              "id": "453355b6-7f32-4dca-9022-7302d9e8075d",
              "name": "countryCode",
              "type": "string",
              "value": "={{ $json.body.phone.split(' ')[0].slice(1) }}"
            },
            {
              "id": "6b9ed8fc-3a7a-48cd-8889-5a71af8b25a4",
              "name": "phone",
              "type": "string",
              "value": "={{ $json.body.phone.split(' ')[1] }}"
            },
            {
              "id": "9df6d7e2-b01d-4d2d-9654-cad3d10ded9f",
              "name": "email",
              "type": "string",
              "value": "={{ $json.body.email }}"
            },
            {
              "id": "a2ff654b-7b24-46f2-bbb6-0bbfd3cf0a5b",
              "name": "portfolio_id",
              "type": "string",
              "value": "81"
            },
            {
              "id": "b0969b74-2fc0-4717-abad-cc315f50beca",
              "name": "sequence_id",
              "type": "string",
              "value": "26"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "0287c5be-737a-49be-8bc1-9d88a9381284",
      "name": "Routing",
      "type": "n8n-nodes-base.switch",
      "position": [
        -464,
        192
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "CREATED",
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "1a34c2a4-fefc-41a7-8cd4-773705b22dfa",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.event }}",
                    "rightValue": "insert"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "UPDATED",
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "c2688616-e7cd-4473-a4b7-df1056d75aaa",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.event }}",
                    "rightValue": "update"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.4
    },
    {
      "id": "5fe454e8-3c55-451e-a822-33df71636b25",
      "name": "Filter Phone",
      "type": "n8n-nodes-base.filter",
      "notes": "is not null",
      "position": [
        -240,
        96
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "4f0bcb67-bafe-4c82-b286-5f5d87212e0c",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.phone }}",
              "rightValue": ""
            },
            {
              "id": "fafb25f5-788a-4269-941a-5a96ce193fd2",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.phone }}",
              "rightValue": ""
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 2.2
    },
    {
      "id": "cccd7822-bf56-4033-9f10-61d647fe5e36",
      "name": "Create Contact",
      "type": "n8n-nodes-beex.beex",
      "position": [
        -16,
        96
      ],
      "parameters": {
        "email": "={{ $json.email }}",
        "priority": 1,
        "resource": "leads",
        "code_client": "={{ $json.code }}",
        "sequence_id": "={{ $json.sequence_id }}",
        "code_country": "={{ $json.countryCode }}",
        "phone_number": "={{ $json.phone }}",
        "portfolio_id": "={{ $json.portfolio_id }}",
        "additionalParameters": {
          "text_01": "Example",
          "first_name": "={{ $json.name }}",
          "paternal_surname": "={{ $json.lastName }}"
        }
      },
      "credentials": {
        "beexApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "22cba1b3-8d23-4c33-8e1f-f56166956277",
      "name": "Get Client",
      "type": "n8n-nodes-beex.beex",
      "position": [
        -240,
        288
      ],
      "parameters": {
        "code": "={{ $json.code }}",
        "operation": "get-one"
      },
      "credentials": {
        "beexApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "a4704514-b369-4be3-8306-79b96d263c61",
      "name": "Update Client",
      "type": "n8n-nodes-beex.beex",
      "position": [
        -16,
        288
      ],
      "parameters": {
        "id": "={{ $json.results[0].id }}",
        "operation": "put",
        "first_name": "={{ $('Routing').item.json.name }}",
        "additionalFields": {},
        "paternal_surname": "={{ $('Routing').item.json.lastName }}",
        "additionalFilters": {}
      },
      "credentials": {
        "beexApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "78e89499-3730-49a4-9bcf-12bbab06c41e",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1616,
        -224
      ],
      "parameters": {
        "width": 496,
        "height": 864,
        "content": "## Sync Zoho Contacts to Beex\n\n> **Disclaimer:** This workflow requires the community node `n8n-nodes-beex`\n\n### Overview\n\nThis workflow listens for **contact creation and update events** from Zoho via a webhook and synchronizes them with **Beex contacts**.\n\n### How It Works\n\n1. **Trigger**: A standard Webhook node receives Zoho contact events. The event type is passed via a request header field called `event`.\n2. **Data Transformation**: A **Set Fields** node flattens and formats the Zoho payload into a clean JSON structure for easier field handling downstream.\n3. **Event Routing**: A **Routing** node reads the `event` header and directs the flow to the appropriate branch:\n   - `CREATED`\n   - `UPDATED`\n4. **Create Branch**: A filter node verifies the contact has a non-null phone number, then creates the contact in Beex using `post: leads`.\n5. **Update Branch**: The Beex **Get Client** node fetches the existing record by matching the Zoho Contact ID stored as the client code in Beex. The client is then updated using `put: clients`.\n\n### Requirements\n\n- **Beex Account** with permission to manage contacts and clients\n  - Community node `n8n-nodes-beex` must be installed\n  - Valid Bearer token configured in the Beex nodes\n- **Zoho Account** with webhook configuration enabled\n  - Must POST `CREATED` and `UPDATED` contact events to the n8n Webhook URL `(HTTP Method \u2192 POST)`\n  - The `event` header field must be included in every outgoing request"
      },
      "typeVersion": 1
    },
    {
      "id": "7247e35c-666b-4493-a6fe-3b9fba539451",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -496,
        -48
      ],
      "parameters": {
        "color": 7,
        "width": 720,
        "height": 528,
        "content": "## Routing + Create/Update\n- Possible Branches: `Creation` or `Update`.\n- A contact is **created** with an available phone number.\n- The contact is **updated** by matching it with the contact ID in Zoho."
      },
      "typeVersion": 1
    },
    {
      "id": "c677dd4f-699b-4d32-b6c4-5c15b95abd61",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1008,
        -48
      ],
      "parameters": {
        "color": 7,
        "width": 256,
        "height": 528,
        "content": "## Trigger Node \n- Link the webhook **URL** on Zoho in Instant Actions"
      },
      "typeVersion": 1
    },
    {
      "id": "9c443005-1bb1-4d94-9b26-bf8fb32571aa",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -752,
        -48
      ],
      "parameters": {
        "color": 5,
        "width": 256,
        "height": 528,
        "content": "## Set Fields\n- The fields to be extracted are defined in Zoho CRM by Workflow Rules"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "timezone": "America/Lima",
    "binaryMode": "separate",
    "callerPolicy": "workflowsFromSameOwner",
    "timeSavedMode": "fixed",
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "babc73f7-db22-44f0-8cfb-4dadfd6eb85b",
  "connections": {
    "Routing": {
      "main": [
        [
          {
            "node": "Filter Phone",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Client",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Client": {
      "main": [
        [
          {
            "node": "Update Client",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Fields": {
      "main": [
        [
          {
            "node": "Routing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Phone": {
      "main": [
        [
          {
            "node": "Create Contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Contact": {
      "main": [
        []
      ]
    },
    "On Listen Event": {
      "main": [
        [
          {
            "node": "Set Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}