v 13.0 Third Party 11 479
Download for v 13.0 Deploy on Odoo.sh
Included Dependencies
Lines of code 1941
Technical Name openapi
LicenseLGPL-3
Websitehttps://apps.odoo.com/apps/modules/13.0/openapi/
Also available in version v 11.0 v 12.0 v 10.0 v 14.0 v 8.0
You bought this module and need support? Click here!
Included Dependencies
Lines of code 1941
Technical Name openapi
LicenseLGPL-3
Websitehttps://apps.odoo.com/apps/modules/13.0/openapi/
Also available in version v 11.0 v 12.0 v 10.0 v 14.0 v 8.0

REST API/OpenAPI/Swagger

Secure tool for convenient integrations

Version: v13.0.1.2.3


Tested and maintained by
IT Projects Labs
Assitance: help@itpp.dev

Key features:
  • Full control over granted access via API
  • Requests/Responses made over API are logged with required level of details: full/short/disabled
  • API specification which is supported by dozens tools, platforms and services

Easy to use in any programming languages

# https://github.com/Yelp/bravado
from bravado.requests_client import RequestsClient
from bravado.client import SwaggerClient
http_client = RequestsClient()
http_client.set_basic_auth('yourdomain.example.com', 'DATABASE-NAME', 'USER-TOKEN')
odoo = SwaggerClient.from_url(
    'https://yourdomain.example.com/api/v1/demo/swagger.json?token=demo_token&db=source',
    http_client=http_client
)
result = odoo.res_partner.callMethodForResPartnerModel(
    method_name="search",
    body={
        'args': [[('email', '=', 'apps@itpp.dev')]]
    }
).response().incoming_response.json()
partner_id = result and result[0]
if not partner_id:
    result = odoo.res_partner.addResPartner(body={
        "name": "OpenAPI Support",
        "email": "apps@itpp.dev"
    }).response().result
    partner_id = result.id
odoo.res_partner.callMethodForResPartnerSingleRecord(
  id=partner_id,
  method_name="message_post",
  body={
    "kwargs": {
      "body": "The Openapi module works in Python! Thank you!",
      "partner_ids": [partner_id]
    }
  }
).response()
Comming soon...
Comming soon...
Comming soon...
Comming soon...
Comming soon...

Choose a platform that fit your needs

AWS Lambda is a serverless autoscalable platform to execute your code. For a simple integration as well as cases when you want to use any of AWS Services it's the best option. No extra module is needed! Check out detailed instruction:

  • Create Notes in Odoo from messages sent to Telegram bot

Syndesis is an integration platform. Syndesis allows to make data mapping from/to Odoo without any programming. No extra module is needed! Check out detailed intruction:

  • Odoo2odoo integration (via Syndesis)

Dataiku is platform to analyze data. No extra module is needed! Check out detailed instruction:

  • Analyzing Odoo GEO Information in Dataiku

Power BI is a service to visualize and analyzing data. No extra module is needed! Check out detailed intruction:

  • Analyzing Odoo GEO Information in Power BI
RESTAPI/OpenAPI vs RPC
    Our implementation of RESTAPI/OpenAPI has the following advantages over the built-in RPC functionality::
  • A lot of utilities supports OpenAPI
  • You can restrict access to the specific models and its methods
  • You can make authorization through tokens (without passwords)
  • You can make requests with the one request

    (for example, in RPC you need to be authorized first, then get uid...)

Need more? Anything with REST API support can be connected to Odoo just with this module!

As a buyer, you are granted to use the module in as many Odoo instances as you need!
Are you not very much aware of API stuff?
You may send this page to your IT guys to evaluate the possibilities or tell us your concerns

REST API/Openapi/Swagger

Installation

  • Install this module in a usual way

  • Add openapi to --load parameter, e.g.:

    ./odoo-bin --workers=2 --load openapi,base,web --config=/path/to/odoo.conf
    
    • Note: Skipping this step may lead to error response:

      werkzeug.exception.BadRequest: 400 Bad Request <..> :
      Function declared as capable of handling request of type 'apijson' but called with a request of type 'json'
      

Configuration

Activating and customization

  • Open menu [[ OpenAPI ]] >> OpenAPI >> Integrations

  • Click [Create]

  • Specify Name for integration, e.g. test

  • Set Log requests to Full

  • Set Log responses to Full

  • In Accessable models tab click Add an item

    • Set Model, for example res.users

    • Configure allowed operations

      • [x] Create via API

        • Set Creation Context Presets, for example
          • Name: brussels
          • Context: {"default_tz":"Europe/Brussels", "default_lang":"fr_BE"}
      • [x] Read via API

        • Set Read One Fields -- fields to return on reading one record

        • Set Read Many Fields -- fields to return on reading multiple records

          Note: you can use Export widget in corresponding Model to create Fields list. To do that:

          • Open menu for the Model
          • Switch to list view
          • Select any record
          • click [Action] -> Export
          • Set Export Type to Export all Data
          • Add the fields you need to right column
          • Click Save fields list, choose name and save the list
          • Now the list is availab to set Read One Fields, Read Many Fields settings
      • [x] Update via API

      • [x] Delete via API

  • Click [Save]

  • Copy Specification Link to use it in any system that support OpenAPI

