Task: Kunai-Metrics-Webflow-Old

n8n workflow:
{"id":1053,"name":"Lever: Handle Candidate Stage Change","nodes":[{"name":"Lever Webhook","type":"n8n-nodes-base.webhook","position":[130,470],"webhookId":"0cfb248e-3e84-4dfe-94f7-f5b301327b36","parameters":{"path":"lever-candidate-event","options":{},"httpMethod":"POST","responseMode":"responseNode"},"typeVersion":1},{"name":"Verify Webhook","type":"n8n-nodes-base.functionItem","position":[350,470],"parameters":{"functionCode":"const crypto = require('crypto');\n\nfunction getSignatureToken(event) {\n\n  switch (event) {\n    case \"candidateStageChange\":\n      return \"3c91ea8a354830200bd337ee058ae1d157fa62ceff035ad8\";\n    case \"candidateArchiveChange\":\n      return \"64068da6ef2744c2253ce4f7ceb701c1d77a666222595439\";\n    case \"candidateHired\":\n      return \"a8a7bfdd0532867d86b280ca87a16c13a93aa687dfd8e994\";\n    case \"candidateDeleted\":\n      return \"e81711860cb01d0a38e393e9c2f78a61cf9460ee1af79dde\"\n    default:\n      return \"\";\n  }\n\n}\n\n\nfunction validateWebhook(token, triggeredAt, signature, event) {\n  var plainText = token + triggeredAt\n  var hash = crypto.createHmac('sha256', getSignatureToken(event))\n  hash.update(plainText)\n  hash = hash.digest('hex')\n  return signature === hash\n}\n\nitem.verified = validateWebhook(item.body.token, item.body.triggeredAt, item.body.signature, item.body.event);\n\nreturn item;"},"typeVersion":1},{"name":"IF Verified","type":"n8n-nodes-base.if","position":[560,470],"parameters":{},"typeVersion":1},{"name":"Handle Bad Webhook","type":"n8n-nodes-base.noOp","position":[790,800],"parameters":{},"typeVersion":1},{"name":"Route by Type","type":"n8n-nodes-base.switch","position":[920,210],"parameters":{"rules":{"rules":[{"value2":"candidateStageChange"},{"output":1,"value2":"candidateArchiveChange"},{"output":2,"value2":"candidateHired"},{"output":3,"value2":"candidateDeleted"}]},"value1":"={{$json.body.event}}","dataType":"string"},"typeVersion":1},{"name":"Handle Deleted","type":"n8n-nodes-base.noOp","position":[1150,510],"parameters":{},"typeVersion":1},{"name":"Handle Hired","type":"n8n-nodes-base.noOp","position":[1150,360],"parameters":{},"typeVersion":1},{"name":"Handle Archive","type":"n8n-nodes-base.noOp","position":[1150,200],"parameters":{},"typeVersion":1},{"name":"Handle Stage Change","type":"n8n-nodes-base.noOp","position":[1140,0],"parameters":{},"typeVersion":1},{"name":"Get Opportunity","type":"n8n-nodes-base.httpRequest","position":[1540,-20],"parameters":{"url":"=https://api.lever.co/v1/opportunities/{{$node[\"IF Handled Stage\"].json[\"body\"][\"data\"][\"opportunityId\"]}}","options":{},"authentication":"basicAuth","queryParametersUi":{"parameter":[{"name":"expand","value":"stage"},{"name":"expand","value":"applications"},{"name":"expand","value":"owner"},{"name":"expand","value":"sourcedBy"}]}},"credentials":{"httpBasicAuth":{"id":"18","name":"Kunai Lever Full Access"}},"typeVersion":1},{"name":"Route by New Stage","type":"n8n-nodes-base.switch","position":[2420,-40],"parameters":{"rules":{"rules":[{"value2":"c7131fa5-7ddd-443d-afbf-0a8df8458b71"},{"output":1,"value2":"af784ffd-b997-4411-9b9f-cad9a22f29a8"},{"output":2,"value2":"34114c9f-eb9f-473a-90e3-d8243774ea3e"}]},"value1":"={{$json[\"stage-id\"]}}","dataType":"string","fallbackOutput":3},"typeVersion":1},{"name":"Present to Client","type":"n8n-nodes-base.noOp","position":[2940,-440],"parameters":{},"typeVersion":1},{"name":"Prep for Client","type":"n8n-nodes-base.noOp","position":[2700,-60],"parameters":{},"typeVersion":1},{"name":"Other Stage","type":"n8n-nodes-base.noOp","position":[2680,560],"parameters":{},"typeVersion":1},{"name":"Unify Params","type":"n8n-nodes-base.set","position":[1720,-20],"parameters":{"values":{"number":[{"name":"candidate-last-advanced-at","value":"={{ $node[\"Get Opportunity\"].json[\"data\"][\"lastAdvancedAt\"] }}"}],"string":[{"name":"opportunity-id","value":"={{$node[\"Get Opportunity\"].json[\"data\"][\"id\"]}}"},{"name":"posting-id","value":"={{$json[\"data\"][\"applications\"][0][\"posting\"]}}"},{"name":"stage-id","value":"={{$node[\"Get Opportunity\"].json[\"data\"][\"stage\"][\"id\"]}}"},{"name":"candidate-name","value":"={{$node[\"Get Opportunity\"].json[\"data\"][\"name\"]}}"},{"name":"candidate-contact-id","value":"={{$node[\"Get Opportunity\"].json[\"data\"][\"contact\"]}}"},{"name":"candidate-email","value":"={{$json[\"data\"][\"emails\"][0]}}"},{"name":"candidate-owner-id","value":"={{ $json[\"data\"][\"owner\"][\"id\"] }}"},{"name":"candidate-sourced-by","value":"={{ $json[\"data\"][\"sourcedBy\"][\"id\"] }}"}]},"options":{},"keepOnlySet":true},"typeVersion":1},{"name":"Advance to HM Screen","type":"n8n-nodes-base.httpRequest","position":[4060,-680],"parameters":{"url":"=https://api.lever.co/v1/opportunities/{{$node[\"Present to Client\"].json[\"opportunity-id\"]}}/stage","options":{},"requestMethod":"PUT","authentication":"basicAuth","bodyParametersUi":{"parameter":[{"name":"stage","value":"359fba80-442c-4731-9dd0-5d266544e620"}]}},"credentials":{"httpBasicAuth":{"id":"18","name":"Kunai Lever Full Access"}},"typeVersion":1},{"name":"IF Kunai PtC","type":"n8n-nodes-base.if","position":[3460,-440],"parameters":{"conditions":{"string":[{"value1":"={{ $json[\"data\"][\"categories\"][\"location\"] }}","value2":"Oakland, CA","operation":"contains"}]}},"typeVersion":1},{"name":"IF Kunai PfC","type":"n8n-nodes-base.if","position":[3960,80],"parameters":{"conditions":{"string":[{"value1":"={{ $json[\"data\"][\"categories\"][\"location\"] }}","value2":"Oakland, CA"}]}},"typeVersion":1},{"name":"Note: Advanced to Team Interview","type":"n8n-nodes-base.httpRequest","position":[3180,-60],"parameters":{"url":"=https://api.lever.co/v1/opportunities/{{$json[\"data\"][\"id\"]}}/notes","options":{},"requestMethod":"POST","authentication":"basicAuth","bodyParametersUi":{"parameter":[{"name":"value","value":"Applicant for Kunai role was moved to \"Prep for Client\" stage. Application has been automatically advanced to \"Team Interview\" stage. No email address was created."},{"name":"notifyFollowers","value":"={{true}}"}]}},"credentials":{"httpBasicAuth":{"id":"18","name":"Kunai Lever Full Access"}},"typeVersion":1},{"name":"Note: Advanced to HM Screen","type":"n8n-nodes-base.httpRequest","position":[4280,-680],"parameters":{"url":"=https://api.lever.co/v1/opportunities/{{$json[\"data\"][\"id\"]}}/notes","options":{},"requestMethod":"POST","authentication":"basicAuth","bodyParametersUi":{"parameter":[{"name":"value","value":"Applicant for Kunai role was moved to \"Present to Client\" stage. Application has been automatically advanced to \"Hiring Manager Screen\" stage."},{"name":"notifyFollowers","value":"={{true}}"}]}},"credentials":{"httpBasicAuth":{"id":"18","name":"Kunai Lever Full Access"}},"typeVersion":1},{"name":"Respond 200","type":"n8n-nodes-base.respondToWebhook","position":[870,450],"parameters":{"options":{"responseCode":200},"respondWith":"text","responseBody":"=Webhook received and authenticated. Initiated Worflow Execution ID: {{$executionId}}."},"typeVersion":1},{"name":"Respond 401","type":"n8n-nodes-base.respondToWebhook","position":[990,800],"parameters":{"options":{"responseCode":401},"respondWith":"text","responseBody":"Webhook received. Authentication failed."},"typeVersion":1},{"name":"Update Pre-Sub Tracker","type":"n8n-nodes-base.noOp","position":[3900,-420],"parameters":{},"typeVersion":1},{"name":"Get Notion Job","type":"n8n-nodes-base.notion","position":[4120,-420],"parameters":{"options":{"filter":{"singleCondition":{"key":"Lever Posting ID|rich_text","condition":"equals","richTextValue":"={{$node[\"Present to Client\"].json[\"posting-id\"]}}"}}},"resource":"databasePage","operation":"getAll","databaseId":"4cd53a7a-5d52-438c-b807-1b4ba1d4c6ff"},"credentials":{"notionApi":{"id":"3","name":"Kunai Staffing n8n Key"}},"typeVersion":1},{"name":"IF Pre-Sub Exists","type":"n8n-nodes-base.if","position":[4620,-420],"parameters":{"conditions":{"boolean":[{"value1":"={{$json[\"id\"].length > 0}}","value2":true}]}},"typeVersion":1},{"name":"Create Pre-Sub","type":"n8n-nodes-base.notion","position":[4960,-400],"parameters":{"resource":"databasePage","databaseId":"fa05d118-5e22-418e-b7c8-c509dbe5fe82","propertiesUi":{"propertyValues":[{"key":"Candidate Name|title","title":"={{$node[\"Get Opportunity\"].json[\"data\"][\"name\"]}}"},{"key":"Lever Opportunity ID|rich_text","textContent":"={{$node[\"Get Opportunity\"].json[\"data\"][\"id\"]}}"},{"key":"Job|relation","relationValue":["={{$node[\"Get Notion Job\"].json[\"id\"]}}"]},{"key":"Original Resume|url","urlValue":"=https://hire.lever.co/candidates/{{$node[\"Lever Webhook\"].json[\"body\"][\"data\"][\"candidateId\"]}}"}]}},"credentials":{"notionApi":{"id":"3","name":"Kunai Staffing n8n Key"}},"typeVersion":1},{"name":"Auto Advance to Team Interview","type":"n8n-nodes-base.httpRequest","position":[2960,-60],"parameters":{"url":"=https://api.lever.co/v1/opportunities/{{$node[\"Prep for Client\"].json[\"opportunity-id\"]}}/stage","options":{},"requestMethod":"PUT","authentication":"basicAuth","bodyParametersUi":{"parameter":[{"name":"stage","value":"0401bad9-a8ab-4025-b103-bf5279fdf6a9"}]}},"credentials":{"httpBasicAuth":{"id":"18","name":"Kunai Lever Full Access"}},"typeVersion":1},{"name":"Get Posting - Present","type":"n8n-nodes-base.httpRequest","position":[3120,-440],"parameters":{"url":"=https://api.lever.co/v1/postings/{{$json[\"posting-id\"]}}","options":{},"authentication":"basicAuth"},"credentials":{"httpBasicAuth":{"id":"18","name":"Kunai Lever Full Access"}},"typeVersion":1},{"name":"IF No Reqs - Present","type":"n8n-nodes-base.if","position":[3200,-940],"parameters":{"conditions":{"boolean":[{"value1":"={{$json[\"data\"][\"requisitionCodes\"].length === 0}}","value2":true}]}},"typeVersion":1},{"name":"Handle 0 Reqs - Present","type":"n8n-nodes-base.noOp","position":[3420,-1160],"parameters":{},"typeVersion":1},{"name":"Use 1st Req  - Present","type":"n8n-nodes-base.noOp","position":[3420,-920],"parameters":{},"typeVersion":1},{"name":"Get Posting - Prep","type":"n8n-nodes-base.httpRequest","position":[3780,80],"parameters":{"url":"=https://api.lever.co/v1/postings/{{$json[\"posting-id\"]}}","options":{},"authentication":"basicAuth"},"credentials":{"httpBasicAuth":{"id":"18","name":"Kunai Lever Full Access"}},"typeVersion":1},{"name":"IF No Reqs - Prep","type":"n8n-nodes-base.if","position":[3280,1260],"parameters":{"conditions":{"boolean":[{"value1":"={{$json[\"data\"][\"requisitionCodes\"].length === 0}}","value2":true}]}},"typeVersion":1},{"name":"Handle 0 Reqs - Prep","type":"n8n-nodes-base.noOp","position":[3520,1080],"parameters":{},"typeVersion":1},{"name":"Use 1st Req - Prep","type":"n8n-nodes-base.noOp","position":[3520,1280],"parameters":{},"typeVersion":1},{"name":"Get Req 0 - Prep","type":"n8n-nodes-base.httpRequest","position":[3740,1280],"parameters":{"url":"https://api.lever.co/v1/requisitions","options":{},"authentication":"basicAuth","queryParametersUi":{"parameter":[{"name":"requisition_code","value":"={{$json[\"data\"][\"requisitionCodes\"][0]}}"}]}},"credentials":{"httpBasicAuth":{"id":"18","name":"Kunai Lever Full Access"}},"typeVersion":1},{"name":"Get Req 0  - Present","type":"n8n-nodes-base.httpRequest","position":[3640,-920],"parameters":{"url":"https://api.lever.co/v1/requisitions","options":{},"authentication":"basicAuth","queryParametersUi":{"parameter":[{"name":"requisition_code","value":"={{$json[\"data\"][\"requisitionCodes\"][0]}}"}]}},"credentials":{"httpBasicAuth":{"id":"18","name":"Kunai Lever Full Access"}},"typeVersion":1},{"name":"IF Handled Stage","type":"n8n-nodes-base.if","position":[1360,0],"parameters":{"conditions":{"string":[{"value1":"={{$json[\"body\"][\"data\"][\"toStageId\"]}}","value2":"359fba80-442c-4731-9dd0-5d266544e620"},{"value1":"={{$json[\"body\"][\"data\"][\"toStageId\"]}}","value2":"0401bad9-a8ab-4025-b103-bf5279fdf6a9"},{"value1":"={{$json[\"body\"][\"data\"][\"toStageId\"]}}","value2":"offer"},{"value1":"={{$json[\"body\"][\"data\"][\"toStageId\"]}}","value2":"c7131fa5-7ddd-443d-afbf-0a8df8458b71"},{"value1":"={{$json[\"body\"][\"data\"][\"toStageId\"]}}","value2":"af784ffd-b997-4411-9b9f-cad9a22f29a8"},{"value1":"={{$json[\"body\"][\"data\"][\"toStageId\"]}}","value2":"34114c9f-eb9f-473a-90e3-d8243774ea3e"}]},"combineOperation":"any"},"typeVersion":1},{"name":"Get Candidate Record","type":"n8n-nodes-base.notion","position":[2880,660],"parameters":{"options":{"filter":{"singleCondition":{"key":"Lever Opportunity|rich_text","condition":"equals","richTextValue":"={{$json[\"opportunity-id\"]}}"}}},"resource":"databasePage","operation":"getAll","returnAll":true,"databaseId":"92246292-d3fe-40ed-9945-2d46e361f9bf"},"credentials":{"notionApi":{"id":"3","name":"Kunai Staffing n8n Key"}},"typeVersion":1,"alwaysOutputData":true},{"name":"Set Notion Data","type":"n8n-nodes-base.set","position":[3040,660],"parameters":{"values":{"string":[{"name":"notion-page-id","value":"={{$json.id}}"},{"name":"notion-lever-opportunity-id","value":"={{$json[\"Lever Opportunity\"]}}"}]},"options":{},"keepOnlySet":true},"typeVersion":1},{"name":"Set Empty Notion ID","type":"n8n-nodes-base.set","position":[2880,500],"parameters":{"values":{"string":[{"name":"notion-page-id"}]},"options":{}},"typeVersion":1},{"name":"Merge from Notion","type":"n8n-nodes-base.merge","position":[3220,520],"parameters":{"mode":"mergeByKey","overwrite":"blank","propertyName1":"opportunity-id","propertyName2":"notion-lever-opportunity-id"},"typeVersion":1},{"name":"Create Notion Payload","type":"n8n-nodes-base.functionItem","position":[3440,520],"parameters":{"functionCode":"var notionObject = {\n        \"page\": \"\",\n        \"parent\": {\n          \"database_id\": \"92246292d3fe40ed99452d46e361f9bf\"\n        },\n        \"properties\": {\n            \"Name\": {\n                \"type\": \"title\",\n                \"title\": [\n                    {\n                        \"type\": \"text\",\n                        \"text\": {\n                            \"content\": $json[\"candidate-name\"]\n                        }\n                    }\n                ]\n            },\n            // \"Current Status\": {\n            //     \"type\": \"select\",\n            //     \"select\": {\n            //         \"name\": $json[\"job_stage\"]\n            //     }\n            // },\n            // \"Phone\": {\n            //     \"type\": \"phone_number\",\n            //     \"phone_number\": $json[\"candidate_phone\"]\n            // },\n            \"Email\": {\n                \"type\": \"email\",\n                \"email\": $json[\"candidate-email\"]\n            },\n            // \"Jazz URL\": {\n            //     \"type\": \"url\",\n            //     \"url\": $json[\"candidate_jazz_url\"]\n            // }\n        }\n};\n\nif ($json[\"candidate-sourced-by\"]) {\n  notionObject.properties[\"Original Source\"] = {\n    \"type\": \"select\",\n        \"select\": {\n          \"name\": $json[\"candidate-sourced-by\"]\n        }\n    }\n}\n\n//If Updating an existing Notion Page\nif ($json[\"notion-page-id\"].length > 0) {\n    notionObject.page = $json[\"notion-page-id\"]\n} else {\n    notionObject.properties[\"Lever Opportunity\"] = {\n        \"type\": \"rich_text\",\n        \"rich_text\": [\n            {\n                \"type\": \"text\",\n                \"text\": {\n                    \"content\": $json[\"opportunity-id\"]\n                }\n            }\n        ]\n    }\n}\n\nnotionObject.properties[\"Last Change\"] = {\n    type: \"date\",\n    date: {\n        start: new Date($json[\"candidate-last-advanced-at\"]).toISOString()\n    }\n}\n\n//TO DO: SET JOB RELATION FOR NEW!\n\n// if ($json[\"notion_job_page\"] && $json[\"notion_job_page\"].length > 0) {\n//   notionObject.properties[\"Job Record\"] = {\n//     \"type\": \"relation\",\n//     \"relation\": [{\"id\": $json[\"notion_job_page\"]}] \n//   }\n// }\n\nswitch ($json[\"stage-id\"]) {\n\n    //Case: Hiring Manger Screen\n    case '359fba80-442c-4731-9dd0-5d266544e620':\n        notionObject.properties[\"Submission Date\"] = {\n            type: \"date\",\n            date: {\n                start: new Date($json[\"candidate-last-advanced-at\"]).toISOString()\n            }\n        }\n\n        notionObject.properties[\"Lever: Stage\"] = {\n            type: \"select\",\n            select: {\n                name: \"Hiring Manager Screen\"\n            }\n        }\n\n        notionObject.properties[\"Current Status\"] = {\n            type: \"select\",\n            select: {\n                name: \"CLIENT SUBMISSION\"\n            }\n        }\n\n        break;\n\n        //Case: Team Interview\n        case '0401bad9-a8ab-4025-b103-bf5279fdf6a9':\n    \n            notionObject.properties[\"Lever: Stage\"] = {\n                type: \"select\",\n                select: {\n                    name: \"Team Interview\"\n                }\n            }\n    \n            notionObject.properties[\"Current Status\"] = {\n                type: \"select\",\n                select: {\n                    name: \"CLIENT SCHEDULING\"\n                }\n            }\n    \n            break;\n\n    case 'offer':\n        notionObject.properties[\"Offer Date\"] = {\n            type: \"date\",\n            date: {\n                start: new Date($json[\"candidate-last-advanced-at\"]).toISOString()\n            }\n        }\n\n        notionObject.properties[\"Lever: Stage\"] = {\n            type: \"select\",\n            select: {\n                name: \"Offer\"\n            }\n        }\n\n        notionObject.properties[\"Current Status\"] = {\n            type: \"select\",\n            select: {\n                name: \"CANDIDATE OFFER\"\n            }\n        }\n\n        break;\n}\n\nitem.notionData = notionObject;\n\nreturn item;"},"typeVersion":1},{"name":"IF New Candidate","type":"n8n-nodes-base.if","position":[3640,520],"parameters":{"conditions":{"string":[{"value1":"={{$json[\"notion-page-id\"]}}","operation":"isEmpty"}],"boolean":[]}},"typeVersion":1},{"name":"Get Job for New Record","type":"n8n-nodes-base.notion","position":[3900,340],"parameters":{"limit":1,"options":{"filter":{"singleCondition":{"key":"Lever Posting ID|rich_text","condition":"equals","richTextValue":"={{$json[\"posting-id\"]}}"}}},"resource":"databasePage","operation":"getAll","databaseId":"4cd53a7a-5d52-438c-b807-1b4ba1d4c6ff"},"credentials":{"notionApi":{"id":"3","name":"Kunai Staffing n8n Key"}},"typeVersion":1},{"name":"Retain Previous Data","type":"n8n-nodes-base.functionItem","position":[4120,340],"parameters":{"functionCode":"// Code here will run once per input item.\n// More info and help: https://docs.n8n.io/nodes/n8n-nodes-base.functionItem\n\n// Add a new field called 'myNewField' to the JSON of the item\nvar newItem = $item(0).$node[\"IF New Candidate\"].json\n\nnewItem[\"notion-job-id\"] = item.id\n\nnewItem.notionData.properties[\"Job Record\"] = {\n  type: \"relation\",\n  relation: [{id: item.id}]\n}\n\nreturn newItem;"},"executeOnce":true,"typeVersion":1},{"name":"Create Notion Candidate","type":"n8n-nodes-base.httpRequest","position":[4540,340],"parameters":{"url":"https://api.notion.com/v1/pages","options":{},"requestMethod":"POST","authentication":"headerAuth","bodyParametersUi":{"parameter":[{"name":"parent","value":"={{$json[\"notionData\"][\"parent\"]}}"},{"name":"properties","value":"={{$json[\"notionData\"][\"properties\"]}}"}]},"headerParametersUi":{"parameter":[{"name":"Notion-Version","value":"2021-08-16"}]}},"credentials":{"httpHeaderAuth":{"id":"4","name":"Manual Notion Key - Kunai n8n Staffing Integration"}},"typeVersion":1},{"name":"Get Pre-Sub for Update","type":"n8n-nodes-base.notion","position":[4760,340],"parameters":{"options":{"filter":{"singleCondition":{"key":"Lever Opportunity ID|rich_text","condition":"equals","richTextValue":"={{$json[\"properties\"][\"Lever Opportunity\"][\"rich_text\"][0][\"plain_text\"]}}"}}},"resource":"databasePage","operation":"getAll","databaseId":"fa05d118-5e22-418e-b7c8-c509dbe5fe82"},"credentials":{"notionApi":{"id":"3","name":"Kunai Staffing n8n Key"}},"typeVersion":1,"alwaysOutputData":false},{"name":"Mark as Submitted","type":"n8n-nodes-base.notion","position":[4960,340],"parameters":{"pageId":"={{$json[\"id\"]}}","resource":"databasePage","operation":"update","propertiesUi":{"propertyValues":[{"key":"Sent to Client|relation","relationValue":["={{$node[\"Create Notion Candidate\"].json[\"id\"]}}"]}]}},"credentials":{"notionApi":{"id":"3","name":"Kunai Staffing n8n Key"}},"typeVersion":1},{"name":"Update Notion Candidate","type":"n8n-nodes-base.httpRequest","position":[3900,580],"parameters":{"url":"=https://api.notion.com/v1/pages/{{$json[\"notion-page-id\"]}}","options":{},"requestMethod":"PATCH","authentication":"headerAuth","bodyParametersUi":{"parameter":[{"name":"properties","value":"={{$json.notionData.properties}}"}]},"headerParametersUi":{"parameter":[{"name":"Notion-Version","value":"2021-08-16"}]}},"credentials":{"httpHeaderAuth":{"id":"4","name":"Manual Notion Key - Kunai n8n Staffing Integration"}},"typeVersion":1},{"name":"Retain Candidate Object","type":"n8n-nodes-base.functionItem","notes":"Also check for Kunai Email","position":[4140,1020],"parameters":{"functionCode":"var newItem = $node[\"Prep for Client\"].json\n\nnewItem[\"candidate-first-name\"] = newItem[\"candidate-name\"].split(\" \")[0].replace(/[^a-zA-Z ]/g, \"\").toLowerCase();\nnewItem[\"candidate-last-name\"] = newItem[\"candidate-name\"].split(\" \")[1].replace(/[^a-zA-Z ]/g, \"\").toLowerCase();\n\nnewItem[\"candidate-all-emails\"] = $node[\"Get Opportunity\"].json.data.emails;\n\nnewItem[\"candidate-has-kunai-email\"] = false;\n\nnewItem[\"candidate-all-emails\"].forEach(function(email) {\n  const domain = email.split(\"@\")[1].toLowerCase();\n  \n  if (domain.indexOf('kunaico.com') !== -1 || domain.indexOf('kun.ai') !== -1 || domain.indexOf('kunaiconsulting.com') !== -1) {\n    newItem[\"candidate-has-kunai-email\"] = true;\n  }\n  \n});\n\nreturn newItem;"},"notesInFlow":true,"typeVersion":1},{"name":"IF Partial Name","type":"n8n-nodes-base.if","position":[4380,1020],"parameters":{"conditions":{"number":[{"value1":"={{$json[\"candidate-first-name\"].length}}","value2":1,"operation":"smallerEqual"},{"value1":"={{$json[\"candidate-last-name\"]}}","value2":1,"operation":"smallerEqual"}],"string":[]},"combineOperation":"any"},"typeVersion":1},{"name":"IF Kunai Email Set","type":"n8n-nodes-base.if","position":[4660,1040],"parameters":{"conditions":{"boolean":[{"value1":"={{$json[\"candidate-has-kunai-email\"]}}","value2":true}]}},"typeVersion":1},{"name":"Note: Partial Name","type":"n8n-nodes-base.httpRequest","position":[4660,840],"parameters":{"url":"=https://api.lever.co/v1/opportunities/{{$json[\"opportunity-id\"]}}/notes","options":{},"requestMethod":"POST","authentication":"basicAuth","bodyParametersUi":{"parameter":[{"name":"notifyFollowers","value":"={{true}}"},{"name":"value","value":"Candidate name in Lever must be in the format \"[First Name] [Last Name]\" in order to auto-generate a kunaiconsulting.com email address. To advance this candidate, please:\n1. Correct the candidate's name in Lever\n2. Manually move the candidate back to the \"Hiring Manager Screen\" stage\n3. Manually advance the candidate again to the \"Prep for Client\" stage"}]}},"credentials":{"httpBasicAuth":{"id":"18","name":"Kunai Lever Full Access"}},"typeVersion":1},{"name":"Check for GSuite Account","type":"n8n-nodes-base.gSuiteAdmin","notes":"on personal email","position":[4940,1060],"parameters":{"options":{"query":"=email={{$json[\"candidate-email\"]}}"},"operation":"getAll"},"credentials":{"gSuiteAdminOAuth2Api":{"id":"6","name":"GSuite Admin OAuth for n8n - Ruan"}},"notesInFlow":true,"typeVersion":1,"alwaysOutputData":true},{"name":"Email has Kunai Account","type":"n8n-nodes-base.if","position":[5180,1060],"parameters":{"conditions":{"boolean":[{"value1":"={{Object.keys($json).length > 0}}","value2":true}]}},"typeVersion":1},{"name":"Get first.last@","type":"n8n-nodes-base.gSuiteAdmin","notes":"check for first.last@kunaiconsulting","position":[5420,1080],"parameters":{"options":{"query":"=email={{$node[\"Retain Candidate Object\"].json[\"candidate-first-name\"]}}.{{$node[\"Retain Candidate Object\"].json[\"candidate-last-name\"]}}@kunaiconsulting.com"},"operation":"getAll"},"credentials":{"gSuiteAdminOAuth2Api":{"id":"6","name":"GSuite Admin OAuth for n8n - Ruan"}},"notesInFlow":true,"typeVersion":1,"alwaysOutputData":true},{"name":"First.Last@ Exists","type":"n8n-nodes-base.if","position":[5600,1080],"parameters":{"conditions":{"boolean":[{"value1":"={{Object.keys($json).length > 0}}","value2":true}]}},"typeVersion":1},{"name":"Generate Password","type":"n8n-nodes-base.functionItem","position":[5840,1100],"parameters":{"functionCode":"var newItem = $node[\"Retain Candidate Object\"].json\n\nfunction generateP() {\n            var pass = '';\n            var str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + \n                    'abcdefghijklmnopqrstuvwxyz0123456789@#$';\n              \n            for (i = 1; i <= 16; i++) {\n                var char = Math.floor(Math.random()\n                            * str.length + 1);\n                  \n                pass += str.charAt(char)\n            }\n              \n            return pass;\n}\n\nnewItem.tempPassword = generateP();\n\nreturn newItem;"},"typeVersion":1},{"name":"Create Account","type":"n8n-nodes-base.gSuiteAdmin","position":[6040,1100],"parameters":{"domain":"kunaiconsulting.com","lastName":"={{$json[\"candidate-name\"].split(\" \")[1]}}","password":"={{$json[\"tempPassword\"]}}","username":"={{$json[\"candidate-first-name\"]}}.{{$json[\"candidate-last-name\"]}}","firstName":"={{$json[\"candidate-name\"].split(\" \")[0]}}","additionalFields":{"emailUi":{"emailValues":[{"type":"home","address":"={{$json[\"candidate-email\"]}}"}]},"changePasswordAtNextLogin":true}},"credentials":{"gSuiteAdminOAuth2Api":{"id":"6","name":"GSuite Admin OAuth for n8n - Ruan"}},"typeVersion":1},{"name":"Send Welcome Email","type":"n8n-nodes-base.sendGrid","position":[6240,1100],"parameters":{"toEmail":"={{$json[\"emails\"][0][\"address\"]}}","fromName":"Kunai Talent Team","resource":"mail","fromEmail":"talent.team@kunaico.com","templateId":"d-b64b7d71b0ce415f93265fc4d7bdf027","dynamicTemplate":true,"additionalFields":{"bccEmail":"talent.team@kunaico.com"},"dynamicTemplateFields":{"fields":[{"key":"kunaiEmail","value":"={{$json[\"primaryEmail\"]}}"},{"key":"temporaryPassword","value":"={{$node[\"Generate Password\"].json[\"tempPassword\"]}}"},{"key":"firstName","value":"={{$json[\"name\"][\"givenName\"]}}"}]}},"credentials":{"sendGridApi":{"id":"8","name":"Ruan Kunai Sendgrid"}},"typeVersion":1},{"name":"Put Email in Lever","type":"n8n-nodes-base.httpRequest","position":[6440,1100],"parameters":{"url":"=https://api.lever.co/v1/contacts/{{$node[\"Lever Webhook\"].json[\"body\"][\"data\"][\"contactId\"]}}","options":{},"requestMethod":"PUT","authentication":"basicAuth","bodyParametersUi":{"parameter":[{"name":"emails","value":"={{$node[\"Generate Password\"].json[\"candidate-all-emails\"].concat([$node[\"Create Account\"].json[\"primaryEmail\"]])}}"}]}},"credentials":{"httpBasicAuth":{"id":"18","name":"Kunai Lever Full Access"}},"typeVersion":1},{"name":"Add Note on KN Email","type":"n8n-nodes-base.httpRequest","position":[6680,1100],"parameters":{"url":"=https://api.lever.co/v1/opportunities/{{$node[\"Generate Password\"].json[\"opportunity-id\"]}}/notes","options":{},"requestMethod":"POST","authentication":"basicAuth","bodyParametersUi":{"parameter":[{"name":"value","value":"=Created email address {{$node[\"Create Account\"].json[\"primaryEmail\"]}} and added it to candidate profile. Login information sent to {{$node[\"Generate Password\"].json[\"candidate-email\"]}} via Sendgrid (message id {{$node[\"Send Welcome Email\"].json[\"messageId\"]}}). Advancing candidate to Team Interview stage."}]}},"credentials":{"httpBasicAuth":{"id":"18","name":"Kunai Lever Full Access"}},"typeVersion":1},{"name":"Advance to Team Interview","type":"n8n-nodes-base.httpRequest","position":[6900,1100],"parameters":{"url":"=https://api.lever.co/v1/opportunities/{{$node[\"Generate Password\"].json[\"opportunity-id\"]}}/stage","options":{},"requestMethod":"PUT","authentication":"basicAuth","bodyParametersUi":{"parameter":[{"name":"stage","value":"0401bad9-a8ab-4025-b103-bf5279fdf6a9"}]}},"credentials":{"httpBasicAuth":{"id":"18","name":"Kunai Lever Full Access"}},"typeVersion":1},{"name":"IF Posting Defined","type":"n8n-nodes-base.if","position":[2220,-20],"parameters":{"conditions":{"boolean":[{"value1":"={{$json[\"posting-id\"].length > 0}}","value2":true}]}},"typeVersion":1},{"name":"Wait 10s","type":"n8n-nodes-base.wait","position":[1560,220],"webhookId":"e454044f-2533-4286-96c2-58793c020c6a","parameters":{"unit":"seconds","amount":"={{$runIndex === 0 ? 10 : ($runIndex === 1 ? 60 : ($runIndex === 2 ? 120 : 180) ) }}"},"typeVersion":1},{"name":"Retry Application","type":"n8n-nodes-base.slack","position":[2380,200],"parameters":{"text":"=:warning:\n*Request:* Attempted to sync candidate {{$json[\"candidate-name\"]}} ( https://hire.lever.co/candidates/{{$json[\"opportunity-id\"]}} ) with Notion. \n*Result:* Job application was not available in Lever. Retrying in {{$runIndex === 0 ? 10 : ($runIndex === 1 ? 60 : ($runIndex === 2 ? 120 : 180) )}} seconds.\n*Details:* Applicant will remain in current stage in Lever, but is *not* yet synced Notion.","channel":"staffing-automations","blocksUi":{"blocksValues":[]},"attachments":[],"otherOptions":{"link_names":true,"unfurl_links":false}},"credentials":{"slackApi":{"id":"7","name":"Slack n8n Auth Token"}},"typeVersion":1},{"name":"IF 1st or 2nd Retry","type":"n8n-nodes-base.if","position":[1720,220],"parameters":{"conditions":{"number":[{"value1":"={{$runIndex}}","value2":3}],"boolean":[]}},"typeVersion":1},{"name":"Stop Retrying","type":"n8n-nodes-base.slack","position":[2380,380],"parameters":{"text":"=:red_circle: :fire:\n*Request:* Attempted to sync candidate {{$json[\"candidate-name\"]}} ( https://hire.lever.co/candidates/{{$json[\"opportunity-id\"]}} ) to the with Notion in execution number {{$executionId}}.\n*Result:* Job application is still not available in Lever after three attempts 5 minutes apart.\n*Details:* Applicant will remain in \"Present to Client\" stage in Lever, but is *not* yet synced with Notion.\n@ruan","channel":"staffing-automations","attachments":[],"otherOptions":{}},"credentials":{"slackApi":{"id":"7","name":"Slack n8n Auth Token"}},"typeVersion":1},{"name":"IF Retried","type":"n8n-nodes-base.if","position":[2400,-240],"parameters":{"conditions":{"number":[{"value1":"={{$node[\"Get Opportunity\"].runIndex}}","operation":"larger"}]}},"typeVersion":1},{"name":"Retry Successful","type":"n8n-nodes-base.slack","position":[2580,-580],"parameters":{"text":"=:white_check_mark:\n*Request:* Attempted to sync candidate {{$json[\"candidate-name\"]}} ( https://hire.lever.co/candidates/{{$json[\"opportunity-id\"]}} ) to Notion Trackers. \n*Result:* Job application was available in Lever. Retry Successful.\n*Details:* Applicant will be synced with Notion.","channel":"staffing-automations","attachments":[],"otherOptions":{}},"credentials":{"slackApi":{"id":"7","name":"Slack n8n Auth Token"}},"typeVersion":1},{"name":"Get Recruiter","type":"n8n-nodes-base.notion","position":[5180,-400],"parameters":{"limit":1,"options":{"filter":{"singleCondition":{"key":"Lever User ID|rich_text","condition":"equals","richTextValue":"={{$node[\"Present to Client\"].json[\"candidate-owner-id\"]}}"}}},"resource":"databasePage","operation":"getAll","databaseId":"e9d06e19-d80d-4058-a9f2-c0f701a51715"},"credentials":{"notionApi":{"id":"3","name":"Kunai Staffing n8n Key"}},"typeVersion":1},{"name":"Add Recruiter to Pre-Sub","type":"n8n-nodes-base.notion","position":[5400,-400],"parameters":{"pageId":"={{$node[\"Create Pre-Sub\"].json[\"id\"]}}","resource":"databasePage","operation":"update","propertiesUi":{"propertyValues":[{"key":"Recruiter|relation","relationValue":["={{$json.id}}"]}]}},"credentials":{"notionApi":{"id":"3","name":"Kunai Staffing n8n Key"}},"typeVersion":1},{"name":"Archive Handler","type":"n8n-nodes-base.executeWorkflow","position":[1320,200],"parameters":{"workflowId":"1039"},"typeVersion":1},{"name":"IF Unsubmitted","type":"n8n-nodes-base.if","position":[4960,-660],"parameters":{"conditions":{"number":[{"value1":"={{$json[\"Sent to Client\"].length}}","operation":"equal"}]}},"typeVersion":1},{"name":"Activate Pre-Sub","type":"n8n-nodes-base.notion","position":[5180,-680],"parameters":{"pageId":"={{$json.id}}","resource":"databasePage","operation":"update","propertiesUi":{"propertyValues":[{"key":"Submission Cancelled|checkbox"},{"key":"Cancel Reason|select","selectValue":"4b741b7b-c75e-434f-be82-cdf697400a26"}]}},"credentials":{"notionApi":{"id":"3","name":"Kunai Staffing n8n Key"}},"typeVersion":1},{"name":"Recruiter Screen","type":"n8n-nodes-base.noOp","position":[2700,240],"parameters":{},"typeVersion":1},{"name":"Check for Pre-Sub","type":"n8n-nodes-base.notion","position":[2880,240],"parameters":{"limit":1,"options":{"filter":{"singleCondition":{"key":"Lever Opportunity ID|rich_text","condition":"equals","richTextValue":"={{$json[\"opportunity-id\"]}}"}}},"resource":"databasePage","operation":"getAll","databaseId":"fa05d118-5e22-418e-b7c8-c509dbe5fe82"},"credentials":{"notionApi":{"id":"3","name":"Kunai Staffing n8n Key"}},"typeVersion":1},{"name":"Cancel Pre-Sub","type":"n8n-nodes-base.notion","position":[3100,240],"parameters":{"pageId":"={{$json.id}}","resource":"databasePage","operation":"update","propertiesUi":{"propertyValues":[{"key":"Submission Cancelled|checkbox","checkboxValue":true},{"key":"Cancel Reason|select","selectValue":"6e254e9a-a270-4634-bc60-3948c097f308"}]}},"credentials":{"notionApi":{"id":"3","name":"Kunai Staffing n8n Key"}},"typeVersion":1},{"name":"Get Existing Pre-Sub (old)","type":"n8n-nodes-base.notion","position":[4240,-940],"parameters":{"options":{"filter":{"singleCondition":{"key":"Lever Opportunity ID|rich_text","condition":"equals","richTextValue":"={{$node[\"Present to Client\"].json[\"opportunity-id\"]}}"}}},"resource":"databasePage","operation":"getAll","returnAll":true,"databaseId":"fa05d118-5e22-418e-b7c8-c509dbe5fe82"},"credentials":{"notionApi":{"id":"3","name":"Kunai Staffing n8n Key"}},"typeVersion":1,"alwaysOutputData":true},{"name":"Get Existing Pre-Sub","type":"n8n-nodes-base.notion","position":[4360,-420],"parameters":{"options":{},"resource":"databasePage","operation":"getAll","databaseId":"fa05d118-5e22-418e-b7c8-c509dbe5fe82","filterJson":"={\n    \"property\": \"Lever Opportunity ID\",\n        \"rich_text\": {\n            \"equals\": \"{{$node[\"Present to Client\"].json[\"opportunity-id\"]}}\"\n        }\n}","filterType":"json"},"credentials":{"notionApi":{"id":"3","name":"Kunai Staffing n8n Key"}},"typeVersion":2,"alwaysOutputData":true}],"active":false,"settings":{},"connections":{"Wait 10s":{"main":[[{"node":"IF 1st or 2nd Retry","type":"main","index":0}]]},"IF Retried":{"main":[[{"node":"Retry Successful","type":"main","index":0}]]},"IF Verified":{"main":[[{"node":"Route by Type","type":"main","index":0},{"node":"Respond 200","type":"main","index":0}],[{"node":"Handle Bad Webhook","type":"main","index":0}]]},"Other Stage":{"main":[[{"node":"Get Candidate Record","type":"main","index":0},{"node":"Set Empty Notion ID","type":"main","index":0}]]},"IF Kunai PtC":{"main":[[{"node":"Advance to HM Screen","type":"main","index":0}],[{"node":"Update Pre-Sub Tracker","type":"main","index":0}]]},"Unify Params":{"main":[[{"node":"IF Posting Defined","type":"main","index":0}]]},"Get Recruiter":{"main":[[{"node":"Add Recruiter to Pre-Sub","type":"main","index":0}]]},"Lever Webhook":{"main":[[{"node":"Verify Webhook","type":"main","index":0}]]},"Route by Type":{"main":[[{"node":"Handle Stage Change","type":"main","index":0}],[{"node":"Handle Archive","type":"main","index":0}],[{"node":"Handle Hired","type":"main","index":0}],[{"node":"Handle Deleted","type":"main","index":0}]]},"Create Account":{"main":[[{"node":"Send Welcome Email","type":"main","index":0}]]},"Create Pre-Sub":{"main":[[{"node":"Get Recruiter","type":"main","index":0}]]},"Get Notion Job":{"main":[[{"node":"Get Existing Pre-Sub","type":"main","index":0}]]},"Handle Archive":{"main":[[{"node":"Archive Handler","type":"main","index":0}]]},"IF Unsubmitted":{"main":[[{"node":"Activate Pre-Sub","type":"main","index":0}]]},"Verify Webhook":{"main":[[{"node":"IF Verified","type":"main","index":0}]]},"Get Opportunity":{"main":[[{"node":"Unify Params","type":"main","index":0}]]},"Get first.last@":{"main":[[{"node":"First.Last@ Exists","type":"main","index":0}]]},"IF Partial Name":{"main":[[{"node":"Note: Partial Name","type":"main","index":0}],[{"node":"IF Kunai Email Set","type":"main","index":0}]]},"Prep for Client":{"main":[[{"node":"Auto Advance to Team Interview","type":"main","index":0}]]},"Set Notion Data":{"main":[[{"node":"Merge from Notion","type":"main","index":1}]]},"IF Handled Stage":{"main":[[{"node":"Get Opportunity","type":"main","index":0}]]},"IF New Candidate":{"main":[[{"node":"Get Job for New Record","type":"main","index":0}],[{"node":"Update Notion Candidate","type":"main","index":0}]]},"Recruiter Screen":{"main":[[{"node":"Check for Pre-Sub","type":"main","index":0}]]},"Check for Pre-Sub":{"main":[[{"node":"Cancel Pre-Sub","type":"main","index":0}]]},"Generate Password":{"main":[[{"node":"Create Account","type":"main","index":0}]]},"IF No Reqs - Prep":{"main":[[{"node":"Handle 0 Reqs - Prep","type":"main","index":0}],[{"node":"Use 1st Req - Prep","type":"main","index":0}]]},"IF Pre-Sub Exists":{"main":[[{"node":"IF Unsubmitted","type":"main","index":0}],[{"node":"Create Pre-Sub","type":"main","index":0}]]},"Merge from Notion":{"main":[[{"node":"Create Notion Payload","type":"main","index":0}]]},"Present to Client":{"main":[[{"node":"Get Posting - Present","type":"main","index":0}]]},"First.Last@ Exists":{"main":[[],[{"node":"Generate Password","type":"main","index":0}]]},"Handle Bad Webhook":{"main":[[{"node":"Respond 401","type":"main","index":0}]]},"IF Kunai Email Set":{"main":[[],[{"node":"Check for GSuite Account","type":"main","index":0}]]},"IF Posting Defined":{"main":[[{"node":"Route by New Stage","type":"main","index":0},{"node":"IF Retried","type":"main","index":0}],[{"node":"Wait 10s","type":"main","index":0},{"node":"Retry Application","type":"main","index":0}]]},"Put Email in Lever":{"main":[[{"node":"Add Note on KN Email","type":"main","index":0}]]},"Route by New Stage":{"main":[[{"node":"Present to Client","type":"main","index":0}],[{"node":"Prep for Client","type":"main","index":0}],[{"node":"Recruiter Screen","type":"main","index":0}],[{"node":"Other Stage","type":"main","index":0}]]},"Send Welcome Email":{"main":[[{"node":"Put Email in Lever","type":"main","index":0}]]},"Use 1st Req - Prep":{"main":[[{"node":"Get Req 0 - Prep","type":"main","index":0}]]},"Handle Stage Change":{"main":[[{"node":"IF Handled Stage","type":"main","index":0}]]},"IF 1st or 2nd Retry":{"main":[[{"node":"Get Opportunity","type":"main","index":0}],[{"node":"Stop Retrying","type":"main","index":0}]]},"Set Empty Notion ID":{"main":[[{"node":"Merge from Notion","type":"main","index":0}]]},"Add Note on KN Email":{"main":[[{"node":"Advance to Team Interview","type":"main","index":0}]]},"Advance to HM Screen":{"main":[[{"node":"Note: Advanced to HM Screen","type":"main","index":0}]]},"Get Candidate Record":{"main":[[{"node":"Set Notion Data","type":"main","index":0}]]},"Get Existing Pre-Sub":{"main":[[{"node":"IF Pre-Sub Exists","type":"main","index":0}]]},"IF No Reqs - Present":{"main":[[{"node":"Handle 0 Reqs - Present","type":"main","index":0}],[{"node":"Use 1st Req  - Present","type":"main","index":0}]]},"Retain Previous Data":{"main":[[{"node":"Create Notion Candidate","type":"main","index":0}]]},"Create Notion Payload":{"main":[[{"node":"IF New Candidate","type":"main","index":0}]]},"Get Posting - Present":{"main":[[{"node":"IF Kunai PtC","type":"main","index":0}]]},"Get Job for New Record":{"main":[[{"node":"Retain Previous Data","type":"main","index":0}]]},"Get Pre-Sub for Update":{"main":[[{"node":"Mark as Submitted","type":"main","index":0}]]},"Update Pre-Sub Tracker":{"main":[[{"node":"Get Notion Job","type":"main","index":0}]]},"Use 1st Req  - Present":{"main":[[{"node":"Get Req 0  - Present","type":"main","index":0}]]},"Create Notion Candidate":{"main":[[{"node":"Get Pre-Sub for Update","type":"main","index":0}]]},"Email has Kunai Account":{"main":[[],[{"node":"Get first.last@","type":"main","index":0}]]},"Retain Candidate Object":{"main":[[{"node":"IF Partial Name","type":"main","index":0}]]},"Check for GSuite Account":{"main":[[{"node":"Email has Kunai Account","type":"main","index":0}]]},"Auto Advance to Team Interview":{"main":[[{"node":"Note: Advanced to Team Interview","type":"main","index":0}]]}}}