Skip to main content
Odoo Community Association

WebService Core

Production/Stable License: AGPL-3 OCA/web-api Translate me on Weblate Try me on Runboat

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")  # -> bytes: the response content

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"))

Full response: call() returns response.content by default. Pass content_only=False to get the full requests.Response object instead (status code, headers, etc.):

response = backend.call("get", content_only=False)
response.status_code

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

Authors

  • Creu Blanca

  • Camptocamp

Contributors

Maintainers

This module is maintained by the OCA.

Odoo Community Association

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:

simahawk

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.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for odoo-addon-webservice-core 18.0.1.0.0.2
File Interpreter ABI Platform
odoo_addon_webservice_core-18.0.1.0.0.2-py3-none-any.whl Python 3 none any Details

Release files / odoo_addon_webservice_core-18.0.1.0.0.2-py3-none-any.whl

Download URL odoo_addon_webservice_core-18.0.1.0.0.2-py3-none-any.whl
Size 38.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
04f36937e47968e0fc49e1ee9a2b2b0b4854f206e3389af9836da53017037212
BLAKE2b-256 checksum
How to use checksums
fea833238422f4dd78174d6b7ed320dc441ef2bf32544ac9e4c98b5b4760526d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release history Release notifications | RSS feed

This release

18.0.1.0.0.2 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page