{
  "name": "Incoming WhatsApp (WbizTool) → HubSpot note",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "wbiztool-hubspot-notes",
        "responseMode": "onReceived",
        "options": {}
      },
      "id": "c2a36c0b-62df-5cdb-aa4b-fb9327965cd4",
      "name": "WbizTool webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        300
      ],
      "webhookId": "ebf68bb4-b88e-5c34-a60b-b873905e9f6e"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "03d986e2-cbbd-5dd9-aa26-a6df709a998a",
              "leftValue": "={{ $json.body.contact.is_group }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              }
            },
            {
              "id": "bdcc310c-af6b-5a42-bc45-0de4a58a8dd5",
              "leftValue": "={{ $json.body.contact.phone_hidden }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              }
            },
            {
              "id": "dda98f71-891e-5505-8c6c-e2b8f7f11ee8",
              "leftValue": "={{ $json.body.contact.phone }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "86aa08d6-90a2-5f92-a9db-7d7efb5f7f22",
      "name": "Person with a number?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        220,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// Your country code, without +: it is removed from the front of the number,\n// because HubSpot searches phone numbers without their country code.\nconst countryCode = '1';\n\nreturn $input.all().map((item) => {\n  const data = item.json.body;\n  const phone = String(data.contact.phone || '');\n  const national = phone.startsWith(countryCode) ? phone.slice(countryCode.length) : phone;\n  const name = data.contact.name || '';\n  const label = data.message.direction === 'outgoing' ? 'WhatsApp to' : 'WhatsApp from';\n  return {\n    json: {\n      phone,\n      national,\n      name,\n      note: `${label} ${name} (+${phone}): ${data.message.content}`,\n      timestamp: data.message.timestamp,\n      messageId: data.message.id,\n    },\n  };\n});\n"
      },
      "id": "7f2017f8-f94f-5a1d-8f29-71fac8fd6b23",
      "name": "National number",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        440,
        280
      ]
    },
    {
      "parameters": {
        "authentication": "appToken",
        "resource": "contact",
        "operation": "search",
        "returnAll": false,
        "limit": 1,
        "filterGroupsUi": {
          "filterGroupsValues": [
            {
              "filtersUi": {
                "filterValues": [
                  {
                    "propertyName": "phone|string",
                    "operator": "EQ",
                    "value": "={{ $json.national }}"
                  }
                ]
              }
            },
            {
              "filtersUi": {
                "filterValues": [
                  {
                    "propertyName": "mobilephone|string",
                    "operator": "EQ",
                    "value": "={{ $json.national }}"
                  }
                ]
              }
            }
          ]
        },
        "additionalFields": {
          "properties": [
            "firstname",
            "phone"
          ]
        }
      },
      "id": "5c4c9f1e-5fa8-587b-8876-e38e2911d4d8",
      "name": "Find contact by phone",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2.2,
      "position": [
        660,
        280
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "c0bd8b21-c60b-5f41-8a82-81a1bccd7c21",
              "leftValue": "={{ $json.id }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "7c5ccd3c-3ad4-58fe-a882-cfd0881b0323",
      "name": "Contact found?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        880,
        280
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.hubapi.com/crm/objects/2026-09/notes",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "hubspotAppToken",
        "options": {},
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ properties: { hs_timestamp: $('National number').first().json.timestamp, hs_note_body: $('National number').first().json.note }, associations: [{ to: { id: $json.id }, types: [{ associationCategory: 'HUBSPOT_DEFINED', associationTypeId: 202 }] }] }) }}"
      },
      "id": "5d69b489-8ec7-5df7-953f-e488498a66e3",
      "name": "Add note",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1100,
        180
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.hubapi.com/crm/objects/2026-09/contacts",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "hubspotAppToken",
        "options": {},
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ properties: { phone: '+' + $('National number').first().json.phone, firstname: $('National number').first().json.name } }) }}"
      },
      "id": "0e7e1ced-528b-560f-af6d-70ed45fb2c21",
      "name": "Create contact",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1100,
        400
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.hubapi.com/crm/objects/2026-09/notes",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "hubspotAppToken",
        "options": {},
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ properties: { hs_timestamp: $('National number').first().json.timestamp, hs_note_body: $('National number').first().json.note }, associations: [{ to: { id: $json.id }, types: [{ associationCategory: 'HUBSPOT_DEFINED', associationTypeId: 202 }] }] }) }}"
      },
      "id": "74b6e6b8-d3cf-5efa-8916-e7397c9fce72",
      "name": "Add note to new contact",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1320,
        400
      ]
    }
  ],
  "connections": {
    "WbizTool webhook": {
      "main": [
        [
          {
            "node": "Person with a number?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Person with a number?": {
      "main": [
        [
          {
            "node": "National number",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "National number": {
      "main": [
        [
          {
            "node": "Find contact by phone",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find contact by phone": {
      "main": [
        [
          {
            "node": "Contact found?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Contact found?": {
      "main": [
        [
          {
            "node": "Add note",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create contact": {
      "main": [
        [
          {
            "node": "Add note to new contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
