MuK REST API for Odoo

by
Odoo 5

101.00

v 10.0 v 11.0 v 12.0 Third Party 450
Live Preview
Availability
Odoo Online
Odoo.sh
On Premise
Community Apps Dependencies
Lines of code 3875
Technical Name muk_rest
LicenseOPL-1
Websitehttp://www.mukit.at
Versions 15.0 14.0 11.0 12.0 16.0 17.0 13.0 10.0
You bought this module and need support? Click here!
Availability
Odoo Online
Odoo.sh
On Premise
Community Apps Dependencies
Lines of code 3875
Technical Name muk_rest
LicenseOPL-1
Websitehttp://www.mukit.at
Versions 15.0 14.0 11.0 12.0 16.0 17.0 13.0 10.0

MuK REST API for Odoo

A customizable Restful API for Odoo

MuK IT GmbH - www.mukit.at

Overview

Enables a REST API for the Odoo server. The API has routes to authenticate and retrieve a token. Afterwards, a set of routes to interact with the server are provided. The API can be used by any language or framework which can make an HTTP requests and receive responses and works with both the Community and the Enterprise Edition.

  • Clients
  • Examples
  • Documentation
  • FAQs

In case the module should be active in every database just change the auto install flag to True . To activate the routes even if no database is selected the module should be loaded right at the server start. This can be done by editing the configuration file or passing a load parameter to the start script.

Parameter: --load=web,muk_rest

Key Features

Authentication with the server can be done either via OAuth1 or OAuth2.
All Grant Types are supported by the API

  • OAuth1 - Authentication

  • Temporary Credentials Acquisition
  • POST
    /api/authentication/oauth1/initiate
  • Authorization
  • GET
    /api/authentication/oauth1/authorize
  • Token Exchange
  • POST
    /api/authentication/oauth1/token
  • OAuth2 - Authentication

  • Authorization
  • GET
    /api/authentication/oauth2/authorize
  • Token Exchange
  • POST
    /api/authentication/oauth2/token
  • Token Revocation
  • POST
    /api/authentication/oauth2/revoke

These API endpoints can be used to communicate with the system

  • Version
  • GET
    /api
  • Languages
  • GET
    /api/languages
  • Countries
  • GET
    /api/countries
  • Binary
  • GET
    /api/binary/{xmlid}
  • GET
    /api/binary/{xmlid}/{filename}
  • GET
    /api/binary/{id}
  • GET
    /api/binary/{id}/{filename}
  • GET
    /api/binary/{id}-{unique}
  • GET
    /api/binary/{id}-{unique}/{filename}
  • GET
    /api/binary/{model}/{id}/{field}
  • GET
    /api/binary/{model}/{id}/{field}/{filename}
  • Modules
  • GET
    /api/modules
  • Call
  • POST
    /api/call/{model}
  • POST
    /api/call/{model}/{method}
  • User
  • GET
    /api/user
  • Session
  • GET
    /api/session
  • Reports
  • GET
    /api/reports{name}
  • GET
    /api/reports/{name}{model}
  • Report
  • GET
    /api/report{report}
  • GET
    /api/report/{report}{type}

These API endpoints can be used to communicate with Odoo models

  • Field Names
  • GET
    /api/field_names/{model}
  • Fields
  • GET
    /api/fields/{model}
  • Metadata
  • GET
    /api/metadata/{model}
  • Create
  • POST
    /api/create/{model}
  • Write
  • PUT
    /api/write/{model}
  • Unlink
  • DELETE
    /api/unlink/{model}
  • Search
  • GET
    /api/search/{model}
  • GET
    /api/search/{model}/{order}
  • GET
    /api/search/{model}/{limit}/{order}
  • GET
    /api/search/{model}/{limit}/{offset}/{order}
  • Search Read
  • GET
    /api/search_read/{model}
  • GET
    /api/search_read/{model}/{order}
  • GET
    /api/search_read/{model}/{limit}/{order}
  • GET
    /api/search_read/{model}/{limit}/{offset}/{order}
  • Name
  • GET
    /api/name/{model}
  • Read
  • GET
    /api/read/{model}
  • Search Group
  • GET
    /api/read_group/{model}
  • GET
    /api/read_group/{model}/{orderby}
  • GET
    /api/read_group/{model}/{limit}/{orderby}
  • GET
    /api/read_group/{model}/{limit}/{offset}/{orderby}

These API endpoints can be used to check access rights

  • Access Rights
  • GET
    /api/access/rights/{model}
  • GET
    /api/access/rights/{model}/{operation}
  • Access Rules
  • GET
    /api/access/rules/{model}
  • GET
    /api/access/rules/{model}/{operation}
  • Access Fields
  • GET
    /api/access/fields/{model}
  • GET
    /api/access/fields/{model}/{operation}
  • General Access
  • GET
    /api/access/{model}
  • GET
    /api/access/{model}/{operation}

