From edcf09febd116f4d364ba314dd8cacdebaa33850 Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 11 Aug 2022 21:05:24 -0500 Subject: [PATCH] Website: add Zapier webhook to signup.js (#7177) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add Zapier webhook request to signup form, add signupReason input * webhook-secret ยป webhookSecret --- website/api/controllers/entrance/signup.js | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/website/api/controllers/entrance/signup.js b/website/api/controllers/entrance/signup.js index 4169786c13..c9a2e93b7b 100644 --- a/website/api/controllers/entrance/signup.js +++ b/website/api/controllers/entrance/signup.js @@ -55,6 +55,12 @@ the account verification message.)`, type: 'string', example: 'Rivera', description: 'The user\'s last name.', + }, + + signupReason: { + type: 'string', + isIn: ['Buy a license', 'Try Fleet Sandbox'], + defaultsTo: 'Buy a license', } }, @@ -81,7 +87,7 @@ the account verification message.)`, }, - fn: async function ({emailAddress, password, firstName, lastName, organization}) { + fn: async function ({emailAddress, password, firstName, lastName, organization, signupReason}) { var newEmailAddress = emailAddress.toLowerCase(); @@ -114,7 +120,24 @@ the account verification message.)`, stripeCustomerId }); } - + // Send a POST request to Zapier + await sails.helpers.http.post( + 'https://hooks.zapier.com/hooks/catch/3627242/bqsf4rj/', + { + 'emailAddress': newEmailAddress, + 'organization': signupReason === 'Buy a license' ? organization : '?', + 'firstName': signupReason === 'Buy a license' ? firstName : '?', + 'lastName': signupReason === 'Buy a license' ? lastName : '?', + 'signupReason': signupReason, + '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 new user signed up, a lead/contact could not be verified in the CRM for this email address: ${newEmailAddress}. Raw error: ${err}`); + return; + }); // Store the user's new id in their session. this.req.session.userId = newUserRecord.id;