{
  "name": "Trevilo: qualified lead to HubSpot contact and task",
  "nodes": [
    {
      "parameters": {
        "content": "## Trevilo: qualified lead to HubSpot contact and task\n\n1. Open **Trevilo enquiry**, copy the **Production URL**.\n2. In **Trevilo enquiry**, create a **Header Auth** credential: name `X-Webhook-Key`, value a long random key.\n3. In Trevilo, add a rule about \"A new enquiry or quote\", \"A product\" or \"A service\" and send it to an n8n connection with that URL. Set its login to **API key in a header**, header name `X-Webhook-Key`, and the same key.\n4. In both HubSpot steps, create a **HubSpot App Token** credential from a HubSpot private app.\n5. In **Create task**, set the owner who should follow up (Associations, Owner ID).\n6. Publish, then send a test enquiry from Trevilo.",
        "height": 420,
        "width": 460
      },
      "id": "4c1fa568-fbce-5c29-84eb-615099c5ba6e",
      "name": "Setup",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -560,
        -280
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "trevilo-qualified-lead",
        "authentication": "headerAuth",
        "options": {}
      },
      "id": "e27768f4-7018-5383-8262-d44c12feef8e",
      "name": "Trevilo enquiry",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.2,
      "position": [
        0,
        0
      ],
      "webhookId": "a21ee911-3e14-5abf-8008-0757dc229ada"
    },
    {
      "parameters": {
        "operation": "removeItemsSeenInPreviousExecutions",
        "dedupeValue": "={{ $('Trevilo enquiry').item.json.headers['idempotency-key'] }}",
        "options": {}
      },
      "id": "0f33a7c4-6c2e-54b8-9f56-4ba01392fb4c",
      "name": "Skip repeat deliveries",
      "type": "n8n-nodes-base.removeDuplicates",
      "typeVersion": 2,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "d76ebea6-2b00-5136-9a71-3e1cb1ccfde8",
              "leftValue": "={{ [null, 'inquiry', 'product', 'service'].includes($('Trevilo enquiry').item.json.body.enquiry?.intent ?? null) && Boolean($('Trevilo enquiry').item.json.body.contact?.email) }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "4964a46b-69a1-54f4-ad32-d51311e21626",
      "name": "Qualified lead with email?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "authentication": "appToken",
        "resource": "contact",
        "operation": "upsert",
        "email": "={{ $('Trevilo enquiry').item.json.body.contact.email }}",
        "additionalFields": {
          "firstName": "={{ ($('Trevilo enquiry').item.json.body.enquiry?.name || '').split(' ')[0] }}",
          "lastName": "={{ ($('Trevilo enquiry').item.json.body.enquiry?.name || '').split(' ').slice(1).join(' ') }}",
          "phoneNumber": "={{ $('Trevilo enquiry').item.json.body.contact?.phone || '' }}",
          "message": "={{ $('Trevilo enquiry').item.json.body.enquiry?.message || '' }}"
        },
        "options": {}
      },
      "id": "c3541918-3d76-5619-a602-1bc2824ad585",
      "name": "Create or update contact",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2.2,
      "position": [
        660,
        -100
      ]
    },
    {
      "parameters": {
        "authentication": "appToken",
        "resource": "engagement",
        "type": "task",
        "dueDate": "={{ $now.plus({ days: 1 }).toISO() }}",
        "metadata": {
          "subject": "=Follow up: {{ $('Trevilo enquiry').item.json.body.enquiry?.intent_label || 'Not classified' }} from {{ $('Trevilo enquiry').item.json.body.enquiry?.name || $('Trevilo enquiry').item.json.body.contact.email }}",
          "body": "={{ $('Trevilo enquiry').item.json.body.enquiry?.message || '' }}\n\nPage: {{ $('Trevilo enquiry').item.json.body.source?.url || '' }}",
          "status": "NOT_STARTED",
          "forObjectType": "CONTACT"
        },
        "additionalFields": {
          "associations": {
            "contactIds": "={{ $json.vid }}"
          }
        }
      },
      "id": "179d0463-26a2-5c5c-a5ea-884d2faa94cf",
      "name": "Create task",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2.2,
      "position": [
        880,
        -100
      ]
    }
  ],
  "connections": {
    "Trevilo enquiry": {
      "main": [
        [
          {
            "node": "Skip repeat deliveries",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Skip repeat deliveries": {
      "main": [
        [
          {
            "node": "Qualified lead with email?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create or update contact": {
      "main": [
        [
          {
            "node": "Create task",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Qualified lead with email?": {
      "main": [
        [
          {
            "node": "Create or update contact",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  }
}