These API endpoints can be used to interact with the database

  • Master Password
  • POST
    /api/change_master_password
  • List Databases
  • GET
    /api/database/list
  • Backup Database
  • POST
    /api/database/backup
  • Restore Database
  • POST
    /api/database/restore
  • Create Database
  • POST
    /api/database/create
  • Duplicate Database
  • POST
    /api/database/duplicate
  • Drop Database
  • POST
    /api/database/drop

Custom Endpoints

In addition to the existing API endpoints, more can easily be added. It is not necessary to write any kind of code. New endpoints can be created in the backend and are immediately available through the API.

Different types of endpoints can be created. The domain evaluation can be used to query certain data and return it via the API. The second type calls a particular server action that is defined in the system. And if you have a more complex case, you can enter a Python code directly in the backend.

Extend the API

Even if the API is extended using Python code, the REST API framework provides a number of helpers. Keep in mind that if these extensions are included in a new module, it may also have to be loaded as a global module to make the created endpoints available without a selected database.

from odoo import http
from odoo.http import request, Response

from odoo.addons.muk_rest import tools
from odoo.addons.muk_rest.utils.json import ResponseEncoder		
				
class ModelController(odoo.http.Controller):

	@odoo.http.route([
	    '/api/myapp/myroute'
	], auth="none", type='http', methods=['GET'], csrf=False)
	@tools.common.parse_exception
	@tools.common.ensure_database
	@tools.common.ensure_module()
	@tools.security.protected()
	def myroute(self, **kw):
	    result = ...
	    content = json.dumps(result, sort_keys=True, indent=4, cls=ResponseEncoder)
	    return Response(content, content_type='application/json;charset=utf-8', status=200)
	      

Read more about creating your own API and how to use the provided helpers in the documentation.

Demo

User:
apps
Password:
demo
Live Preview

Help and Support

Feel free to contact us, if you need any help with your Odoo integration or addiontal features.
You will get 30 Days free support incase of any bugs or issues (Except data recovery or migration).

Restful API

Enables a REST API for the Odoo server. The API has routes to authenticate and retrieve a token. Afterwards, a set of routes to interact with the server are provided.

Requirements

OAuthLib

A generic, spec-compliant, thorough implementation of the OAuth request-signinglogic for Python. To install OAuthLib please follow the instructions or install the library via pip.

pip install oauthlib

Installation

To install this module, you need to:

Download the module and add it to your Odoo addons folder. Afterward, log on to your Odoo server and go to the Apps menu. Trigger the debug mode and update the list by clicking on the "Update Apps List" link. Now install the module by clicking on the install button.

Another way to install this module is via the package management for Python (PyPI).

To install our modules using the package manager make sure odoo-autodiscover is installed correctly. Then open a console and install the module by entering the following command:

pip install --extra-index-url https://nexus.mukit.at/repository/odoo/simple <module>

The module name consists of the Odoo version and the module name, where underscores are replaced by a dash.

Module:

odoo<version>-addon-<module_name>

Example:

sudo -H pip3 install --extra-index-url https://nexus.mukit.at/repository/odoo/simple odoo11-addon-muk-utils

Once the installation has been successfully completed, the app is already in the correct folder. Log on to your Odoo server and go to the Apps menu. Trigger the debug mode and update the list by clicking on the "Update Apps List" link. Now install the module by clicking on the install button.

The biggest advantage of this variant is that you can now also update the app using the "pip" command. To do this, enter the following command in your console:

pip install --upgrade --extra-index-url https://nexus.mukit.at/repository/odoo/simple <module>

When the process is finished, restart your server and update the application in Odoo. The steps are the same as for the installation only the button has changed from "Install" to "Upgrade".

You can also view available Apps directly in our repository and find a more detailed installation guide on our website.

For modules licensed under OPL-1, you will receive access data when you purchase the module. If the modules were not purchased directly from MuK IT please contact our support (support@mukit.at) with a confirmation of purchase to receive the corresponding access data.

Upgrade

To upgrade this module, you need to:

Download the module and add it to your Odoo addons folder. Restart the server and log on to your Odoo server. Select the Apps menu and upgrade the module by clicking on the upgrade button.

If you installed the module using the "pip" command, you can also update the module in the same way. Just type the following command into the console:

pip install --upgrade --extra-index-url https://nexus.mukit.at/repository/odoo/simple <module>

When the process is finished, restart your server and update the application in Odoo, just like you would normally.

Configuration

In case the module should be active in every database just change the auto install flag to True. To activate the routes even if no database is selected the module should be loaded right at the server start. This can be done by editing the configuration file or passing a load parameter to the start script.

Parameter: --load=web,muk_rest

To configure this module, you need to:

  1. Go to Settings -> Restful API -> Dashboard. Here you can see an overview of all your APIs.
  2. Click on Create or go to either Restful API -> OAuth1 or Restful API -> OAuth2 to create a new API.

