410.37

v 15.0 Third Party
Lines of code 833
Technical Name six_api_rest
LicenseSee License tab
Websitehttps://sixphere.com
Also available in version v 14.0
You bought this module and need support? Click here!
Lines of code 833
Technical Name six_api_rest
LicenseSee License tab
Websitehttps://sixphere.com
Also available in version v 14.0

SIXPHERE RESTful API

Overview

Are you tired of wasting hours accessing data or integrating your systems with your ERP?

The API REST module by Sixphere provides you an easy way to create fucntional endpoints, building for you a very practical abstracted layer over the complex Odoo data model. No more tricky integrations with other systems that force them to know how Odoo is working, using the very friendly way this module allows you to create and link endpoints, you can build a business layer on you Odoo just in a couple of steps.

Key features

  • Create your own endpoints and implement specific CRUD operations for each one.
  • Provide 'query' parameters to set the fields are wanted to be returned.
  • Provide 'nested' parameters to set the fields are wanted to be expanded before the output is returned.
  • Provide 'filter' parameters to set domain filters to be applied before the output is returned.
  • Set the correct version for each endpoint in order to control different versions.
  • Active only the verbs are requiered for each use case.
  • Create endpoints to implement bulk UPDATE and bulk DELETE operations on a set of records.
  • Create endpoints to implement PATCH operations, to execute internal Odoo methods and functions.
  • Override the code executed in POST, PUT and PATCH verbs.
  • Create second level endpoints to access child properties of a record.
  • Tag and describe the endpoint to be documented automatically using Swagger.
  • Access the endpoints using user credentials or API keys.
  • Use the pre-installed endpoints to directly access the main Odoo functionalities.

Support

Start your digitalization here. We want to listen to you, understand your necessities, and provide you with the best solution.

Reach us at: Sixphere.com

Drop us a message at: codelovers@sixphere.com

Odoo API RestFull module by Sixphere

New API Rest section is enabled for administrators, for creating endpoints to any Odoo model. Below features are available:

  • Create endpoints to implement all CRUD operations.
  • Provide "query" parameters to set the fields are wanted to be returned.
  • Provide "nested" parameters to set the fields are wanted to be expanded before the output is returned.
  • Provide "filter" parameters to set domain filters to be applied before the output is returned.
  • Set the correct version for each endpoint in order to control different versions.
  • Active only the verbs are required for each use case.
  • Create endpoints to implement bulk UPDATE and bulk DELETE operations on a set of records.
  • Create endpoints to implement PATCH operations, to execute internal Odoo methods and functions.
  • Override the code executed in POST, PUT and PATCH verbs.
  • Create second level endpoints to access child properties of a record.
  • Tag and describe the endpoint to be documented automatically using Swagger.
  • Access the endpoints using user credentials or API keys.

Previous Requirements

This module requires python modules cryptography and numpy, execute the code below to install them:

pip install cryptography
pip install numpy

Getting Started

