Created
March 18, 2025 23:42
-
-
Save twosdai/29179a11f462170d9f776870b07e3b49 to your computer and use it in GitHub Desktop.
Webhook Register
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Description: This script registers a webhook, tests it, and then unregisters it. | |
// Run npm install cross-fetch to install the cross-fetch package. you can also use node-fetch but the ESM module system will struggle with it. | |
// To run the script, run: node webHookRegisterAndTest.js | |
const fetch = require("cross-fetch"); | |
const apiKey = "EXAMPLE_API_KEY"; | |
const webhookUrl = "https://public.prod.tenex.email/webhooks/register"; | |
const testWebhookUrl = "https://public.prod.tenex.email/webhooks/test"; | |
const unregisterWebhookUrl = "https://public.prod.tenex.email/webhooks/"; | |
const payload = { | |
webhookUrl: "FILL_IN_WEBHOOK_URL", | |
webhookSecret: "shhh", | |
webhookType: "LEAD", | |
}; | |
console.log(`Registering webhook...`); | |
fetch(webhookUrl, { | |
method: "POST", | |
body: JSON.stringify(payload), | |
headers: { "Content-Type": "application/json", "X-API-KEY": apiKey }, | |
}) | |
.then((res) => res.json()) | |
.then((data) => { | |
console.log(`Webhook registered successfully: ${data.webhookId}`); | |
console.log(`Testing webhook...`); | |
return fetch(testWebhookUrl, { | |
method: "POST", | |
body: JSON.stringify({ | |
webhookId: data.webhookId, | |
}), | |
headers: { "Content-Type": "application/json", "X-API-KEY": apiKey }, | |
}); | |
}) | |
.then((res) => res.json()) | |
.then((data) => { | |
console.log(`Webhook test successful: ${data.message}`); | |
console.log(`Webhook test completed`); | |
console.log(`Unregistering webhook...`); | |
return fetch(unregisterWebhookUrl + data.webhookId, { | |
method: "DELETE", | |
headers: { "Content-Type": "application/json", "X-API-KEY": apiKey }, | |
}); | |
}) | |
.then((res) => res.json()) | |
.then((data) => { | |
console.log(`Webhook unregistered successfully: ${data.message}`); | |
console.log(`Webhook unregistration completed`); | |
}) | |
.catch((err) => console.error(err)); | |
console.log("Done"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment