Social Media Marketing

What is a Webhook? How He Works with Examples

[ad_1]

Have you heard that the product you are discussing has a “webhook”, and the unspoken assumption is that you both understand and are happy. Yes, you should be excited because webhooks are really amazing, but before we start trumpeting, let’s first understand what a webhook is and why it’s important.

A webhook is a tool used in web or API development, which allows applications to provide real-time information to other applications when a certain event occurs. They have a payload that is sent to a separate URL, providing an easy way for applications to send data to each other. Translation: a webhook is a URL that you give to another system that the program calls when there is some event that needs to be known about.

Let’s look at an example. It says you want to know every time the weather drops below 32 degrees Fahrenheit or 0 degrees Celicius and the National Weather Service offers this via webhook integration – which it didn’t, but it would be surprising if they did. You create a URL, a webhook URL, in your system that when called notifies you that the temperature has dropped. After registering this URL with the weather service, the weather service calls your URL whenever the temperature drops below 32 degrees. That’s how a webhook works.

Now let’s get into the details.

A Webhook is an HTTP callback

A webhook request is a type of user-defined HTTP callback. Event notification is actually via HTTP POST. When a certain event occurs in the source application, it triggers a webhook, and sends a message, usually in JSON or XML format, to a specified URL – the webhook URL. This message contains information about the event that just happened. A webhook is similar to an API request but is triggered by some type of event rather than a plain request call.

How Webhooks work

The process of setting up and using a webhook involves several steps:

  1. Configuration: Configure a webhook in the source application, specifying the webhook URL to which notifications should be sent and the events that should trigger the webhook. Correspondingly, configure the receiving program with the logic of what to do with the received message.
  2. Start Event: When the specified event occurs in the source application the webhook is triggered. Like new user registration, form submission, or activity.
  3. Notice: The source application generates a message and sends it to the receiving application for the specified webhook URL as an HTTP POST request.
  4. Action: The receiving application receives this message and takes action based on its content.

In the diagram below we see an example of how a webhook is triggered, generates a notification, and executes an action.

In this case, the web application has a front-end dashboard and a server. We can set up a webhook URL on the server to receive a notification that the scheduled post has been successfully published on Facebook (step 1). The webhook server receives that message (step 2), then runs the process to update some data and update the user’s dashboard (step 3). The end user gets to see the new data in the dashboard (step 4) when the post is published successfully.

A diagram showing the process of creating a web application with a webbook.

Advantages of Using Webhooks

For simple, real-time data communication, another common method of webhooks is polling. In contrast to polls, webhooks have several advantages:

  • Real time updates: Webhooks provide instant notifications, unlike polling methods that need to be checked frequently for updates. At Ayrshare, we provide a webhook that notifies you whenever a scheduled post is due for processing.
  • Good performance: They reduce server load and improve performance, as they eliminate the need for frequent polling. An example is batch processing – a webhook can be used to notify you when a task is complete.
  • Customization: You can define logic to control which events trigger webhook requests and which data is sent. Sometimes you just need some information. For example, Stripe has a great webhook offering. Instead of finding all the events happening at Stripe, and there are many, you can sign up for specific events that you care about.

Common Use Cases

Webhooks are useful for many use cases. Here are a few examples to illustrate their importance:

  1. On the basics of e-commercewebhook events are used to update order status, track shipments, and manage inventory. For example, when a customer places an order in an e-commerce web application, a webhook can trigger an update in the inventory system and notify the shipping service to ship the product.
  2. Payment platform it can notify merchants about the status of transactions, such as successful payments, transaction failures, or refunds, enabling immediate action or review by the customer.
  3. In the Customer Relationship Management Platformyou can use webhook events to send an automated email campaign based on a customer’s action.
  4. For a social media management platformyou can trigger webhook events to update the user’s dashboard when a scheduled post is successfully published in the future, like the example flow above.

Here’s an example using Ayrshare webhooks that calls a registered webhook URL when a scheduled social media post is published – i Organized Action. The following JSON is the data sent to your webhook URL:

{
    "action": "scheduled",          // The action taken
    "subAction": "tikTokPublished", // Only present when TikTok video publishing complete
    "created": "2023-01-05T01:18:47Z",
    "code": 200,                    // HTTP response code
    "refId": "140b8700bd6ade089b242d845e268fb886130c53", // User Reference ID
    "status": "success",            // success or error
    "id": "TBAAAqAMMpoweA9wKHUp",   // Ayrshare id of post
    "errors": [],                   // List of errors if any occurred
    "postIds": [                    // Individual successful posts status
        {
            "postUrl" :"
            "platform": "facebook",
            "status":"success",
            "id":"102775127855689_361718068618052"
        }
    ],
    "url": "
}

Webhook Security

Before you launch or register your wehbook, consider what webhook security you will need; it’s usually an afterthought, but webhook security is very important.

Imagine if you had a webhook that gets notified whenever the stock price drops below a certain amount. If the event is buying a sotck. Neglecting webhook security means that a bad actor can maliciously call your webhook URL forcing many unintended purchases. Wow!

You can secure your webhook by setting HMAC authentication as an HTTP request. Basically the webhook and private key submission is accelerated, e.g. using SHA256. The hash is sent along with the webhook event and you compare this to your message hash and private key. You can read more about this at the link above.

In summary…

Webhooks are often critical in many workflows where two parts of your system, or two systems need to send data when an action occurs, but they need a simple way to communicate.

As you continue your webhook journey, always remember to ensure that your webhooks are secure, and that you research what types of events or actions webhooks are available when building webhook integrations with third-party platforms.

Also check out our article on using a Webhook with a Proxy.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button