After the module is installed, a section named API REST is avilable in the root menu only for administrator users. Two subsections are available:

  • Endpoints, in which the endpoints can be managed. See section [Preinstalled Endpoints](#preinstalled_endpoints) to know the preinstalled endpoints.
  • Documentation, to access the Swagger documentation. This documentation is automatically generated.
API REST

Create a new endpoint

Let's create a new endpoint to list the products.

  1. Access endpoint section and click on Create button
  2. Name the endpoint as "products" and set the field "relation" as "product.product"
  3. Save the changes and go to the section Documentation. A new set of endpoint related with products have been created.
API Documentation

Since a Odoo session is opened, endpoints can be accessed without any key. Follow the below sections to know how to access them externally.

Access endpoints externally using an API Key

To generate an API Key go to user's preferences section and generate e new developer API Key. The full path is: UserPreferencesAccount SecurityDeveloper API KeysNew API Key

Create API Key

This API key can be use in the Swagger documentation env or directly as an authorization header. For example:

curl --location --request GET 'http://localhost:8069/api/v1/products' --header 'Authorization: <API KEY>'

Access endpoints externally using user's credentials

There is a core endpoint to get a session_id providing the user's credentials. The syntax is:

curl --output /dev/null --cookie-jar - --location --request POST 'http://localhost:8069/auth' --header 'Content-Type: application/json' --data-raw '{"params": {"db": <DB NAME>, "login": <USER NAME>, "password": <USER PASSWORD>}}'

The output returned by this call should be like:

#HttpOnly_localhost FALSE / FALSE 1662886711 session_id <SESSION_ID>

The session_id key can be used as cookie to grant access user. For example:

curl --location --request GET 'http://localhost:8069/api/v1/products' --header 'Cookie: session_id=<SESSION_ID>'

Code override for POST, PUT and PATCH verbs

These verbs are available to be overrided. This allows to implement complex behaviours, for example, create an invoice with its lines in the same single call.

Any Python code can be set to override these verbs. The following variables can be used in the Python code:

  • endpoint_record. The endpoint record stored in the database in which the verb code is being overrided.
  • parent_id. The id of the parent record for endpoints with a parent endpoint.
  • params. The request body content.
  • data_service. CRUD library service.
    • data_service.post_model_data(model, **param). Method to create a new instance of the model.
    • data_service.put_model_record(model, rec_id, **params). Method to update an existing instance of the model.
    • data_service.put_model_records(model, **params). Method to update ALL instances of the model.
    • data_service.delete_model_record(model, rec_id). Method to delete an existing instance of the model.
    • data_service.delete_model_records(model, rec_id, **params). Method to delete ALL instances of the model,
    • data_service.call_obj_function(model, rec_id, function, **params). Method to call a function on an existing instance of the model.
  • results. Array to store results to be returned to the main process. If results array is not empty, the main process WILL NOT execute the POST operation. Appending values to results, code can be executed before and after the record is created.
  • logger. Logging service.
  • exceptions. Odoo exceptions namespace.

Example:

The next code can be use to override the POST verb in the invoices endpoint. It manages the param 'invoice_lines' in the request body in order to create those lines, and assign them to the created invoice.

def _set_taxes(line):
  taxes = line._get_computed_taxes()
  if taxes and line.move_id.fiscal_position_id:
    taxes = line.move_id.fiscal_position_id.map_tax(taxes, partner=line.partner_id)
  line.tax_ids = taxes
# if invoice lines data is found on the body
# the lines are created and assigned to the invoice
try:
  data = params['data']
except KeyError:
  msg = "`data` parameter is not found on POST request body"
  raise exceptions.ValidationError(msg)
try:
  data['move_type']
except KeyError:
  msg = "`move_type` parameter is not found on POST request body. It has to be placed on 'data' dictionary"
  raise exceptions.ValidationError(msg)
if 'invoice_lines' in data:
  for line in data['invoice_lines']:
    if 'account_id' not in line:
      msg = "`account_id` has to be set for every invoice line"
      raise exceptions.ValidationError(msg)
  invoice_lines = data['invoice_lines']
  del data['invoice_lines']
else:
  invoice_lines = []
created_invoice = data_service.post_model_data('account.move', **params)
results.append(created_invoice)
for line in invoice_lines:
  line['move_id'] = created_invoice.id
  created_line = data_service.post_model_data('account.move.line', **{'data': line, 'context': {'check_move_validity': False}})
  _set_taxes(created_line)
# Recompute lines tax
data_service.call_obj_function('account.move', created_invoice.id, '_recompute_dynamic_lines', **{
    'kwargs': {
        'recompute_all_taxes': True,
        'recompute_tax_base_amount': True
    },
    'context': {
        'check_move_validity': False}
})

Licenses

The module needs to get a license in order to run correctly. To obtain a license, please contact us at codelovers@sixphere.com

Registering a new license could be done in Settings → API REST

API License

Preinstalled Endpoints

The module provides this set of preinstalled endpoints:

  • Accounts. To access accounts information.
  • Customers. To access and manage customers information.
    • Invoices. To access customer's invoices.
    • Sales. To access customer's sales.
  • Deliveries. To access information about inventory delivery orders.
  • Invoices. To access and manage in and out invoices.
  • Manufacturing orders. To access manufacturing orders info.
    • Work orders. To access info about the work orders of a manufacturing order.
  • Projects. To access and manage projects info.
    • Stages. To access and manage the stages of a project.
    • Tasks. To access and manage the tasks of a project.
  • Purchases. To access and manage purchases info.
  • Receptions. To access information about inventory receptions orders.
  • Sales. To access and manage sales info.
  • Suppliers. To access and manage suppliers info.
    • Invoices. To access supplier's invoices.
    • Purchases. To access supplier's purchases.
  • Work centers. To access manufacturing work centers info.
Swagger Docs

Support

Start your digitalization here. We want to listen to you, understand your necessities, and provide you with the best solution.

Reach us at: Sixphere.com

Drop us a message at: codelovers@sixphere.com

Sixphere Technologies Proprietary License v1.0
This software and associated files (the "Software") may only be used
(executed, modified, executed after modifications) if you have
purchased a valid license from Sixphere Technologies SL.
The above permissions are granted for a single database per purchased
license. Furthermore, with a valid license it is permitted to use the
software on other databases as long as the usage is limited to a testing
or development environment.
You may develop modules based on the Software or that use the Software
as a library (typically by depending on it, importing it and using its
resources), but without copying any source code or material from the
Software. You may distribute those modules under the license of your
choice, provided that this license is compatible with the terms of the
Sixphere Technologies Proprietary License (For example: LGPL, MIT, or
proprietary licenses similar to this one).
It is forbidden to publish, distribute, sublicense, or sell copies of
the Software or modified copies of the Software.
The above copyright notice and this permission notice must be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

Please log in to comment on this module

  • The author can leave a single reply to each comment.
  • This section is meant to ask simple questions or leave a rating. Every report of a problem experienced while using the module should be addressed to the author directly (refer to the following point).
  • If you want to start a discussion with the author or have a question related to your purchase, please use the support page.