Authentication

  • Activate Developer Mode
  • Open menu [[ Settings ]] >> Users & Companies >> Users
  • Select a user that will be used for iteracting over API
  • In Allowed Integration select some integrations
  • Copy OpenAPI Token to use it in any system that support OpenAPI

If necessary, you can reset the token by pressing [Reset OpenAPI Token] button

Usage

Swagger Editor

As the simplest example, you can try API in Swagger Editor. It allows to review and check API

  • Open http://editor.swagger.io/
  • Click menu File >> Import URL
  • Set Specification link
  • RESULT: Specification is parsed succefully and you can see API presentation
  • Click [Authorize] button
    • Username -- set database name
    • Password -- set OpenAPI Token (how to get one is described in authentication above)
Note:

The Swagger Editor sends requests directly from browser which leads to CORS error and work with it is not available in odoo.sh. The easiest solution is to simply copy-past the curl command from Swagger Editor and run it from the terminal.

Alternatively, you can grant CORS headers in your web server. Below is example for Nginx:

location /api/v1 {
   if ($request_method = 'OPTIONS') {
      add_header 'Access-Control-Allow-Origin' '*';
      add_header 'Access-Control-Allow-Credentials' 'true';
      add_header 'Access-Control-Max-Age' 1728000;
      add_header 'Content-Type' 'text/plain charset=UTF-8';
      add_header 'Content-Length' 0;
      return 204;
   }
   if ($request_method = 'POST') {
      add_header 'Access-Control-Allow-Origin' '*';
      add_header 'Access-Control-Allow-Credentials' 'true';
   }
   if ($request_method = 'GET') {
      add_header 'Access-Control-Allow-Origin' '*';
      add_header 'Access-Control-Allow-Credentials' 'true';
   }
}

How to call methods with arguments via API

Here is an example of calling a search method with domain.

This is how it is usually done from python code:

partner_ids = self.env["res.partner"].search([("is_company", "=", "True")])

On using API it would be as following:

curl -X PATCH "http://example.com/api/v1/demo/res.partner/call/search" -H "accept: application/json" \
-H "authorization: Basic BASE64_ENCODED_EXPRESSION" -H "Content-Type: application/json" \
-d '{ "args": [[["is_company", "=", "True" ]]]}'

Updating existing record

For example, to set phone value for a partner, make a PUT request in the following way:

curl -X PUT -H "Authorization: Basic BASE64_ENCODED_EXPRESSION" \
-H "Content-Type: application/json" -H "Accept: */*" \
-d '{ "phone": "+7123456789"}' "http://example.com/api/v1/demo/res.partner/41"

To set many2one field, you need to pass id as a value:

curl -X PUT -H "Authorization: Basic BASE64_ENCODED_EXPRESSION" \
-H "Content-Type: application/json" -H "Accept: */*" \
-d '{ "parent_id": *RECORD_ID*}' "http://example.com/api/v1/demo/res.partner/41"

For more examples visit https://itpp.dev/sync website

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, please use the developer contact information. They can usually be found in the description.
Please choose a rating from 1 to 5 for this module.
Fix error please
by
Jatin Naguri
on 3/11/21, 3:50 PM

Hi, I set up your api using docs, then make GET /api/v1/demo/account.move request, and got this error:

500 INTERNAL SERVER ERROR
...
Traceback (most recent call last):
  File "/home/jatin/erp-tests/dev/openapi/controllers/pinguin.py", line 375, in controller_method_wrapper
    response = controller_method(*iargs, **ikwargs)
  File "/home/jatin/erp-tests/dev/openapi/controllers/api.py", line 106, in read_multi__GET
    conf = pinguin.get_model_openapi_access(namespace, model)
  File "/home/jatin/erp-tests/dev/openapi/controllers/pinguin.py", line 551, in get_model_openapi_access
    res["method"]["main"]["whitelist"].append(method)
KeyError: 'method'

Could you fix this bug please

Re: Fix error please
by
Elizaryev Ivan Nikolaevich
on 3/14/21, 10:07 AM Author

Hello

We cannot reproduce the error. If you have more details, contact at by email help@itpp.dev


bad
by
Salman Uddin
on 1/23/21, 10:23 AM

