{
  "name": "Formstep: public form to a CRM-prefilled request",
  "nodes": [
    {
      "parameters": {
        "content": "## Public form to a CRM-prefilled request\n\n1. **New email on the public form**: pick your short public form. It needs an email question with the field key `email`.\n2. **Find the contact in HubSpot**: pick a HubSpot App Token credential with the `crm.objects.contacts.read` scope.\n3. **Send the second form**: pick your Formstep credential and the published Client Onboarding form.\n\nDelivery is Email the Invitation, which needs Formstep Pro or Business. On Free, set it to None and send the request's `url` from a node of your own.\n\nTest Mode is on, so nothing is emailed. Turn it off before you publish.",
        "height": 360,
        "width": 620,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -360
      ],
      "id": "2f0a6c1e-1000-4000-8000-000000000001",
      "name": "How to set it up"
    },
    {
      "parameters": {
        "formId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "event": "submission_created"
      },
      "type": "n8n-nodes-formstep.formstepTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ],
      "id": "2f0a6c1e-1000-4000-8000-000000000002",
      "name": "New email on the public form"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.hubapi.com/crm/v3/objects/contacts/search",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "hubspotAppToken",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ filterGroups: [{ filters: [{ propertyName: 'email', operator: 'EQ', value: $json.data.answers.email }] }], properties: ['firstname', 'lastname', 'company'], limit: 1 }) }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        240,
        0
      ],
      "id": "2f0a6c1e-1000-4000-8000-000000000003",
      "name": "Find the contact in HubSpot"
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// The first HubSpot match, or none: a new lead still gets the form, with less filled in.\nconst event = $('New email on the public form').item.json.data\nconst match = $json.results[0]\nconst contact = match ? match.properties : {}\nreturn {\n  json: {\n    email: event.answers.email,\n    first_name: contact.firstname ?? '',\n    full_name: [contact.firstname, contact.lastname].filter(Boolean).join(' '),\n    company_name: contact.company ?? '',\n    metadata: match ? { hubspotContactId: match.id } : {},\n    submission_id: event.submission.id,\n  },\n}"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        480,
        0
      ],
      "id": "2f0a6c1e-1000-4000-8000-000000000004",
      "name": "Shape the prefill"
    },
    {
      "parameters": {
        "resource": "request",
        "operation": "create",
        "formId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "recipientEmail": "={{ $json.email }}",
        "fields": {
          "mappingMode": "defineBelow",
          "value": {
            "full_name": "={{ $json.full_name }}",
            "email": "={{ $json.email }}",
            "company_name": "={{ $json.company_name }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "full_name",
              "displayName": "Full Name (full_name)",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": false,
              "display": true,
              "type": "string"
            },
            {
              "id": "email",
              "displayName": "Email Address (email)",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": false,
              "display": true,
              "type": "string"
            },
            {
              "id": "company_name",
              "displayName": "Company (company_name)",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": false,
              "display": true,
              "type": "string"
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "readonly": [
          "email"
        ],
        "waitForOutcome": false,
        "additionalFields": {
          "delivery": "email",
          "recipientName": "={{ $json.first_name }}",
          "externalId": "=signup-{{ $json.submission_id }}",
          "metadata": "={{ JSON.stringify($json.metadata) }}",
          "test": true
        }
      },
      "type": "n8n-nodes-formstep.formstep",
      "typeVersion": 5,
      "position": [
        720,
        0
      ],
      "id": "2f0a6c1e-1000-4000-8000-000000000005",
      "name": "Send the second form"
    }
  ],
  "pinData": {},
  "connections": {
    "New email on the public form": {
      "main": [
        [
          {
            "node": "Find the contact in HubSpot",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find the contact in HubSpot": {
      "main": [
        [
          {
            "node": "Shape the prefill",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Shape the prefill": {
      "main": [
        [
          {
            "node": "Send the second form",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}