Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Code snippet on how to create a webhook using the MessageMedia Webhooks Node.js SDK.
const lib = require('messagemedia-webhooks-sdk');
// Sets your auth credentials and creates controller which is used to call the createWebhook function from the SDK
function setup(){
var controller;
// Configuration parameters and credentials
lib.Configuration.basicAuthUserName = "API_KEY";
lib.Configuration.basicAuthPassword = "API_SECRET";
controller = lib.WebhooksController;
return controller;
function createWebhook(){
var controller = setup();
// Create body of your webhook
var body = new lib.CreateWebhookRequest({
"url": "", // URL of the webhook
"method": "POST", // HTTP method
"encoding": "JSON", // Content type of the request
"events": [
"RECEIVED_SMS" // Webhook subscribed to RECEIVED_SMS event which is triggered when an SMS is received
"template": "{\"id\":\"$mtId\",\"time_sent\":\"$submittedTimestamp\",\"time_received\":\"$receivedTimestamp\",\"account_id\":\"$accountId\"}" // The attributes in the template will be returned when the webhook is triggered
// Call the function that creates the webhook
controller.createWebhook(body, function(error, response, context) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.