{
  "name": "Pipedrive deal from a web form",
  "nodes": [
    {
      "parameters": {
        "content": "## Pipedrive deal from a web form\n\nPortfolio demo only. This workflow is an original example for demonstration. It is not client work and it does not represent a deployment for any customer.\n\nRun **Run demo** to execute the offline rules engine. The live branch is used only when the incoming item sets `demo` to false and the placeholder credentials have been replaced.",
        "height": 220,
        "width": 520,
        "color": 4
      },
      "id": "77d9d569-2a7b-41fd-ba99-e27db2edf410",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -40
      ]
    },
    {
      "parameters": {},
      "id": "3bc94725-e6b7-4af0-bd2c-9fdc32aa2f3e",
      "name": "Run demo",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        40,
        280
      ],
      "notes": "CLI and the n8n editor start here. An empty manual run loads the bundled sample.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "pipedrive-deal-from-web-form",
        "authentication": "none",
        "responseMode": "lastNode",
        "responseData": "firstEntryJson",
        "options": {}
      },
      "id": "1a9f71c8-cbba-4f4a-a33b-a942db8fb0f1",
      "name": "Inbound webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        40,
        460
      ],
      "notes": "POST JSON to this path. Include demo:false only after credentials are connected.",
      "notesInFlow": true,
      "webhookId": "86c18d7b-d2ee-4fc9-8517-3fe5b9c776db"
    },
    {
      "parameters": {
        "formTitle": "Tell us about the project",
        "formDescription": "Portfolio demo form. Submissions land in the same rules engine as the webhook.",
        "responseMode": "lastNode",
        "formFields": {
          "values": [
            {
              "fieldLabel": "firstName",
              "fieldType": "text",
              "requiredField": false
            },
            {
              "fieldLabel": "lastName",
              "fieldType": "text",
              "requiredField": false
            },
            {
              "fieldLabel": "email",
              "fieldType": "text",
              "requiredField": false
            },
            {
              "fieldLabel": "company",
              "fieldType": "text",
              "requiredField": false
            },
            {
              "fieldLabel": "title",
              "fieldType": "text",
              "requiredField": false
            },
            {
              "fieldLabel": "employees",
              "fieldType": "number",
              "requiredField": false
            }
          ]
        }
      },
      "id": "b4570644-723b-40c0-846b-07ef2d48ba35",
      "name": "Web form",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        40,
        640
      ],
      "notes": "n8n Form trigger. Field names match the sample payload.",
      "notesInFlow": true,
      "webhookId": "1fb3f743-b12e-425d-bb94-27b2a11b21e3"
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const sample = {\n  \"demo\": true,\n  \"firstName\": \"Nora\",\n  \"lastName\": \"Rahman\",\n  \"email\": \"nora@brightline.example\",\n  \"company\": \"Northwind Supplies\",\n  \"title\": \"Head of Operations\",\n  \"employees\": 42,\n  \"budget\": 12000,\n  \"source\": \"referral\",\n  \"utmSource\": \"linkedin\",\n  \"utmMedium\": \"cpc\",\n  \"utmCampaign\": \"ops-audit-q1\"\n};\nconst incoming = $input.first()?.json ?? {};\nconst provided = Object.keys(incoming).filter((key) => incoming[key] !== undefined && incoming[key] !== null && incoming[key] !== '');\nconst base = provided.length ? { ...sample, ...incoming } : { ...sample };\nconst flag = incoming.demo;\nbase.demo = !(flag === false || flag === 'false' || flag === 0 || flag === '0');\nreturn [{ json: base }];\n"
      },
      "id": "8dbdf98b-d111-467b-bb1b-04f3a62da7ce",
      "name": "Normalize input",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        340,
        360
      ],
      "notes": "Merges the request over the bundled sample. demo stays true unless the caller explicitly turns it off.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const item = $input.first().json;\nconst produced = (() => {\n\nconst email = String(item.email || '').trim().toLowerCase();\nconst company = String(item.company || 'Unknown company').trim();\nconst source = String(item.source || 'unknown').trim().toLowerCase();\nconst employees = Number(item.employees || item.headcount || 0);\nconst budget = Number(item.budget || 0);\nconst title = String(item.title || '').toLowerCase();\nconst domain = email.includes('@') ? email.split('@')[1] : '';\nconst freeDomains = ['gmail.com', 'yahoo.com', 'hotmail.com', 'outlook.com'];\nconst intentSources = ['demo', 'pricing', 'referral'];\nlet score = 15;\nconst reasons = [];\nif (email && !freeDomains.includes(domain)) {\n  score += 15;\n  reasons.push('work email');\n} else if (email) {\n  reasons.push('free inbox, keep it in nurture');\n}\nif (employees >= 50) {\n  score += 20;\n  reasons.push('headcount at or above 50');\n} else if (employees >= 10) {\n  score += 10;\n  reasons.push('team of 10 or more');\n}\nif (intentSources.includes(source)) {\n  score += 25;\n  reasons.push('high-intent source: ' + source);\n}\nif (budget >= 4000) {\n  score += 15;\n  reasons.push('budget at or above 4000');\n}\nif (/(founder|owner|vp|head|director|ceo|cto|cmo)/.test(title)) {\n  score += 10;\n  reasons.push('buyer title');\n}\nscore = Math.max(0, Math.min(100, score));\nlet tier = score >= 70 ? 'sql' : score >= 40 ? 'mql' : 'nurture';\nconst known = Array.isArray(item.knownEmails) ? item.knownEmails.map((value) => String(value).toLowerCase()) : [];\nif (email && known.includes(email)) tier = 'duplicate';\nconst record = {\n  email,\n  firstName: item.firstName || '',\n  lastName: item.lastName || '',\n  company,\n  title: item.title || '',\n  source,\n  employees,\n  budget,\n  score,\n  tier,\n  reasons: reasons.join('; '),\n  dealName: company + ' \u2014 ' + tier.toUpperCase(),\n  amount: budget,\n  stage: tier === 'sql' ? 'appointmentscheduled' : 'qualifiedtobuy',\n};\nreturn {\n  summary: tier === 'duplicate'\n    ? email + ' is already on file. No new Pipedrive record is required.'\n    : company + ' (' + email + ') scored ' + score + ' and landed in ' + tier + ' for Pipedrive.',\n  route: tier,\n  record,\n  slackText: tier.toUpperCase() + ' lead ' + email + ' at ' + company + ' scored ' + score + '. ' + reasons[0],\n  actions: [\n    { app: 'Pipedrive', operation: 'upsert', payload: record },\n  ],\n};\n\n})();\nif (!produced || typeof produced.summary !== 'string' || !produced.summary.trim()) {\n  throw new Error('Apply rules must return a summary string');\n}\nreturn [{\n  json: {\n    ...item,\n    ...produced,\n    demo: item.demo !== false,\n  },\n}];\n"
      },
      "id": "adda30db-90c3-42d5-98ee-9fee80f5798b",
      "name": "Apply rules",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        620,
        360
      ],
      "notes": "Deterministic stand-in for the model or enrichment API. Replace or precede this with a live model node when you turn demo mode off.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "e91d9665-f3f3-4cb4-aac5-87a8d7a9ddc4",
              "leftValue": "={{ $json.demo }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "b12be24e-1954-4ace-b82f-389184e2be43",
      "name": "Demo mode?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        900,
        360
      ],
      "notes": "True: package the offline result. False: run the credentialed apps.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const item = $input.first().json;\nreturn [{\n  json: {\n    demo: true,\n    status: 'demo_ready',\n    workflow: 'pipedrive-deal-from-web-form',\n    summary: item.summary,\n    route: item.route ?? null,\n    record: item.record ?? {},\n    actions: item.actions ?? [],\n    slackText: item.slackText ?? item.summary,\n    notes: 'Demo mode did not call external apps. Send {\"demo\": false} after placeholder credentials are replaced.',\n  },\n}];\n"
      },
      "id": "be6c7c28-9a3b-4877-b45b-f4fb536a2005",
      "name": "Package demo result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1180,
        180
      ]
    },
    {
      "parameters": {
        "authentication": "apiToken",
        "resource": "person",
        "operation": "create",
        "title": "={{ $json.record.dealName || $json.record.company || $json.summary }}",
        "name": "={{ $json.record.fullName || $json.record.email || 'Lead' }}",
        "associateWith": "organization",
        "org_id": 0,
        "additionalFields": {}
      },
      "id": "f648235d-4619-41b0-abc3-50285bbcf6e9",
      "name": "Create Pipedrive person",
      "type": "n8n-nodes-base.pipedrive",
      "typeVersion": 2,
      "position": [
        1180,
        760
      ],
      "credentials": {
        "pipedriveApi": {
          "id": "PLACEHOLDER_PIPEDRIVEAPI",
          "name": "Pipedrive account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "apiToken",
        "resource": "deal",
        "operation": "create",
        "title": "={{ $json.record.dealName || $json.record.company || $json.summary }}",
        "name": "={{ $json.record.fullName || $json.record.email || 'Lead' }}",
        "associateWith": "organization",
        "org_id": 0,
        "additionalFields": {}
      },
      "id": "d25c93bb-d7d8-442f-81d9-11382baccd50",
      "name": "Create Pipedrive deal",
      "type": "n8n-nodes-base.pipedrive",
      "typeVersion": 2,
      "position": [
        1460,
        760
      ],
      "credentials": {
        "pipedriveApi": {
          "id": "PLACEHOLDER_PIPEDRIVEAPI",
          "name": "Pipedrive account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "message",
        "operation": "post",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "name",
          "value": "#pipeline"
        },
        "text": "={{ $json.slackText || $json.summary }}",
        "otherOptions": {}
      },
      "id": "e2869416-9965-4024-a2d0-144a75ba46e3",
      "name": "Post #pipeline",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        1740,
        760
      ],
      "credentials": {
        "slackOAuth2Api": {
          "id": "PLACEHOLDER_SLACKOAUTH2API",
          "name": "Slack account"
        }
      }
    },
    {
      "parameters": {
        "content": "## Live path\n\nReplace every `PLACEHOLDER_*` credential, then POST the sample with `\"demo\": false`.\n\nThe nodes on this branch use the `record` and `actions` fields produced by Apply rules.",
        "height": 180,
        "width": 420,
        "color": 6
      },
      "id": "4380ece8-57e3-4997-9b2b-8fcecfc5bbcc",
      "name": "Live path",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1120,
        520
      ]
    }
  ],
  "connections": {
    "Run demo": {
      "main": [
        [
          {
            "node": "Normalize input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Inbound webhook": {
      "main": [
        [
          {
            "node": "Normalize input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Web form": {
      "main": [
        [
          {
            "node": "Normalize input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize input": {
      "main": [
        [
          {
            "node": "Apply rules",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apply rules": {
      "main": [
        [
          {
            "node": "Demo mode?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Demo mode?": {
      "main": [
        [
          {
            "node": "Package demo result",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Pipedrive person",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Pipedrive person": {
      "main": [
        [
          {
            "node": "Create Pipedrive deal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Pipedrive deal": {
      "main": [
        [
          {
            "node": "Post #pipeline",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "A web form creates a Pipedrive person and a deal, then posts the new deal title to Slack. The rules node sets the stage from the budget and source."
  },
  "active": false
}
