REST API for Webhook
Project description
REST API for Webhook
This module provides a standard webhook framework for Odoo with full request/response logging and config-driven outbound push notifications.
Inbound (External → Odoo)
5 REST API routes: create_data, update_data, create_update_data, search_data, call_function
Session-based and API Key authentication
Friendly relational field format: many2one, many2many, one2many resolved by name or id
auto_create support for missing related records
Automatic API log creation per request, with configurable per-route toggle
Request and response preview (first N characters, configurable) stored on the log record
Request and response size (character count) displayed on each log
Full payload stored as JSON attachment (accessible via Full Log button) when preview limit exceeded
Autovacuum cron to purge old logs, with optional chunk-based deletion
Outbound (Odoo → External)
webhook.outbound.rule - config-driven rules: which model + domain → which endpoint
webhook.outbound.mixin - add to any model with a single _inherit line; no per-model code required
Trigger domain: full Odoo domain expression evaluated after write(); webhook fires only when a record transitions into matching the domain
Endpoint source: static URL per rule, or per-record callback_url passed by the external system at create time
Payload fields: JSON list supporting field{sub1,sub2} expansion for relational fields - same syntax as search_data
Outbound calls logged in API Logs (log_type = send) with success/failed state
Table of contents
Configuration
System Parameters
Go to Settings > Technical > Parameters > System Parameters to adjust the following keys:
webhook.preview_limit (default 2000) - Maximum characters stored in the preview fields. Payloads longer than this are also saved as a full JSON attachment.
webhook.create_data_log (default True) - Enable logging for /api/create_data
webhook.update_data_log (default True) - Enable logging for /api/update_data
webhook.create_update_data_log (default True) - Enable logging for /api/create_update_data
webhook.search_data_log (default True) - Enable logging for /api/search_data
webhook.call_function_log (default True) - Enable logging for /api/call_function
webhook.rollback_state_failed (default 1) - Roll back the transaction when the API response is not successful
webhook.rollback_except (default 1) - Roll back the transaction when an unhandled exception occurs
webhook.ignore_checkcompany_model (default []) - JSON list of model names excluded from company-scoped record lookup
Outbound Webhook Rules
Go to Settings > Technical > API Configuration > Outbound Webhook Rules to configure outbound push rules.
Model - The Odoo model to watch (e.g. sale.order)
Trigger Domain - Odoo domain evaluated after write(). Webhook fires when a record transitions into matching the domain. Uses the domain widget - select a model first to get field suggestions.
Endpoint Source - Static URL - always POST to the configured URL. Record Callback URL - use the callback_url stored from the inbound request.
Endpoint URL - Required when Endpoint Source is Static URL.
Payload Fields - JSON list of field names to include. Supports field{sub1,sub2} for relational expansion. Leave empty to send {"id": <record_id>} only.
Authorization Header - Optional Authorization header value sent with every outbound request, e.g. Bearer <token>.
Usage
Before sending a REST API request to Odoo, an initial call to authenticate the API is necessary. You can achieve this by calling the /web/session/authenticate route.
The authentication format requires a header with Content-type set to application/json, and the body should include:
{
"jsonrpc": "2.0",
"method": "call",
"params": {
"db": "<db_name>",
"login": "<username>",
"password": "<password>"
}
}
Alternative Authentication Method (API Key)
As an alternative to session-based authentication, you can use an API Key for your requests. To use this method, send a header with Authorization set to Bearer <api_key> for every API route call.
Authorization: Bearer <api_key>
Relational Field Format
All relational fields follow a consistent pattern based on cardinality:
Field type |
Format |
Example |
|---|---|---|
many2one |
{"<lookup_field>": "<value>"} |
{"name": "Customer A"} or {"id": 5} |
many2many |
{"mode": "add"|"replace", "records": [{"<lookup_field>": "<value>"}]} (mode optional, defaults to "replace") |
{"records": [{"name": "Tag1"}]} or {"mode": "add", "records": [...]} |
one2many |
[{<field>: <value>, ...}, ...] |
[{"product_id": {"name": "A"}, "qty": 1}] |
The lookup field can be any indexed field on the related model (name, id, ref, etc.). Multiple many2many items sharing the same lookup field are batched into a single DB query.
Following successful authentication, you can proceed with five API routes:
/api/create_data: This route allows the creation of new data only.
{ "params": { "model": "<model name>", "vals": { "payload": { "<field1>": "<value1>", "<many2one_field_id>": {"name": "<value>"}, "<many2many_field_ids>": {"mode": "replace", "records": [{"name": "<val1>"}, {"name": "<val2>"}]}, "<one2many_field_ids>": [ { "<field>": "<value>", "<nested_m2o_id>": {"name": "<value>"} } ] }, "auto_create": { "<many2one_field_id>": {"name": "<value>", ...} }, "result_field": ["<field1>", ...] } } }/api/create_update_data: This route facilitates updating data. If the data does not exist, it will automatically create it.
{ "params": { "model": "<model name>", "vals": { "search_key": { "<key_field>": "<value>" }, "payload": { "<field1>": "<value1>", "<many2one_field_id>": {"name": "<value>"}, "<many2many_field_ids>": {"records": [{"name": "<val1>"}]} }, "result_field": ["<field1>", ...] } } }/api/update_data: This route allows updating existing data.
{ "params": { "model": "<model name>", "vals": { "search_key": { "<key_field>": "<value>" }, "payload": { "<field1>": "<value1>", "<many2one_field_id>": {"id": 5}, "<many2many_field_ids>": {"mode": "add", "records": [{"name": "<val1>"}]} } } } }/api/search_data: This route allows you to search for the value of a desired field in a model by using a search domain to find the desired recordset. You can also limit and order the resulting data.
{ "params": { "model": "<model name>", "vals": { "payload": { "search_field": ["field1", "field2", "field3{subfield1, subfield2}", ...], "search_domain": "[('field', 'operator', 'value')]", "limit": 1, "order": "field1 , field2 desc, ..." } } } }/api/call_function: This route allows you to call a function on a model object based on the provided input.
- Parameters:
name (str): The name of the model to perform the function on.
method (str): The name of the function to call.
parameter (dict, optional): Keyword arguments to pass to the function. Use named keys so order does not matter and optional parameters can be omitted.
context (dict, optional): Odoo context values merged into env.context before the method is called (e.g. lang, force_company, custom flags).
{ "params": { "model": "<model name>", "vals": { "search_key": { "<key_field>": "<value>" }, "payload": { "method": "<method>", "parameter": {"<key>": "<value>", ...}, "context": {"lang": "th_TH", "<key>": "<value>", ...} } } } }Example — confirm an invoice and set language context:
{ "params": { "model": "account.move", "vals": { "search_key": {"id": 26}, "payload": { "method": "action_post", "context": {"lang": "th_TH"} } } } }
Note: If you want to attach a file to a record, you can add the key “attachment_ids” at any level of the payload.
Example Request with Attachment:
{ "params": { "model": "<model name>", "vals": { "search_key": { "<key_field>": "value" }, "payload": { "attachment_ids": [ { "name": "<file_name>", "datas": "<base64_encoded_data>" } ], ... } } } }
Bug Tracker
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed feedback.
Do not contact contributors directly about support or help with technical issues.
Credits
Contributors
Kitti Upariphutthiphong <kittiu@ecosoft.co.th>
Saran Lim. <saranl@ecosoft.co.th>
Maintainers
This module is part of the ecosoft-odoo/ecosoft-addons project on GitHub.
You are welcome to contribute.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file odoo_addon_usability_webhooks-15.0.3.0.0-py3-none-any.whl.
File metadata
- Download URL: odoo_addon_usability_webhooks-15.0.3.0.0-py3-none-any.whl
- Upload date:
- Size: 62.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54339a9e353104feea7df9e9dee3f48385d09019f6c1513762606801c6445b9d
|
|
| MD5 |
ecd94648026ac08e07baae1e2c70d0ca
|
|
| BLAKE2b-256 |
12d8091c403f0c9cf471e3121b3fbfcdad9cc71e735136c804675c3bc7c1c354
|