Enable Dark Mode!
how-to-use-odoo-16-webhooks-to-connect-external-systems.jpg
By: Mohd Ajmal M

How to Use Odoo 16 Webhooks to Connect External Systems

Technical Odoo 16

APIs and Webhooks provide features to sync and share different information between different software systems. The idea of both of them is the same as sharing and syncing information between the software systems, but actually, they are different. APIs are like an interface that allows two-way communication via a request response cycle between the software systems. Webhooks are a powerful tool that allows us to receive real-time updates from external systems and perform or trigger some actions within Odoo. Rather than requests, webhooks are driven by events that occur on the software systems.

In this blog, we will go through the steps required to build a real-time integration between Odoo and an external system using Webhooks.

To drive a webhook, we need some URL that needs to send data based on some event occurrence in external software systems. This URL will be provided to the external software systems along with the event which triggers the webhook. Once this event happens, a response is sent to the system pointing to the specified URL. In Odoo, the URL must point to a controller which can manipulate the received data. To create a controller, refer to How to Configure Web Controllers in Odoo 16.

As described above, once the event occurs in the external system, the response will be sent to the URL which is pointed to the Odoo controller. From here, we can manage the data received from the external software system. Mostly the incoming data will be in JSON format. This must be parsed and can be used in the controller. In the controller, we can add different actions to be performed along with this received data.

Let us look at a real example. Here, I'm using Shopify, an eCommerce platform, as an external software system. One more thing to remember is that these external systems must support webhooks. In Shopify, it supports webhooks and thus, we can use it to integrate Odoo in real-time using webhooks.

how-to-use-odoo-16-webhooks-to-connect-external-systems-1
Here in the above image, I have added a new webhook in Shopify where I specified the URL to point to the Odoo controller. In the first part, I provided the link to the Odoo instance and after that, specified the controller URL. When the event which I selected as Customer Creation happens, a call to this controller from Odoo is done. After, the code inside the controller is executed.
import json
from odoo import http
from odoo.http import request
class ShopifyWebhook(http.Controller):
    @http.route('/customer', type='json', auth='none', methods=['POST'],
                csrf=False)
    def get_webhook_url(self, *args, **kwargs):
        print('received webhook data')
        data = json.loads(request.httprequest.data)
        print('data', data)
From the above code, I have written a controller with the same URL specified on Shopify. So when the webhook call from Shopify is triggered, the above controller works.
Inside this controller, we can perform different actions and execute different methods with the received data.
how-to-use-odoo-16-webhooks-to-connect-external-systems-2
Now, when I click on the Send test notification button from Shopify, a test call is triggered and thus, the controller will get executed.
how-to-use-odoo-16-webhooks-to-connect-external-systems-3
Webhooks are a powerful tool to build a real-time integration between Odoo and external systems. By following the above steps in the blog, we can define a webhook URL using controllers in Odoo, which on occurrences of particular events in external systems, implement the controllers and trigger the provided actions within them. With this integration in place, you can automate your business processes to improve efficiency.


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment

 


whatsapp
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message