From d89af249557fa67d2a545999547c565dc0212f9b Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 8 Apr 2024 10:51:15 -0500 Subject: [PATCH] Website: Update /start questionnaire to update leads (#18120) Changes: - Updated the `save-questionnaire-progress` to send a request to Zapier when a user completes the "What are you using Fleet for" step of the /start questionnaire. --- .../controllers/save-questionnaire-progress.js | 16 ++++++++++++++++ website/assets/js/pages/start.page.js | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/website/api/controllers/save-questionnaire-progress.js b/website/api/controllers/save-questionnaire-progress.js index 8ef697de53..3f53545906 100644 --- a/website/api/controllers/save-questionnaire-progress.js +++ b/website/api/controllers/save-questionnaire-progress.js @@ -59,6 +59,22 @@ module.exports = { await User.updateOne({id: this.req.me.id}).set({ primaryBuyingSituation }); + // Send a POST request to Zapier + await sails.helpers.http.post.with({ + url: 'https://hooks.zapier.com/hooks/catch/3627242/3pl7yt1/', + data: { + primaryBuyingSituation, + emailAddress: this.req.me.emailAddress, + webhookSecret: sails.config.custom.zapierSandboxWebhookSecret, + } + }) + .timeout(5000) + .tolerate(['non200Response', 'requestFailed'], (err)=>{ + // Note that Zapier responds with a 2xx status code even if something goes wrong, so just because this message is not logged doesn't mean everything is hunky dory. More info: https://github.com/fleetdm/fleet/pull/6380#issuecomment-1204395762 + sails.log.warn(`When a user completed the 'What are you using Fleet for' questionnaire step, a lead/contact could not be updated in the CRM for this email address: ${this.req.me.emailAddress}. Raw error: ${err}`); + return; + }); + // Set the primary buying situation in the user's session. this.req.session.primaryBuyingSituation = primaryBuyingSituation; } diff --git a/website/assets/js/pages/start.page.js b/website/assets/js/pages/start.page.js index 9b7173da0b..47dfe0bc98 100644 --- a/website/assets/js/pages/start.page.js +++ b/website/assets/js/pages/start.page.js @@ -75,7 +75,7 @@ parasails.registerPage('start', { } // If this user has not completed the 'what are you using fleet for' step, and has a primaryBuyingSituation set by an ad. prefill the formData for this step. if(this.primaryBuyingSituation && _.isEmpty(this.formData['what-are-you-using-fleet-for'])){ - this.formData['what-are-you-using-fleet-for'].primaryBuyingSituation = _.clone(this.primaryBuyingSituation); + this.formData['what-are-you-using-fleet-for'] = {primaryBuyingSituation: this.primaryBuyingSituation}; } }, mounted: async function() {