Usage

This module provides a set of routes to interact with the system via HTTP requests. Currently it is not possible to send requests with the content type "application/json" due to a limitation of the Odoo framework. Take a look at the clients and examples or open the documentation to get a detailed description of every available route.

Credits

Contributors

Images

Some pictures are based on or inspired by:

  • Prosymbols
  • Smashicons

Author & Maintainer

This module is maintained by the MuK IT GmbH.

MuK IT is an Austrian company specialized in customizing and extending Odoo. We develop custom solutions for your individual needs to help you focus on your strength and expertise to grow your business.

If you want to get in touch please contact us via mail (sale@mukit.at) or visit our website (https://mukit.at).

Odoo 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 the authors, typically via Odoo Apps, or if you have received a written
agreement from the authors of the Software (see the COPYRIGHT file).

You may develop Odoo modules 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 Odoo 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.
Does not support the PKCE for native app ?
by
Dhifi Borni
on 4/25/19, 9:16 AM

Public native app clients MUST implement the Proof Key for Code Exchange (PKCE [RFC7636]) extension to OAuth. Best Practice OAuth 2.0 for Native Apps : https://www.rfc-editor.org/rfc/rfc8252.txt this module allow authorization code using only client authentification is not secure for distributed native apps because the client secret is embedded in the client and is sent with requests


Perfect
by
alexey.yevsyukov@gmail.com
on 12/11/18, 2:52 PM

Perfect module and perfect technical support. Thanx!


nice
by
bonka
on 12/13/18, 5:52 PM Confirmed Purchase

nice module


by
Mathias Markl
on 10/6/18, 5:57 AM Author

See tests at: muk_rest/tests/test_database_rest.py


by
Mathias Markl
on 10/6/18, 5:55 AM Author

Therefore I think it is very unlikely that it is due to the REST API. So either the error is already in your used Odoo version or you have specified several databases. Please report bugs and errors to Github, as the Odoo App Store does not inform me when a new comment is posted. https://github.com/muk-it/muk_docs/tree/12%2C0/muk_rest Or write an email to support@mukit.at


by
Mathias Markl
on 10/6/18, 5:51 AM Author

The drop route executes the following code: http.dispatch_rpc('db','drop', [ master_password, database_name]) which is the same as Odoo does with an rpc call or if you delete a database in the database manager.


uggly error!!!!!!!!!1
by
Pier Moen
on 10/5/18, 10:44 AM

hey did you tested your code well? we just tried to delete a database using /api/database/drop path with only one database name but it deleted all!! databases in our postgresql instance! how do we restore our data now??!


uid
by
alexey.yevsyukov@gmail.com
on 9/25/18, 3:17 PM Confirmed Purchase

How I can fetch uid? I have this line in 3rd party module: customer_group = self.env['res.users'].sudo().browse(uid).customer_grp_id if uid else request.website.user_id.sudo().customer_grp_id When I fetch data from rest api, I have not UID.


How to fetch User_id of current logged
by
Raghu S
on 9/20/18, 3:46 PM

How can I get Uid of current logged user just in case to use it in search criteria?


Which languages are supported?
by
Mathias Markl
on 2/26/18, 4:48 AM Author

The REST API can be used by any language/framework which can make/receive an HTTP requests/responses with JSON payloads.


How to connect to the Demo System?
by
Mathias Markl
on 2/26/18, 4:43 AM Author


== Javascript ==

$.ajax({
  method: "POST",
  url: "https://muk-rest-demo.mukit.at/api/authenticate",
  data: { 
	db: "O11-muk-rest-demo.mukit.at",
    login: "demo",
    password: "demo",
  }
}).done(function(msg) {
  alert(msg);
});

== Python ==

import requests

def authentication(self):
  response = requests.post(
	"https://muk-rest-demo.mukit.at/api/authenticate",
	data = {
	  'db': "O11-muk-rest-demo.mukit.at",
	  'login': "demo",
	  'password': "demo"
	}
  )
return response.json()['token']



How to connect to the Demo System?
by
Mathias Markl
on 2/26/18, 4:39 AM Author

== Javascript == $.ajax({ method: "POST", url: "https://muk-rest-demo.mukit.at/api/authenticate", data: { db: "O11-muk-rest-demo.mukit.at", login: "demo", password: "demo", } }).done(function(msg) { alert(msg); }); == Python == import requests def authentication(self): response = requests.post( "https://muk-rest-demo.mukit.at/api/authenticate", data = { 'db': "O11-muk-rest-demo.mukit.at", 'login': "demo", 'password': "demo" } ) return response.json()['token']


Does it work on CE and EE?
by
Mathias Markl
on 2/26/18, 3:57 AM Author

Our test system runs on the Odoo Community Edition, but since the module doesn't use any features exclusively provided by the Community Edition, it will run on both versions.