WebService Core
This module provides the webservice.backend model with its authentication (public, username/password, API key) and HTTP call features (get/post/put).
It has no dependency on component or server_environment, so it can be used as a lightweight building block by any module needing to configure and call an outbound webservice, without pulling in extra frameworks.
Table of contents
Configuration
Go to Settings > Technical > WebService Backend (requires the Administration / Settings group) and create a new backend:
Name / Technical Name: a label and a unique technical key you’ll use to look the backend up from code (e.g. env.ref is not used here; search by tech_name instead).
Protocol: only HTTP Request is available in this module.
URL: the base URL every call is relative to, e.g. https://api.example.com. It may contain {placeholder} tokens (see Usage), e.g. https://api.example.com/{endpoint}.
Content-Type: optional default Content-Type header for every call.
Then configure authentication via Auth Type:
Public: no credentials needed.
Username & password: sent as HTTP Basic Auth. Requires Username and Password.
API Key: sent as a custom header. Requires API Key and API Key header (the header name to send it under, e.g. X-Api-Key).
Required fields depend on the selected auth type; the form only shows and requires the ones that apply, and saving enforces it.
Usage
Look up the backend (e.g. by its technical name) and call it:
backend = env["webservice.backend"].search([("tech_name", "=", "my_api")])
result = backend.call("get") # -> requests.Response
result.content
result.status_code
call(method, *args, **kwargs) accepts any of the standard HTTP verbs (get, post, put, delete) and forwards everything else to requests, so any of its keyword arguments work too (data, json, params, files, …):
backend.call("post", data=b"<xml>...</xml>")
backend.call("post", json={"foo": "bar"})
URL: by default the backend’s own url is used. Pass url to hit a different path - relative paths are appended to the backend’s URL, a full http(s):// URL is used as-is:
backend.call("get", url="orders") # -> <backend url>/orders
backend.call("get", url="https://other.example.com/orders")
If the backend’s URL (or the url passed above) contains {placeholder} tokens, fill them with url_params:
# backend.url == "https://api.example.com/{endpoint}"
backend.call("get", url_params={"endpoint": "orders"})
Headers: pass headers to add/override headers for that call; they are merged on top of the backend’s own Content-Type and auth-derived headers (e.g. the API key header):
backend.call("get", headers={"X-Request-Id": "42"})
Auth override: pass auth to bypass the backend’s configured auth type for a single call (same format requests itself accepts, e.g. a (user, password) tuple):
backend.call("get", auth=("other_user", "other_password"))
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
Simone Orsi <simone.orsi@camptocamp.com>
Enric Tobella <etobella@creublanca.es>
Alexandre Fayolle <alexandre.fayolle@camptocamp.com>
Maintainers
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
Current maintainer:
This module is part of the OCA/web-api project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Release files for odoo-addon-webservice-core 18.0.1.0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| odoo_addon_webservice_core-18.0.1.0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Release files / odoo_addon_webservice_core-18.0.1.0.1.1-py3-none-any.whl
| Download URL | odoo_addon_webservice_core-18.0.1.0.1.1-py3-none-any.whl |
|---|---|
| Size | 39.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e990e03db53ee7393c78abdd52f5a183ca32830b7840adf01d6d0d0f9a3b3759
|
|
BLAKE2b-256 checksum How to use checksums |
719e39fc744b6494adc5315abc148f52e6d2e753179ec991bdd347f448d5a92b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|