An application is rarely used by itself in today's software stack. These days, businesses use a variety of software programs, including customer relationship management software, e-commerce websites, payment gateways, and ERP systems. To exchange data, these software systems must communicate with one another. This is the point at which webhooks become very potent. A webhook enables an application to send data to another application based on a particular event rather than requesting data from another application. When used to create software system integrations, like those found in an ERP environment like Odoo, this feature is incredibly potent.
Developers now have more options to use event-driven communication between Odoo and other software systems thanks to Odoo 19. When a particular Odoo event takes place, like when a sales order is created, a customer is updated, or a payment is confirmed, developers can use webhooks to send notifications to third-party software systems. Because it eliminates needless API calls between software systems, this feature is incredibly potent. The creation of webhooks in Odoo 19 will be discussed in this blog. We will also look at the development of software system integrations using webhooks.
Let’s Understand Webhooks
A straightforward yet effective method of enabling real-time communication between Odoo and external apps is through webhooks. A webhook enables Odoo to automatically alert another system whenever a particular event takes place, as opposed to continuously polling the Odoo database for updates. Integrations become much more efficient, quicker, and require fewer resources as a result.
Webhooks can be implemented in Odoo 19 by building a controller that exposes an endpoint and initiates HTTP requests whenever a system event takes place. The practical steps needed to implement webhooks in Odoo are covered in this section.
1. Understanding the Webhook Workflow
It is helpful to comprehend how the webhook process operates before putting the feature into practice.
In Odoo, a typical webhook flow looks like this:
- In Odoo, an event takes place (like the creation of a sales order).
- Odoo uses automation or custom logic to identify the event.
- A configured external URL receives an HTTP request from Odoo.
- After receiving the request, the data is processed by the external application.
Without requiring constant API requests, this event-driven strategy guarantees that external systems receive updates instantly.
2. Creating a Custom Module
To implement webhooks, the first step is to create a custom Odoo module. This module will contain the logic responsible for sending webhook notifications.
A typical module structure might look like this:
odoo_webhook_integration/
¦
+-- __init__.py
+-- __manifest__.py
+-- controllers/
¦ +-- webhook_controller.py
+-- models/
¦ +-- sale_order.py
The module will contain two main components:
- Controller – to handle webhook endpoints.
- Model extension – to trigger webhook events when specific actions occur.
3. Creating a Webhook Controller
Odoo controllers allow external systems to interact with the Odoo server through HTTP routes. By defining a route, you create an endpoint that can receive webhook requests or send responses.
Example controller:
from odoo import http
from odoo.http import request
class WebhookController(http.Controller):
@http.route('/webhook/receive', type='json', auth='public', methods=['POST'], csrf=False)
def receive_webhook(self, **kwargs):
data = request.jsonrequest
if data:
# Process received data
return {'status': 'success', 'message': 'Webhook received'}
return {'status': 'error', 'message': 'No data received'}
In this example:
- A route /webhook/receive is created.
- The endpoint accepts POST requests.
- Incoming JSON payloads are processed using request.jsonrequest.
This endpoint can now receive webhook data from external services.
4. Triggering Webhooks from Odoo Events
The next step is sending webhook notifications when specific events occur inside Odoo. This is usually implemented by extending an existing model.
For example, we can trigger a webhook whenever a Sales Order is created.
import logging
import requests
from odoo import models
_logger = logging.getLogger(__name__)
class SaleOrder(models.Model):
_inherit = 'sale.order'
def create(self, vals):
order = super(SaleOrder, self).create(vals)
webhook_url = "https://example.com/webhook"
payload = {
"order_id": order.id,
"customer": order.partner_id.name,
"total": order.amount_total
}
_logger.info("Webhook Triggered for Sale Order ID: %s", order.id)
_logger.debug("Webhook Payload: %s", payload)
try:
response = requests.post(webhook_url, json=payload, timeout=10)
_logger.info(
"Webhook sent successfully for Order ID %s | Status Code: %s",
order.id, response.status_code
)
if response.status_code != 200:
_logger.warning(
"Unexpected response from webhook for Order ID %s | Response: %s",
order.id, response.text
)
except requests.exceptions.RequestException as e:
_logger.error(
"Webhook failed for Order ID %s | Error: %s",
order.id, str(e)
)
return order
In this example:
- The create() method of the sale.order model is overridden.
- Whenever a sales order is created, Odoo sends a POST request to the webhook URL.
- The payload contains important order details.
This allows external systems to instantly receive updates whenever new orders are generated.
5. Best Practices for Implementing Webhooks
When implementing webhooks in production environments, it is important to follow certain best practices to ensure reliability and security.
Use authentication mechanisms
Webhook endpoints should not always be publicly accessible. Implement token-based authentication or API keys to verify requests.
Handle failures gracefully
Network failures can occur. Instead of letting errors interrupt the main process, implement retry mechanisms or logging.
Keep payloads lightweight
Send only the necessary data required by the receiving system. Large payloads increase processing time and network load.
Log webhook activity
Maintaining logs of webhook requests helps track integrations and troubleshoot issues when they occur.
6. Common Use Cases for Webhooks in Odoo
Webhooks are widely used in real-world integrations. Some common examples include:
- Syncing new orders with an external fulfillment system
- Sending customer updates to a CRM platform
- Notifying payment gateways when invoices are created
- Updating inventory levels in connected e-commerce stores
- Triggering notifications in messaging platforms like Slack
By leveraging webhooks, Odoo can function as part of a larger digital ecosystem where systems communicate instantly and efficiently.
With this approach, developers can build integrations that react immediately to business events, eliminating delays and reducing the need for constant API polling.
A useful and effective method for creating real-time integrations between Odoo and other systems is through webhooks. They enable instantaneous communication between applications whenever significant events take place rather than depending on recurrent API requests. By defining HTTP controllers and initiating requests from model events, developers can quickly implement webhook functionality in Odoo 19. This method minimizes needless server load while simultaneously increasing system responsiveness. Webhooks can become a dependable part of contemporary Odoo integrations by adhering to appropriate implementation procedures, such as protecting endpoints, managing failures, and keeping payloads light. Knowing how to use webhooks in Odoo can help developers create more scalable and responsive solutions as businesses rely more and more on connected platforms.
To read more about How to Use Odoo 18 Webhooks to Connect External Systems, refer to our blog How to Use Odoo 18 Webhooks to Connect External Systems.