We are often asked about webhooks and if Shotstack uses them. And the answer to that is yes, we do. We know that time is of the essence when creating and distributing videos, especially at scale and we’ve put together the guide below to give you an overview of what a webhook is and how to use them, if you haven’t before.
Introduction
As developers in the video space, we often require real-time communication between various applications and services to create seamless experiences for our users. Webhooks are an essential tool for achieving this goal, allowing instant notifications and actions to be triggered by specific events. In this blog post, we'll explore what webhooks are, how they work, and dive into some practical use cases tailored specifically for video applications.
What are Webhooks?
Webhooks are user-defined HTTP callbacks that facilitate real-time communication between applications. They enable one application to send an automatic message, or "payload", to another application when a specific event occurs. By using webhooks, applications can receive instant notifications without the need for constant polling or repeated API queries.
How Do Webhooks Work?
Webhooks follow a simple yet effective process:
- Event triggers: An event occurs in the source application, such as a video upload or a live stream starting.
- Payload creation: The source application creates a payload, which is a JSON or XML object containing relevant data about the event.
- HTTP request: The source application sends an HTTP POST request, containing the payload, to a pre-configured URL (the webhook's endpoint) in the target application.
- Data processing: The target application receives the webhook's payload, processes the data, and performs the predefined action(s) based on the information received.
- Response: The target application sends an HTTP response back to the source application to acknowledge receipt of the webhook. This response doesn't necessarily need to contain any data but should have an appropriate status code (e.g., 200 OK) to indicate successful processing.
Video-centric Use Cases
Webhooks can play a significant role in enhancing video applications. Some use cases specific to the video domain include:
- Video processing notifications: Webhooks can notify users or other services when a video has finished processing, allowing for actions like sending a notification to subscribers or updating video metadata.
- Live stream monitoring: Webhooks can trigger alerts when a live stream starts or ends, enabling real-time monitoring of streaming events and facilitating instant notifications to viewers.
- Comment moderation: Webhooks can help automate comment moderation on video platforms by triggering actions, such as flagging or hiding inappropriate comments, based on predefined criteria.
- Video analytics: Webhooks can send real-time video performance data to analytics platforms, allowing developers to monitor video engagement, view counts, and other important metrics.
- Third-party integrations: Webhooks can help integrate video platforms with external services like content management systems (CMS), customer relationship management (CRM) tools, or marketing automation platforms, enabling seamless synchronisation of data and actions across applications.
Security Considerations
When working with webhooks in video applications, it's crucial to implement appropriate security measures to protect your data and infrastructure. Some best practices include:
- HTTPS: Always use HTTPS to encrypt the data transmitted between the source and target applications.
- Secret tokens: Use a secret token to authenticate the webhook's payload. The token should be known only to the source and target applications and should be included in the HTTP request header.
- IP whitelisting: Restrict incoming webhook requests to specific IP addresses or IP ranges that belong to the source application.
- Validate payloads: Verify that the received payload matches the expected format and structure before processing it.
Conclusion
Webhooks offer a powerful solution for real-time communication in video applications, enabling instant notifications and actions based on specific events. By understanding how webhooks work and implementing them with security best practices in mind, you can enhance your video applications and create more engaging experiences for your users.
Sign up for your Shotstack account now and create thousands of bespoke, data-driven videos in minutes.
Get started with Shotstack's video editing API in two steps:
- Sign up for free to get your API key.
- Send an API request to create your video:
curl --request POST 'https://api.shotstack.io/v1/render' \
--header 'x-api-key: YOUR_API_KEY' \
--data-raw '{
"timeline": {
"tracks": [
{
"clips": [
{
"asset": {
"type": "video",
"src": "https://shotstack-assets.s3.amazonaws.com/footage/beach-overhead.mp4"
},
"start": 0,
"length": "auto"
}
]
}
]
},
"output": {
"format": "mp4",
"size": {
"width": 1280,
"height": 720
}
}
}'