From c4e8f83a70436aff6943ab1493bfa3eae65d4a74 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 28 Feb 2025 19:44:32 -0600 Subject: [PATCH] Website: update Zapier webhook (#26741) ChangeS: - updated the `receive-from-zapier` webhook's expected inputs when receiving a `receive-new-customer-data` event --- .../webhooks/receive-from-zapier.js | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/website/api/controllers/webhooks/receive-from-zapier.js b/website/api/controllers/webhooks/receive-from-zapier.js index 94588c682e..39b7bd90a5 100644 --- a/website/api/controllers/webhooks/receive-from-zapier.js +++ b/website/api/controllers/webhooks/receive-from-zapier.js @@ -75,28 +75,11 @@ module.exports = { } else if (eventName === 'receive-new-customer-data') { assert(_.isObject(data)); assert(_.isString(data.newMarketingStage)); - assert(_.isString(data.name)); - assert(_.isString(data.website)); - assert(_.isString(data.linkedinCompanyPageUrl)); assert(_.isString(data.persona) && AdCampaign.validate('persona', data.persona)); - - // Enrich to obtain linkedin company ID using provided data. - // Remove any trailing slashes from the LinkedIn URL. - let trailingSlashlessLinkedinCompanyUrl = _.trim(data.linkedinCompanyPageUrl, '/'); - // Split the LinkedIn url by slashes - let splitLinkedinCompanyUrl = trailingSlashlessLinkedinCompanyUrl.split('/'); - // Grab the last fragment of the URL, we'll use this for the coreSignal API request to - let linkedinCompanyIdOrSlug = splitLinkedinCompanyUrl[splitLinkedinCompanyUrl.length - 1]; - let matchedCompanyPageInfo = await sails.helpers.http.get('https://api.coresignal.com/cdapi/v1/linkedin/company/collect/'+linkedinCompanyIdOrSlug, {}, { - Authorization: `Bearer ${sails.config.custom.iqSecret}`, - 'content-type': 'application/json' - }).intercept((err)=>{ - sails.log.warn(`When the receive-from-zapier webhook received a request about a Salesforce record, a linkedin company could not be found using the provided linkedIn URL (${data.linkedinCompanyPageUrl})`, err); - return 'couldNotMatchLinkedinId'; - }); + assert(data.linkedinCompanyId); // (FUTURE: make field for this and have it already in CRM so this step isn't necessary) - let linkedinCompanyId = matchedCompanyPageInfo.id; + let linkedinCompanyId = data.linkedinCompanyId; // Check if we have enough space in our current active campaign. // If so, then use it and update its inventory. Otherwise, prepare to create @@ -110,6 +93,9 @@ module.exports = { let filterCriteriaForLatestCampaign = latestCampaign.linkedinCompanyIds.map((id)=>{ return `urn:li:organization:${id}`; }); + // Append the new organization to the end of the the filterCriteria + filterCriteriaForLatestCampaign.push(`urn:li:organization:${linkedinCompanyId}`); + // Send a request to update this campaign. await sails.helpers.http.sendHttpRequest.with({ method: 'POST', url: `https://hooks.zapier.com/hooks/catch/3627242/2wdx23r?webhookSecret=${ encodeURIComponent(sails.config.custom.zapierWebhookSecret)}`,