{ "name": "Outlevo: Stripe paid invoice to a customer", "nodes": [ { "id": "4867c9cb-02cf-4a6d-b101-ceea201666b0", "name": "How to set it up", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ -40, -360 ], "parameters": { "content": "## How to set it up\n\n**Credentials** (n8n asks for each on first open):\n- **Stripe**: connect your Stripe account.\n- **Outlevo API key**: a Header Auth credential, name `Authorization`, value `Bearer olv_live_…` (Settings → API keys in Outlevo).\n\n**API key scopes**: `companies:read`, `companies:write`.\n\nThen switch the workflow to **Active**.", "height": 300, "width": 620 } }, { "id": "aa70b11f-bcae-45ce-9ad1-0e2470f59b7a", "name": "Invoice paid", "type": "n8n-nodes-base.stripeTrigger", "typeVersion": 1, "position": [ 0, 0 ], "parameters": { "events": [ "invoice.paid" ] }, "webhookId": "e27d28e0-c8c9-44c4-8d11-89e50ec72169", "credentials": { "stripeApi": { "id": "", "name": "Stripe" } } }, { "id": "f83f40ac-c742-4863-b755-d308df9deba6", "name": "Find the domain", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 240, 0 ], "parameters": { "mode": "runOnceForAllItems", "jsCode": "// Finds the company in what the form or tool sent: a website or domain field first, else the domain of a work email\n// (free mail like gmail.com does not name a company). Items without one are skipped.\nconst FREE = new Set(['gmail.com', 'googlemail.com', 'yahoo.com', 'outlook.com', 'hotmail.com', 'live.com', 'msn.com', 'icloud.com', 'me.com', 'aol.com', 'proton.me', 'protonmail.com', 'gmx.com', 'gmx.de', 'mail.com', 'yandex.com', 'yandex.ru', 'mail.ru', 'zoho.com', 'qq.com', '163.com']);\nconst flat = (o, pre = '', out = {}) => { for (const [k, v] of Object.entries(o || {})) { if (v && typeof v === 'object' && !Array.isArray(v)) flat(v, `${pre}${k} `, out); else out[`${pre}${k}`.trim()] = Array.isArray(v) ? v.join(', ') : v; } return out; };\nconst host = (x) => { const m = String(x || '').trim().toLowerCase().match(/^(?:[a-z]+:\\/\\/)?(?:www\\.)?([a-z0-9-]+(?:\\.[a-z0-9-]+)*\\.[a-z]{2,63})(?:[/:?#]|$)/); return m ? m[1] : ''; };\nconst SITE = /website|domain|\\bsite\\b|company.?url/;\nreturn $input.all().flatMap((item) => {\n const f = flat({ email: ((item.json.data || {}).object || {}).customer_email });\n const keys = Object.keys(f);\n const pick = (re, skip) => { const k = keys.find((x) => re.test(x.toLowerCase()) && !(skip && skip.test(x.toLowerCase())) && String(f[x] ?? '').trim()); return k ? String(f[k]).trim() : ''; };\n const email = pick(/e-?mail/);\n const fromEmail = email.includes('@') ? email.split('@').pop().toLowerCase() : '';\n const domain = host(pick(SITE)) || (fromEmail && !FREE.has(fromEmail) ? fromEmail : '');\n if (!domain) return [];\n const out = { domain, ...({}) };\n const company = pick(/company|organi[sz]ation|business/, SITE);\n if (company) out.name = company.slice(0, 200);\n const idKey = keys.find((x) => /^(id|external.?id|crm.?id)$/i.test(x) && String(f[x] ?? '').trim());\n if (idKey) out.external_id = String(f[idKey]).slice(0, 200);\n if (item.json.row_number != null) out.row_number = item.json.row_number;\n return [{ json: out }];\n});\n" } }, { "id": "d67b9369-4d7d-4f3a-afae-a7d01ad3dbc1", "name": "Add to Outlevo", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 480, 0 ], "parameters": { "method": "POST", "url": "=https://api.outlevo.com/v1/companies", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Idempotency-Key", "value": "={{ ('stripe-' + $json.domain).slice(0, 200) }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ domain: $json.domain, ...($json.name ? { name: $json.name } : {}), ...($json.external_id ? { external_id: $json.external_id } : {}), relationship: 'customer' }) }}", "options": { "response": { "response": { "neverError": true, "fullResponse": true } } } }, "credentials": { "httpHeaderAuth": { "id": "", "name": "Outlevo API key (Authorization: Bearer olv_live_…)" } } }, { "id": "d485a789-3a8d-4763-a906-fbf7e25b76c5", "name": "Already there", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 720, 0 ], "parameters": { "mode": "runOnceForAllItems", "jsCode": "// Runs once for all items: a Code node set to run for each item can't skip one.\nreturn $input.all().flatMap((item) => {\n const body = item.json.body || {};\n if (item.json.statusCode === 201) return [];\n if (item.json.statusCode === 409 && body.error && body.error.code === 'COMPANY_EXISTS') return [{ json: { company_id: body.error.details.company_id } }];\n throw new Error(`Outlevo said ${item.json.statusCode}: ${body.error ? body.error.message : 'no body'}`);\n});\n" } }, { "id": "47b86c49-4f32-433c-b73f-a4af9eff6ce3", "name": "Get the company", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 960, 0 ], "parameters": { "method": "GET", "url": "=https://api.outlevo.com/v1/companies/{{ $json.company_id }}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": {} }, "credentials": { "httpHeaderAuth": { "id": "", "name": "Outlevo API key (Authorization: Bearer olv_live_…)" } } }, { "id": "acc8a3d2-5142-461d-a8d5-b8c34c689464", "name": "Should it go up?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 1200, 0 ], "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" }, "conditions": [ { "id": "c0f6f438-34f3-4836-83f7-92e1dd1af9d0", "leftValue": "={{ $json.relationship !== 'customer' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "options": {} } }, { "id": "17407af0-4a22-407f-9f6b-1a5674a9a468", "name": "Mark as customer", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1440, 0 ], "parameters": { "method": "PATCH", "url": "=https://api.outlevo.com/v1/companies/{{ $json.id }}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Idempotency-Key", "value": "={{ ('customer-' + $json.id).slice(0, 200) }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ relationship: 'customer' }) }}", "options": {} }, "credentials": { "httpHeaderAuth": { "id": "", "name": "Outlevo API key (Authorization: Bearer olv_live_…)" } } } ], "connections": { "Invoice paid": { "main": [ [ { "node": "Find the domain", "type": "main", "index": 0 } ] ] }, "Find the domain": { "main": [ [ { "node": "Add to Outlevo", "type": "main", "index": 0 } ] ] }, "Add to Outlevo": { "main": [ [ { "node": "Already there", "type": "main", "index": 0 } ] ] }, "Already there": { "main": [ [ { "node": "Get the company", "type": "main", "index": 0 } ] ] }, "Get the company": { "main": [ [ { "node": "Should it go up?", "type": "main", "index": 0 } ] ] }, "Should it go up?": { "main": [ [ { "node": "Mark as customer", "type": "main", "index": 0 } ], [] ] } }, "settings": { "executionOrder": "v1" }, "pinData": {}, "meta": { "templateCredsSetupCompleted": false } }