{ "name": "Outlevo: Competitor changes log in Notion", "nodes": [ { "id": "d2e09aa9-d278-47e6-b337-6117256620b0", "name": "How to set it up", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ -40, -650 ], "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- **Notion**: connect your Notion account.\n\n**API key scopes**: `companies:read`.\n\n**Pick in the node**:\n- **Add to Notion**: the database\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\": [\"competitor.changed\"]}'\n```\nPut the `secret` from the answer into the Crypto credential.\n\nThe Notion database needs only its title property; the details go in the page.\n\nThen switch the workflow to **Active**.", "height": 590, "width": 620 } }, { "id": "b3091d94-5c06-4661-a82c-a42b44b531e6", "name": "Outlevo webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 2, "position": [ 0, 0 ], "parameters": { "httpMethod": "POST", "path": "outlevo-competitor-change-to-notion", "responseMode": "onReceived", "options": { "rawBody": true } }, "webhookId": "30f7212d-b490-42d0-afb6-db4face062ee" }, { "id": "cb47de59-99a7-4ec1-8ad2-5bbec2d6746c", "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": "25fc1144-4149-4936-a62e-68a3559fb237", "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": "c31dae45-fb8c-4721-8ec2-9a9328718a8d", "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": "f88ceda0-3c85-4dc0-afe3-23ebeaa7dbf3", "name": "Competitor changed?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 960, 0 ], "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" }, "conditions": [ { "id": "8bebca7e-2b28-47ca-8fe1-36004f078679", "leftValue": "={{ $json.event }}", "rightValue": "competitor.changed", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} } }, { "id": "05cad3e7-d22a-41c6-ae18-5f014f0a399d", "name": "Get the competitor", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1200, 0 ], "parameters": { "method": "GET", "url": "=https://api.outlevo.com/v1/competitors/{{ $('Competitor changed?').item.json.competitor_id }}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": {} }, "credentials": { "httpHeaderAuth": { "id": "", "name": "Outlevo API key (Authorization: Bearer olv_live_…)" } } }, { "id": "165cd5af-c7a6-427a-99ac-1c5d92aef325", "name": "Write the row", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1440, 0 ], "parameters": { "mode": "runOnceForAllItems", "jsCode": "const ev = $('Competitor changed?').first().json;\nconst cp = $('Get the competitor').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') : '');\nconst n = ev.changes || 1;\nconst list = [...(cp.changes || [])].sort((a, b) => String(b.detected_at).localeCompare(String(a.detected_at))).slice(0, n);\nconst rows = list.map((c) => ({ Detected: s(c.detected_at), Competitor: s(cp.name || cp.domain), Domain: s(cp.domain || ev.domain), Field: s(c.field), Was: s(c.from_value), Now: s(c.to_value), Page: s(c.to_url || c.from_url), Link: `https://app.outlevo.com/competitors/${cp.link_id}` }));\nreturn rows.map((r) => ({ json: { title: String(`${r.Competitor}: ${r.Field}`).slice(0, 200), body: Object.entries(r).filter(([, v]) => v !== '').map(([k, v]) => `${k}: ${v}`).join('\\n').slice(0, 1900) } }));\n" } }, { "id": "0e035b9a-8b0b-4d12-a0ac-a5d9d1c8b6b1", "name": "Add to Notion", "type": "n8n-nodes-base.notion", "typeVersion": 2.2, "position": [ 1680, 0 ], "parameters": { "resource": "databasePage", "operation": "create", "databaseId": { "__rl": true, "mode": "list", "value": "" }, "title": "={{ $json.title }}", "blockUi": { "blockValues": [ { "type": "paragraph", "textContent": "={{ $json.body }}" } ] }, "options": {} }, "credentials": { "notionApi": { "id": "", "name": "Notion" } } } ], "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": "Competitor changed?", "type": "main", "index": 0 } ] ] }, "Competitor changed?": { "main": [ [ { "node": "Get the competitor", "type": "main", "index": 0 } ], [] ] }, "Get the competitor": { "main": [ [ { "node": "Write the row", "type": "main", "index": 0 } ] ] }, "Write the row": { "main": [ [ { "node": "Add to Notion", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1" }, "pinData": {}, "meta": { "templateCredsSetupCompleted": false } }