Skip to main content

Webhooks

Updated over 5 months ago

What's a webhook?

A webhook is a way for two different applications or systems to communicate with each other in real-time. Specifically, a webhook is a method of automatically sending data from one system to another whenever a certain event occurs.

For example, let's say you have an online store and you want to keep track of all your new orders in a separate system. You can use a webhook to automatically send the details of each new order to that system as soon as it happens, without having to manually enter the information each time.

In other words, a webhook is like a phone call that one application makes to another, saying "Hey, something just happened over here, you might want to know about it." The receiving application can then use that information to perform some action, such as updating a database, sending a notification, or triggering some other automated process.

Webhooks are a powerful tool for automating processes and integrating different systems together. By setting up webhooks between different tools you use for your business, you can save time and reduce errors by automating repetitive tasks, and make sure that all your data is up-to-date across all your applications.

Learn more about Webhooks .

Setting up a Webhook in Automations

Our automations allow for you to send a webhook to one or more URLs when a particular trigger takes place within Smarter Launch. For example, you may have another system that keeps track of all sales coming in for your company from various sales channels. You could setup an automation to trigger and send a notification to a specific URL defined within your sales system that will notify it when a proposal is accepted within Smarter Launch.

To setup an automation, simply navigate to your account settings and click on the Automations tab. Create a new automation, set what kind of event should trigger the automation, and select Send a Webhook as the action to be performed. Enter your webhook URL that should receive the data.

Validate the Payload from a Webhook

All webhooks sent from Smarter Launch are signed with a webhook key unique to every account. Your software development team can verify that the payload is valid and has not been tampered with by generating a signature from the payload utilizing your account's unique key.

The signature that is passed within the request header can be compared by implementing the following method:

Node.JS

const crypto = require('crypto'); const secret = 'your-secret-key'; const payloadJson = JSON.stringify(payload); const signature = crypto.createHmac('sha256', secret).update(payloadJson).digest('hex');

  1. First, import the Node.js crypto module.

  2. Assign your secret key to a variable called secret .

  3. Convert the payload data to JSON format using the JSON.stringify() method and assign it to a variable called payloadJson .

  4. Use the crypto.createHmac() method to create a new HMAC instance with the sha256 algorithm and your secret key as the secret.

  5. Use the .update() method to update the HMAC instance with the payload data in JSON format.

  6. Use the .digest() method to generate the HMAC signature as a hex-encoded string, and assign it to a variable called signature .

Python

import hashlib import hmac import json secret = 'your-secret-key' payloadJson = json.dumps(payload) signature = hmac.new(secret.encode('utf-8'), msg=payloadJson.encode('utf-8'), digestmod=hashlib.sha256).hexdigest()

  1. First, import the necessary modules: hashlib , hmac , and json .

  2. Assign your secret key to a variable called secret .

  3. Convert the payload data to JSON format using the json.dumps() method and assign it to a variable called payloadJson .

  4. Use the hmac.new() method to create a new HMAC instance with the sha256 algorithm, your secret key as the key, and the payload data in JSON format as the message.

  5. Use the .hexdigest() method to generate the HMAC signature as a hex-encoded string, and assign it to a variable called signature .

PHP

$signature = hash_hmac('sha256', $payloadJson, $secret);

This code is using the hash_hmac() function in PHP to generate an HMAC signature for a given payload data using a secret key. The hash_hmac() function takes three arguments:

  1. The hashing algorithm to use for the HMAC calculation, which in this case is 'sha256'.

  2. The payload data to be signed, which is stored in the $payloadJson variable.

  3. The secret key to be used for the HMAC calculation, which is stored in the $secret variable.

The hash_hmac() function will return the HMAC signature as a string, which is then stored in the $signature variable. This HMAC signature can be used to verify the integrity of the payload data and ensure that it was not tampered with during transmission.

Confirming Receipt of the Webhook

If we do not receive a response code starting with a "2" we will try again in 10 seconds. If that also fails to receive a successful HTTP response code, we will try again in 100 seconds. We will not try again after these 3 attempts.

Did this answer your question?