From e2022c67db1877043b95738a39ceaa8ae8a79ab2 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 17 Aug 2022 18:46:24 -0500 Subject: [PATCH] Website: send request to Zapier when a subscription is created (#7273) * Website: send request to Zapier when a license is purchased * Update error message/lint fix Co-authored-by: Mike McNeil --- .../save-billing-info-and-subscribe.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/website/api/controllers/customers/save-billing-info-and-subscribe.js b/website/api/controllers/customers/save-billing-info-and-subscribe.js index 888111c25e..bc7c758c37 100644 --- a/website/api/controllers/customers/save-billing-info-and-subscribe.js +++ b/website/api/controllers/customers/save-billing-info-and-subscribe.js @@ -113,6 +113,24 @@ module.exports = { fleetLicenseKey: licenseKey, }); + // Send a POST request to Zapier + await sails.helpers.http.post( + 'https://hooks.zapier.com/hooks/catch/3627242/blhrvf1/', + { + 'emailAddress': this.req.me.emailAddress, + 'numberOfHosts': quoteRecord.numberOfHosts, + 'subscriptionPrice': quoteRecord.quotedPrice, + 'nextBillingTimestamp': new Date(subscription.current_period_end * 1000).toISOString(), + '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 purchased a Fleet Premium license, a lead/contact could not be updated in the CRM for this email address: ${this.req.me.emailAddress}. Raw error: ${err}`); + return; + }); + // Send the order confirmation template email await sails.helpers.sendTemplateEmail.with({ to: this.req.me.emailAddress,