Untested App. I delete one bank acount but almost all records deleted! Very bad((

Re: bad
by
Elizaryev Ivan Nikolaevich
on 1/25/21, 11:58 PM Author

Hello!

I am sad that you have encountered difficulties using our application.

The module allows you to run Odoo functions using api and you may have called the method incorrectly. Write to our support, I think everything is fixable: help@itpp.dev


Nice!
by
Miku Laitinen
on 9/7/20, 1:52 PM

Very intuitive and powerful module. You can easily hook up Odoo to Postman or any other Swagger compatible HTTP client.

Re: Nice!
by
Elizaryev Ivan Nikolaevich
on 9/10/20, 1:59 AM Author

Thank you very much for your feedback, we are appreciate it. We continue to work on the module, stay tuned!


by
Naran
on 3/28/21, 9:25 AM

Thank you for the pointer, got it.


by
Naran
on 3/25/21, 8:29 AM

Hi,

Does this support x2many and many2x nested fields..?

Thanks,

Naran

Re:
by
Elizaryev Ivan Nikolaevich
on 3/28/21, 5:41 AM Author

Hello Naran,

yes, you can read nested fields. Check method search_read_nested in base_api module: https://apps.odoo.com/apps/modules/13.0/base_api/


by
Thang Duong Bao
on 3/20/21, 1:28 PM

Yes, I'm sure the request reaches server, the bug just happen only on one record of model res.partner, when it happen, the record cannot edit event with Odoo app, I tried restart Odoo server and Postgresql server but it still the same (like record has been lock). 

I'm not sure it's will happen again when or where, so I avoid using PUT api request, but change to using PATCH request with write method instead.

May be the bug by Odoo or database, may be just a special case.


PUT request not response
by
Thang Duong Bao
on 3/19/21, 4:22 AM

I try update record using PUT request, ex: PUT /api/v1/test-site/res.partner/28964

body={"name": "Test Name", "mobile": "123456789"}

but odoo server not response.

Re: PUT request not response
by
Elizaryev Ivan Nikolaevich
on 3/20/21, 11:50 AM Author

Hello, are you sure that the request reaches Odoo? Could you send us server logs?

help@itpp.dev


by
Fabio Tielen
on 2/18/21, 1:00 PM

Any information about an upcoming v14 version? 

Or will this version v13 still work with v14 also? 


Thanks!

Re:
by
Elizaryev Ivan Nikolaevich
on 2/24/21, 2:46 AM Author

Hello!

module migration in progress, you can write to us by e-mail to get more information:

help@itpp.dev

Regards


SWAGGER CORS Problem
by
Lukasz87
on 10/30/20, 5:45 AM

If someone have problem with CORS, this is a solution for NGINX:

# Add headers for location from nginx-extras
 more_set_headers 'Access-Control-Allow-Origin: $http_origin';
 more_set_headers 'Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, PATCH, DELETE, HEAD';
 more_set_headers 'Access-Control-Allow-Credentials: true';
 more_set_headers 'Access-Control-Allow-Headers: Content-Type, api_key, Authorization';



location /api/v1 {
   proxy_pass http://127.0.0.1:8069;

   if ($request_method = 'OPTIONS') {
       more_set_headers 'Access-Control-Allow-Origin: $http_origin';
       more_set_headers 'Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, PATCH, DELETE, HEAD';
       more_set_headers 'Access-Control-Max-Age: 1728000';
       more_set_headers 'Access-Control-Allow-Credentials: true';
       more_set_headers 'Access-Control-Allow-Headers: Content-Type, api_key, Authorization';
       more_set_headers 'Content-Type: text/plain; charset=UTF-8';
       more_set_headers 'Content-Length: 0';
       return 204;
   }

}


REST API - AWS Lambda
by
Mayte Montaño
on 9/15/20, 12:32 PM

Hello:


I am interested in your swagger/rest API, it already support integration with AWS Lambda.


Regards,


Mayte

Re: REST API - AWS Lambda
by
Elizaryev Ivan Nikolaevich
on 9/21/20, 9:59 AM Author

Hello Mayte,

Yes, you can use REST API/OpenAPI/Swagger with AWS Lambda.

Support is included in the price of the module so we will definitely help you with the setup if you have any questions.

Best regards


by
Muhsin K
on 3/18/20, 4:43 AM

I am using your openapi module, how can I expose my api end poits for categories, products, customers, pricelists etc for mobile apps ? how can the external systems using Javasript can access ? where is the end points i can give to external systems. Please explain.. Thanks in advance

Re:
by
Elizaryev Ivan Nikolaevich
on 3/18/20, 5:22 AM Author

Try to follow the documentation and let us know the difficulties you face. Please send questions to apps@itpp.dev with the proof of purchase. Ivan