Skip to main content
Odoo Community Association

Base External API

Beta License: AGPL-3 sygel-technology/sy-server-backend

This module provides tools for other modules to use the requests library for making external API calls.

With this module, you can:

  • Create an external API record and configure its URL and authentication_method parameters

  • Log every API call

  • Make asynchronous calls

  • Delete the API logs with an scheduled action

Table of contents

Usage

To use this module, you need to create a new module with:

  1. A data file that creates an External API Config with an external ID.

  2. A python file with code that gets the External API Config and uses it to make an external call with the call() or queued_call() methods.

Some use cases of this module would be sending every new res partner record to, or sending every update in the price of the products, to a remote API.

The code of the first example would look like this:

<odoo noupdate="1">

    <record id="your_external_api_external_id" model="external.api.config">
        <field name="name">Your API Name</field>
        <field name="base_url">https://www.test.com</field>
    </record>

</odoo>
class ResPartner(models.Model):

    _inherit = "res.partner"

    def create(self, vals):
        recs = super().write(vals)
        if SYNCED_FIELDS.intersection(vals):
            for rec in recs:
                partner_json = rec.json()  # Custom function to complete
                self.env.ref(
                    'your_module.your_external_api_external_id'
                ).queued_call(
                    method="post",
                    url="/partner/create",
                    data=partner_json
                )
        return res

To configure the schedule action that deletes logs you need to:

  1. Go to Settings / Technical / Scheduled Actions

  2. Go to the ‘External Api Logs Cleanup’ scheduled action

  3. You can edit the execution interval or the function params

  4. You can manually test the scheduled action.

  5. You can manually edit the parameters of the scheduled action’s function to customize the behaviour. Important fields:

    • server_timeout_seconds: Max time for the scheduled action. If you have edited your server’s timeout_seconds, you’ll have to manually edit this field

    • batch_size: Number of records to delete at the same time. Take into account, that this value should be low enough to delete at least one batch in the server_timeout_seconds

    • model: you can edit the model parameter to delete other sytem logs

    • write_logs: If you set this to True, logs will be printed showing the number of deleted logs

Known issues / Roadmap

  • This module could be extended to add the external_api_endpoint model, with the purpose to store in the database the diferent urls of the same API we can call, and some configuration data or extra information.

  • This module does have a custom logger that can print logs in your console or log file. You can manually enable/disable those logs (Explained in the USAGE section). However, developing an upgrade to simplify the log enable/disable whould be a nice improvement.

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

  • Sygel

Contributors

  • Sygel:

    • Alberto Martínez

    • Valentin Vinagre

    • Harald Panten

Maintainers

This module is part of the sygel-technology/sy-server-backend project on GitHub.

You are welcome to contribute.

Metadata

Release files for odoo-addon-base-external-api 17.0.1.2.1.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-base-external-api 17.0.1.2.1.2
File Interpreter ABI Platform
odoo_addon_base_external_api-17.0.1.2.1.2-py3-none-any.whl Python 3 none any Details

Release files / odoo_addon_base_external_api-17.0.1.2.1.2-py3-none-any.whl

Download URL odoo_addon_base_external_api-17.0.1.2.1.2-py3-none-any.whl
Size 48.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aec1459a154d8350a47d3baefdc55807aba7cf6c8c5f8f84efc667c187bb3b6f
BLAKE2b-256 checksum
How to use checksums
6a78a6a8c0f8416496f1fb7d3c93f2aca6be359e30f5d945b4cbc52cf024b63d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

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