cosmolocal-website/n8n-workflows/01-contact-intake.json

208 lines
5.3 KiB
JSON

{
"name": "Contact Intake — Form to CRM",
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "contact-intake",
"responseMode": "responseNode",
"options": {}
},
"id": "webhook-trigger",
"name": "Webhook — Contact Form",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [240, 300],
"webhookId": "contact-intake"
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "check-email",
"leftValue": "={{ $json.body.email }}",
"rightValue": "",
"operator": {
"type": "string",
"operation": "isNotEmpty"
}
},
{
"id": "check-name",
"leftValue": "={{ $json.body.name }}",
"rightValue": "",
"operator": {
"type": "string",
"operation": "isNotEmpty"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "validate-input",
"name": "Validate Input",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [460, 300]
},
{
"parameters": {
"method": "POST",
"url": "=https://crm.cosmolocal.world/api/v1/objects/people",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "Bearer {{ $env.TWENTY_API_KEY }}"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"name\": {\n \"firstName\": \"{{ $json.body.name.split(' ')[0] }}\",\n \"lastName\": \"{{ $json.body.name.split(' ').slice(1).join(' ') || '' }}\"\n },\n \"emails\": {\n \"primaryEmail\": \"{{ $json.body.email }}\"\n },\n \"phones\": {\n \"primaryPhone\": \"{{ $json.body.phone || '' }}\"\n }\n}",
"options": {}
},
"id": "create-crm-contact",
"name": "Create Contact in Twenty CRM",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [680, 240]
},
{
"parameters": {
"method": "POST",
"url": "=https://crm.cosmolocal.world/api/v1/objects/notes",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "Bearer {{ $env.TWENTY_API_KEY }}"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"title\": \"Contact Form Submission\",\n \"body\": \"{{ $('Webhook — Contact Form').item.json.body.message || 'No message provided' }}\",\n \"noteTargets\": [{\n \"personId\": \"{{ $json.data.id }}\"\n }]\n}",
"options": {}
},
"id": "add-note",
"name": "Add Note to Contact",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [900, 240]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={ \"success\": true, \"message\": \"Contact created successfully\" }",
"options": {
"responseCode": 200
}
},
"id": "respond-success",
"name": "Respond — Success",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.1,
"position": [1120, 240]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={ \"success\": false, \"message\": \"Missing required fields: name and email\" }",
"options": {
"responseCode": 400
}
},
"id": "respond-error",
"name": "Respond — Validation Error",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.1,
"position": [680, 420]
}
],
"connections": {
"Webhook — Contact Form": {
"main": [
[
{
"node": "Validate Input",
"type": "main",
"index": 0
}
]
]
},
"Validate Input": {
"main": [
[
{
"node": "Create Contact in Twenty CRM",
"type": "main",
"index": 0
}
],
[
{
"node": "Respond — Validation Error",
"type": "main",
"index": 0
}
]
]
},
"Create Contact in Twenty CRM": {
"main": [
[
{
"node": "Add Note to Contact",
"type": "main",
"index": 0
}
]
]
},
"Add Note to Contact": {
"main": [
[
{
"node": "Respond — Success",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"tags": [
{
"name": "cosmolocal"
},
{
"name": "crm"
}
],
"pinData": {}
}