{ "nodes": [ { "parameters": { "pollTimes": { "item": [ { "mode": "everyMinute" } ] }, "documentId": { "__rl": true, "value": "1udZ65_L2Hf79RxvUn7NY9SMsninRzr6UHE3RW5nRQ2U", "mode": "list" }, "sheetName": { "__rl": true, "value": 1392151344, "mode": "list" }, "options": {} }, "id": "sheet-trigger-1", "name": "SalonTrigger", "type": "n8n-nodes-base.googleSheetsTrigger", "typeVersion": 1, "position": [ 0, -96 ], "credentials": { "googleSheetsTriggerOAuth2Api": { "id": "qruBDoP6sPGfIyzX", "name": "Google Sheets Trigger account" } } }, { "parameters": { "pollTimes": { "item": [ { "mode": "everyMinute" } ] }, "documentId": { "__rl": true, "value": "1dljqIuz_i7WxQ39ykymY6xsujC0dzwJLvvJGcmMAJzA", "mode": "list" }, "sheetName": { "__rl": true, "value": 1392151344, "mode": "list" }, "options": {} }, "id": "sheet-trigger-2", "name": "ClinicTrigger", "type": "n8n-nodes-base.googleSheetsTrigger", "typeVersion": 1, "position": [ 0, 112 ], "credentials": { "googleSheetsTriggerOAuth2Api": { "id": "qruBDoP6sPGfIyzX", "name": "Google Sheets Trigger account" } } }, { "parameters": { "jsCode": "const items = $input.all();const validItems = [];for (let item of items) { let phone = item.json['Phone'] || ''; let salon = item.json['SalonName'] || ''; let clinic = item.json['ClinicName'] || ''; let intention = item.json['IntentionLevel'] || ''; if (!phone.trim() && !salon.trim() && !clinic.trim()) continue; if (intention !== 'RequestDocs' && intention !== 'SendDocs' && intention !== 'G') continue; let clean = phone.replace(/[^0-9]/g, ''); let company = salon || clinic || 'Unknown'; validItems.push({ json: { ...item.json, formatted_phone: clean, unified_company: company, unified_lastName: (item.json['LastName'] || '').trim() || 'Manager', unified_firstName: (item.json['FirstName'] || '').trim() || '', unified_email: (item.json['Email'] || '').trim() || '', unified_zip: (item.json['Zip'] || '').trim() || '', unified_addr: (item.json['Address'] || '').trim() || '', unified_todo: 'Intention: ' + intention, unified_state: item.json['State'] || '', unified_city: item.json['City'] || '' } });}return validItems;" }, "id": "data-format", "name": "DataFormat", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 256, 0 ] }, { "parameters": { "operation": "getAll", "returnAll": true, "options": { "conditionsUi": { "conditionValues": [ { "field": "campaign__c", "value": "TargetCampaign" } ] } } }, "id": "sf-fetch-campaign", "name": "SFFetchCampaign", "type": "n8n-nodes-base.salesforce", "typeVersion": 1, "position": [ 480, 0 ], "credentials": { "salesforceOAuth2Api": { "id": "VWs1rwBJyiCM1cYc", "name": "Salesforce account" } } }, { "parameters": { "jsCode": "const sheetItem = $(\"DataFormat\").item.json;const sfLeads = $input.all();let matchFound = false;let targetLeadId = null;for (let lead of sfLeads) { const sfEmail = lead.json.Email || ''; const sfPhone = lead.json.Phone || ''; if ((sheetItem.unified_email && sheetItem.unified_email === sfEmail) || (sheetItem.formatted_phone && sheetItem.formatted_phone === sfPhone)) { matchFound = true; targetLeadId = lead.json.Id; break; }}return [{ json: { ...sheetItem, matchFound: matchFound, targetLeadId: targetLeadId } }];" }, "id": "safe-join-check", "name": "SafeJoinCheck", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 704, 0 ] }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 2 }, "conditions": [ { "id": "is-match", "leftValue": "={{ $json.matchFound }}", "rightValue": "true", "operator": { "type": "boolean", "operation": "true" } } ], "combinator": "and" }, "options": {} }, "id": "check-match", "name": "IsMatch", "type": "n8n-nodes-base.if", "typeVersion": 2.2, "position": [ 928, 0 ] }, { "parameters": { "operation": "update", "leadId": "={{ $json.targetLeadId }}", "updateFields": { "email": "={{ $json.unified_email }}", "postalCode": "={{ $json.unified_zip }}", "street": "={{ $json.unified_addr }}" } }, "id": "sf-update-safe", "name": "SFUpdate", "type": "n8n-nodes-base.salesforce", "typeVersion": 1, "position": [ 1152, -96 ], "credentials": { "salesforceOAuth2Api": { "id": "VWs1rwBJyiCM1cYc", "name": "Salesforce account" } } }, { "parameters": { "company": "={{ $json.unified_company }}", "lastname": "={{ $json.unified_lastName }}", "additionalFields": { "city": "={{ $json.unified_city }}", "email": "={{ $json.unified_email }}", "phone": "={{ $json.formatted_phone }}", "postalCode": "={{ $json.unified_zip }}", "state": "={{ $json.unified_state }}", "street": "={{ $json.unified_addr }}" } }, "id": "sf-create-safe", "name": "SFCreate", "type": "n8n-nodes-base.salesforce", "typeVersion": 1, "position": [ 1152, 112 ], "credentials": { "salesforceOAuth2Api": { "id": "VWs1rwBJyiCM1cYc", "name": "Salesforce account" } } }, { "parameters": { "operation": "addToCampaign", "leadId": "={{ $json.targetLeadId || $json.id }}", "campaignId": "701RB00001FY6jOYAT", "options": {} }, "id": "sf-campaign-final", "name": "SFCampaignFinal", "type": "n8n-nodes-base.salesforce", "typeVersion": 1, "position": [ 1504, 0 ], "credentials": { "salesforceOAuth2Api": { "id": "VWs1rwBJyiCM1cYc", "name": "Salesforce account" } }, "continueOnFail": true }, { "parameters": {}, "type": "n8n-nodes-base.merge", "typeVersion": 3.2, "position": [ 1344, 0 ], "id": "merge-results", "name": "MergeResults" } ], "connections": { "SalonTrigger": { "main": [ [ { "node": "DataFormat", "type": "main", "index": 0 } ] ] }, "ClinicTrigger": { "main": [ [ { "node": "DataFormat", "type": "main", "index": 0 } ] ] }, "DataFormat": { "main": [ [ { "node": "SFFetchCampaign", "type": "main", "index": 0 } ] ] }, "SFFetchCampaign": { "main": [ [ { "node": "SafeJoinCheck", "type": "main", "index": 0 } ] ] }, "SafeJoinCheck": { "main": [ [ { "node": "IsMatch", "type": "main", "index": 0 } ] ] }, "IsMatch": { "main": [ [ { "node": "SFUpdate", "type": "main", "index": 0 } ], [ { "node": "SFCreate", "type": "main", "index": 0 } ] ] }, "SFUpdate": { "main": [ [ { "node": "MergeResults", "type": "main", "index": 0 } ] ] }, "SFCreate": { "main": [ [ { "node": "MergeResults", "type": "main", "index": 1 } ] ] }, "MergeResults": { "main": [ [ { "node": "SFCampaignFinal", "type": "main", "index": 0 } ] ] } } }