{ "name": "Newsletter Sync — CRM to Listmonk", "nodes": [ { "parameters": { "rule": { "interval": [ { "triggerAtHour": 6, "triggerAtMinute": 0 } ] } }, "id": "schedule-trigger", "name": "Daily Sync (6 AM)", "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1.2, "position": [240, 300] }, { "parameters": { "method": "GET", "url": "https://crm.cosmolocal.world/api/v1/objects/people", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Authorization", "value": "Bearer {{ $env.TWENTY_API_KEY }}" } ] }, "sendQuery": true, "queryParameters": { "parameters": [ { "name": "limit", "value": "100" } ] }, "options": {} }, "id": "fetch-crm-contacts", "name": "Fetch CRM Contacts", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [460, 300] }, { "parameters": { "fieldToSplitOut": "data.people", "options": {} }, "id": "split-contacts", "name": "Split Into Items", "type": "n8n-nodes-base.splitOut", "typeVersion": 1, "position": [680, 300] }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" }, "conditions": [ { "id": "has-email", "leftValue": "={{ $json.emails?.primaryEmail }}", "rightValue": "", "operator": { "type": "string", "operation": "isNotEmpty" } } ], "combinator": "and" }, "options": {} }, "id": "filter-with-email", "name": "Filter — Has Email", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [900, 300] }, { "parameters": { "method": "GET", "url": "=http://listmonk-cosmolocal:9000/api/subscribers", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Authorization", "value": "Basic {{ Buffer.from($env.LISTMONK_CREDENTIALS || 'admin:changeme').toString('base64') }}" } ] }, "sendQuery": true, "queryParameters": { "parameters": [ { "name": "query", "value": "=subscribers.email = '{{ $json.emails.primaryEmail }}'" }, { "name": "page", "value": "1" }, { "name": "per_page", "value": "1" } ] }, "options": {} }, "id": "check-listmonk-exists", "name": "Check If Subscriber Exists", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [1120, 240] }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" }, "conditions": [ { "id": "not-exists", "leftValue": "={{ $json.data?.total }}", "rightValue": 0, "operator": { "type": "number", "operation": "equals" } } ], "combinator": "and" }, "options": {} }, "id": "if-new-subscriber", "name": "If New Subscriber", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [1340, 240] }, { "parameters": { "method": "POST", "url": "http://listmonk-cosmolocal:9000/api/subscribers", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Authorization", "value": "Basic {{ Buffer.from($env.LISTMONK_CREDENTIALS || 'admin:changeme').toString('base64') }}" }, { "name": "Content-Type", "value": "application/json" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"email\": \"{{ $('Filter — Has Email').item.json.emails.primaryEmail }}\",\n \"name\": \"{{ $('Filter — Has Email').item.json.name?.firstName || '' }} {{ $('Filter — Has Email').item.json.name?.lastName || '' }}\",\n \"status\": \"enabled\",\n \"lists\": [1],\n \"preconfirm_subscriptions\": true,\n \"attribs\": {\n \"source\": \"twenty-crm-sync\",\n \"crm_id\": \"{{ $('Filter — Has Email').item.json.id }}\"\n }\n}", "options": {} }, "id": "create-subscriber", "name": "Create Listmonk Subscriber", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [1560, 180] }, { "parameters": {}, "id": "no-op-exists", "name": "Already Subscribed — Skip", "type": "n8n-nodes-base.noOp", "typeVersion": 1, "position": [1560, 360] } ], "connections": { "Daily Sync (6 AM)": { "main": [ [ { "node": "Fetch CRM Contacts", "type": "main", "index": 0 } ] ] }, "Fetch CRM Contacts": { "main": [ [ { "node": "Split Into Items", "type": "main", "index": 0 } ] ] }, "Split Into Items": { "main": [ [ { "node": "Filter — Has Email", "type": "main", "index": 0 } ] ] }, "Filter — Has Email": { "main": [ [ { "node": "Check If Subscriber Exists", "type": "main", "index": 0 } ], [] ] }, "Check If Subscriber Exists": { "main": [ [ { "node": "If New Subscriber", "type": "main", "index": 0 } ] ] }, "If New Subscriber": { "main": [ [ { "node": "Create Listmonk Subscriber", "type": "main", "index": 0 } ], [ { "node": "Already Subscribed — Skip", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1" }, "staticData": null, "tags": [ { "name": "cosmolocal" }, { "name": "newsletter" } ], "pinData": {} }