{ "name": "Outlevo: Do-not-email list in Google Sheets", "nodes": [ { "id": "5776cb40-e86b-42fd-8646-7620df261696", "name": "How to set it up", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ -40, -628 ], "parameters": { "content": "## How to set it up\n\n**Credentials** (n8n asks for each on first open):\n- **Outlevo webhook signing secret**: a Crypto credential; paste the `secret` Outlevo returns when you register the webhook (below) as its secret.\n- **Outlevo API key**: a Header Auth credential, name `Authorization`, value `Bearer olv_live_…` (Settings → API keys in Outlevo).\n- **Google Sheets**: connect your Google Sheets account.\n\n**API key scopes**: `contacts:read`.\n\n**Replace**: `YOUR_SHEET_ID`.\n\n**Register the webhook** (needs a key with `webhooks:manage`): copy the Production URL of the **Outlevo webhook** node, then:\n```\ncurl -X POST https://api.outlevo.com/v1/webhooks \\\n -H \"Authorization: Bearer $OUTLEVO_KEY\" \\\n -H \"Idempotency-Key: $(uuidgen)\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\"url\": \"\", \"events\": [\"lead.bounced\",\"lead.unsubscribed\"]}'\n```\nPut the `secret` from the answer into the Crypto credential.\n\n**Columns in the \"Do not email\" sheet** (first row): `At`, `Why`, `Email`, `Person`, `Contact id`, `Campaign id`.\n\nThen switch the workflow to **Active**.", "height": 568, "width": 620 } }, { "id": "b54dcedd-ef82-4c1a-a84f-9a9d81697de0", "name": "Outlevo webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 2, "position": [ 0, 0 ], "parameters": { "httpMethod": "POST", "path": "outlevo-bounces-unsubscribes-to-sheet", "responseMode": "onReceived", "options": { "rawBody": true } }, "webhookId": "988635c3-453c-4a3b-9719-15022a7e8af4" }, { "id": "1ab46df7-ffd1-4ce6-b8eb-80e792ff3f9d", "name": "Read the body", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 240, 0 ], "parameters": { "mode": "runOnceForAllItems", "jsCode": "// Outlevo signs every delivery: Outlevo-Signature: t=,v1=.\n// This node reads the raw body and the header; the Crypto node signs the same text with your secret; the next node compares.\nconst item = $input.first();\nconst raw = (await this.helpers.getBinaryDataBuffer(0, 'data')).toString('utf8');\nconst header = String((item.json.headers || {})['outlevo-signature'] || '');\nconst parts = header.split(',').map((kv) => kv.trim().split('='));\nconst t = Number((parts.find(([k]) => k === 't') || [])[1]) || 0;\nconst sigs = parts.filter(([k]) => k === 'v1').map(([, v]) => v || '');\nreturn [{ json: { raw, t, sigs, signed: `${t}.${raw}` } }];\n" } }, { "id": "851bcf94-66d7-4c2f-9e47-7bf341c4f608", "name": "Sign with your secret", "type": "n8n-nodes-base.crypto", "typeVersion": 2, "position": [ 480, 0 ], "parameters": { "action": "hmac", "type": "SHA256", "value": "={{ $json.signed }}", "dataPropertyName": "hmac", "encoding": "hex" }, "credentials": { "crypto": { "id": "", "name": "Outlevo webhook signing secret" } } }, { "id": "a0be4ad1-8313-4808-8df7-f903e7ef35cf", "name": "Check signature", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 720, 0 ], "parameters": { "mode": "runOnceForAllItems", "jsCode": "// Accept the event only if a v1 signature equals the HMAC and it was signed in the last 5 minutes; anything else stops here.\nconst { raw, t, sigs, hmac } = $input.first().json;\nconst same = (a, b) => { if (typeof a !== 'string' || a.length !== b.length) return false; let d = 0; for (let i = 0; i < a.length; i++) d |= a.charCodeAt(i) ^ b.charCodeAt(i); return d === 0; };\nif (!t || Math.abs(Date.now() / 1000 - t) > 300 || !sigs.some((s) => same(s, hmac))) throw new Error('Outlevo signature did not verify');\nconst event = JSON.parse(raw);\nreturn [{ json: { ...event.data, event_id: event.id, event: event.type, created_at: event.created_at } }];\n" } }, { "id": "84fc9b68-d115-47c5-81a2-956417a44b80", "name": "Bounce or unsubscribe?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 960, 0 ], "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" }, "conditions": [ { "id": "5b072931-e374-49b7-aa03-681a39463752", "leftValue": "={{ ['lead.bounced','lead.unsubscribed'].includes($json.event) }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "options": {} } }, { "id": "6175ab04-a7be-446d-9e1c-460f364b96e3", "name": "Get the contact", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1200, 0 ], "parameters": { "method": "GET", "url": "=https://api.outlevo.com/v1/contacts/{{ $('Bounce or unsubscribe?').item.json.contact_id || 'none' }}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": { "response": { "response": { "neverError": true } } } }, "credentials": { "httpHeaderAuth": { "id": "", "name": "Outlevo API key (Authorization: Bearer olv_live_…)" } } }, { "id": "a50c93b1-391a-4df2-bfbd-d160a13470a4", "name": "Write the row", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1440, 0 ], "parameters": { "mode": "runOnceForAllItems", "jsCode": "// Soft bounces are left out: the address may work tomorrow.\nconst ev = $('Bounce or unsubscribe?').first().json;\nconst c = $('Get the contact').first().json;\nconst s = (v) => (v == null ? '' : typeof v === 'string' ? v : typeof v === 'object' ? JSON.stringify(v) : String(v));\nconst person = (c) => [c.first_name, c.last_name].filter(Boolean).join(' ');\nconst when = (d) => (d ? new Date(d).toUTCString().replace(/:\\d\\d GMT$/, ' UTC') : '');\nif (ev.event === 'lead.bounced' && ev.hard === false) return [];\nconst rows = [{ At: s(ev.at || ev.created_at), Why: ev.event === 'lead.unsubscribed' ? 'Unsubscribed' : 'Hard bounce', Email: s(c.email), Person: person(c), 'Contact id': s(ev.contact_id), 'Campaign id': s(ev.campaign_id) }];\nreturn rows.map((r) => ({ json: r }));\n" } }, { "id": "7a36712f-7b4a-4cf7-b3e4-830b3f5fc3c3", "name": "Add to the sheet", "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.5, "position": [ 1680, 0 ], "parameters": { "operation": "append", "documentId": { "__rl": true, "mode": "url", "value": "https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/edit" }, "sheetName": { "__rl": true, "mode": "name", "value": "Do not email" }, "columns": { "mappingMode": "autoMapInputData", "value": {}, "matchingColumns": [], "schema": [] }, "options": {} }, "credentials": { "googleSheetsOAuth2Api": { "id": "", "name": "Google Sheets" } } } ], "connections": { "Outlevo webhook": { "main": [ [ { "node": "Read the body", "type": "main", "index": 0 } ] ] }, "Read the body": { "main": [ [ { "node": "Sign with your secret", "type": "main", "index": 0 } ] ] }, "Sign with your secret": { "main": [ [ { "node": "Check signature", "type": "main", "index": 0 } ] ] }, "Check signature": { "main": [ [ { "node": "Bounce or unsubscribe?", "type": "main", "index": 0 } ] ] }, "Bounce or unsubscribe?": { "main": [ [ { "node": "Get the contact", "type": "main", "index": 0 } ], [] ] }, "Get the contact": { "main": [ [ { "node": "Write the row", "type": "main", "index": 0 } ] ] }, "Write the row": { "main": [ [ { "node": "Add to the sheet", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1" }, "pinData": {}, "meta": { "templateCredsSetupCompleted": false } }