Workflow: Production Workflow
Integrations: function, if, mautic, merge, set, stopAndError, switch, webhook

{"nodes": [{"name": "Webhook", "type": "n8n-nodes-base.webhook", "position": [-550, 450], "parameters": {"path": "PuHq2RQsmc3HXB/hook", "options": {"rawBody": false}, "httpMethod": "POST"}, "typeVersion": 1, "id": "node-ac41d08e"}, {"name": "Mautic", "type": "n8n-nodes-base.mautic", "position": [1260, 180], "parameters": {"email": "={{$node[\"@MAIN STUDENT DATA\"].json[\"student\"][\"email\"]}}", "company": 1, "options": {}, "lastName": "={{$node[\"@MAIN STUDENT DATA\"].json[\"student\"][\"lastName\"]}}", "firstName": "={{$node[\"@MAIN STUDENT DATA\"].json[\"student\"][\"firstName\"]}}", "authentication": "{{ $credentials.oAuth2 }}", "additionalFields": {}}, "credentials": {"mauticOAuth2Api": "OAuth2 Mautic"}, "typeVersion": 1, "alwaysOutputData": false, "id": "node-a642a0cf"}, {"name": "Find User", "type": "n8n-nodes-base.mautic", "position": [170, 260], "parameters": {"limit": 1, "options": {"search": "={{$node[\"Set Webhook Request\"].json[\"student\"][\"email\"]}}"}, "operation": "getAll", "authentication": "{{ $credentials.oAuth2 }}"}, "credentials": {"mauticOAuth2Api": "OAuth2 Mautic"}, "notesInFlow": false, "typeVersion": 1, "alwaysOutputData": false, "id": "node-8f9bd912"}, {"name": "Update User", "type": "n8n-nodes-base.mautic", "position": [1560, 250], "parameters": {"options": {}, "contactId": "={{$node[\"@MAIN STUDENT DATA\"].json[\"userFound\"]}}", "operation": "update", "updateFields": {"email": "={{$node[\"@MAIN STUDENT DATA\"].json[\"student\"][\"email\"]}}", "lastName": "={{$node[\"@MAIN STUDENT DATA\"].json[\"student\"][\"lastName\"]}}", "firstName": "={{$node[\"@MAIN STUDENT DATA\"].json[\"student\"][\"firstName\"]}}"}, "authentication": "{{ $credentials.oAuth2 }}"}, "credentials": {"mauticOAuth2Api": "OAuth2 Mautic"}, "typeVersion": 1, "id": "node-fac3ef36"}, {"name": "Tag User", "type": "n8n-nodes-base.mautic", "position": [430, 670], "parameters": {"options": {}, "contactId": "={{$node[\"Find User To Tag Sale\"].json[\"id\"]}}", "operation": "update", "updateFields": {"tags": "={{$node[\"Set Webhook Request\"].json[\"student\"][\"course\"][\"name\"]}}"}, "authentication": "{{ $credentials.oAuth2 }}"}, "credentials": {"mauticOAuth2Api": "OAuth2 Mautic"}, "typeVersion": 1, "id": "node-7f5515e6"}, {"name": "Unsubscribe User", "type": "n8n-nodes-base.mautic", "position": [2170, 410], "parameters": {"options": {}, "contactId": "={{$node[\"@MAIN STUDENT DATA\"].json[\"userFound\"]}}", "operation": "update", "updateFields": {"tags": "=#unsubscribe"}, "authentication": "{{ $credentials.oAuth2 }}"}, "credentials": {"mauticOAuth2Api": "OAuth2 Mautic"}, "typeVersion": 1, "id": "node-75041876"}, {"name": "Split Full Name", "type": "n8n-nodes-base.function", "position": [340, 420], "parameters": {"functionCode": "const student = items[0].json.student\nstudent.firstName = student.name ? student.name.split(' ').slice(0, -1).join(' ') : ''\nstudent.lastName= student.name ? student.name.split(' ').slice(-1).join(' ') : ''\nitems[0].json.student = student\nreturn items;"}, "typeVersion": 1, "id": "node-0f4593d8"}, {"name": "If not found return -1", "type": "n8n-nodes-base.function", "position": [450, 260], "parameters": {"functionCode": "items[0].json.id = items[0].json.id || -1\nreturn items"}, "typeVersion": 1, "id": "node-285ac437"}, {"name": "@MAIN STUDENT DATA", "type": "n8n-nodes-base.merge", "position": [900, 400], "parameters": {"join": "inner", "mode": "mergeByIndex"}, "typeVersion": 1, "id": "node-da23188f"}, {"name": "Remove unsubscribe", "type": "n8n-nodes-base.mautic", "position": [1770, 500], "parameters": {"options": {}, "contactId": "={{$node[\"@MAIN STUDENT DATA\"].json[\"userFound\"]}}", "operation": "update", "updateFields": {"tags": "=-#unsubscribe"}, "authentication": "{{ $credentials.oAuth2 }}"}, "credentials": {"mauticOAuth2Api": "OAuth2 Mautic"}, "typeVersion": 1, "id": "node-1a0b7db0"}, {"name": "Find User To Tag Sale", "type": "n8n-nodes-base.mautic", "position": [190, 670], "parameters": {"limit": 1, "options": {"search": "={{$node[\"Set Webhook Request\"].json[\"student\"][\"user\"][\"email\"]}}"}, "operation": "getAll", "authentication": "{{ $credentials.oAuth2 }}"}, "credentials": {"mauticOAuth2Api": "OAuth2 Mautic"}, "notesInFlow": false, "typeVersion": 1, "alwaysOutputData": false, "id": "node-72027eef"}, {"name": "Set userFound", "type": "n8n-nodes-base.set", "position": [700, 260], "parameters": {"values": {"string": [{"name": "userFound", "value": "={{$node[\"If not found return -1\"].json[\"id\"]}}"}]}, "options": {}, "keepOnlySet": true}, "typeVersion": 1, "id": "node-f7657e14"}, {"name": "Switch Webhook Types", "type": "n8n-nodes-base.switch", "position": [-70, 450], "parameters": {"rules": {"rules": [{"value2": "User.", "operation": "contains"}, {"output": 1, "value2": "Sale.", "operation": "contains"}]}, "value1": "={{$node[\"Set Webhook Request\"].json[\"type\"]}}", "dataType": "string"}, "typeVersion": 1, "id": "node-53d27675"}, {"name": "Set Webhook Request", "type": "n8n-nodes-base.set", "position": [-310, 450], "parameters": {"values": {"string": [{"name": "student", "value": "={{$node[\"Webhook\"].json[\"body\"][\"object\"]}}"}, {"name": "type", "value": "={{$node[\"Webhook\"].json[\"body\"][\"type\"]}}"}]}, "options": {}, "keepOnlySet": true}, "typeVersion": 1, "id": "node-bf0f164a"}, {"name": "IF NOT userFound", "type": "n8n-nodes-base.if", "position": [1090, 400], "parameters": {"conditions": {"string": [{"value1": "={{$node[\"@MAIN STUDENT DATA\"].json[\"userFound\"]}}", "value2": "-1", "operation": "regex"}]}}, "typeVersion": 1, "id": "node-56ec6298"}, {"name": "Switch User.type", "type": "n8n-nodes-base.switch", "position": [1380, 420], "parameters": {"rules": {"rules": [{"value2": "User.updated"}, {"output": 1, "value2": "User.unsubscribe_from_marketing_emails"}, {"output": 2, "value2": "=User.subscribe_to_marketing_emails"}]}, "value1": "={{$node[\"@MAIN STUDENT DATA\"].json[\"type\"]}}", "dataType": "string"}, "typeVersion": 1, "id": "node-47779f5a"}, {"name": "IF unsubscribe_from_marketing_emails", "type": "n8n-nodes-base.if", "position": [1770, 250], "parameters": {"conditions": {"string": [], "boolean": [{"value1": "={{$node[\"@MAIN STUDENT DATA\"].json[\"student\"][\"unsubscribe_from_marketing_emails\"]}}", "value2": true}]}}, "typeVersion": 1, "id": "node-1da97c49"}, {"id": "error-3edc58bc", "name": "Error Handler", "type": "n8n-nodes-base.stopAndError", "typeVersion": 1, "position": [1000, 400], "parameters": {"message": "Workflow execution error", "options": {}}}], "connections": {}, "name": "Production Workflow", "settings": {"executionOrder": "v1", "saveManualExecutions": true, "callerPolicy": "workflowsFromSameOwner", "errorWorkflow": null, "timezone": "UTC", "executionTimeout": 3600, "maxExecutions": 1000, "retryOnFail": true, "retryCount": 3}, "meta": {"instanceId": "workflow-a158ad65", "versionId": "1.0.0", "createdAt": "2025-09-29T07:07:50.926513", "updatedAt": "2025-09-29T07:07:50.926530", "owner": "n8n-user", "license": "MIT", "category": "automation", "status": "active", "priority": "high", "environment": "production"}, "tags": ["automation", "n8n", "production-ready", "excellent", "optimized"], "description": "Production-ready workflow: Production Workflow. This workflow has been optimized for production use with comprehensive error handling, security, and documentation."}