Odoo RESTFUL API

by
Odoo 6
v 10.0 v 11.0 v 12.0 Third Party 2138
Download for 12.0 series Deploy on Odoo.sh
You bought this module and need support ? Click here !
Technical name restful
LicenseLGPL-3
Websitehttps://ajepe.github.io/blog/restful-api-for-odoo
Read description for v 11.0 v 10.0
Technical name restful
LicenseLGPL-3
Websitehttps://ajepe.github.io/blog/restful-api-for-odoo
Read description for v 11.0 v 10.0

Odoo RESTFUL API

This module helps you to connect or integrate any third party application with Odoo.
It provides a fluent and easy HTTP based API interface instead of the Odoo default RPC.
By design Odoo is shipped with RPC API interfaces which may not be straight forward for many developers that are not familiar with the RPC(s). This is module only cares about generating an HTTP response for each HTTP request, it has nothing to do with your or existing application logic. For detailed example of REST API refer
https://ajepe.github.io/posts/restful-api-for-odoo

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.
Odoo
Would like to try this
by on

Attempting to install the plugin on ODOO 12.0. It fails, and I see this error: Odoo Server Error Traceback (most recent call last): File "/home/regrehan/odoo-dev/odoo/odoo/models.py", line 1108, in _validate_fields check(self) File "/home/regrehan/odoo-dev/odoo/odoo/addons/base/models/ir_ui_view.py", line 351, in _check_xml self.postprocess_and_fields(view.model, view_doc, view.id) File "/home/regrehan/odoo-dev/odoo/odoo/addons/base/models/ir_ui_view.py", line 1106, in postprocess_and_fields self.raise_view_error(message, view_id) File "/home/regrehan/odoo-dev/odoo/odoo/addons/base/models/ir_ui_view.py", line 548, in raise_view_error raise ValueError(message) ValueError: Field `rest_api` does not exist There is more. It all appears to have to do with the Field 'rest_api' does not exist.


Odoo
can not get image in product.template database.
by on

I used this model in odoo12 enterprise version, in the "/api/product.template" API, I always got the "image": null, "image_medium": null, "image_small": null,


Odoo
Issue with *2many on create
by on

Hello Ajepe, I have an issue with *2many fields when I create new records. I used the same example in the module documentation. """Create a new record. Basic sage: import requests headers = { 'content-type': 'application/x-www-form-urlencoded', 'charset': 'utf-8', 'access-token': 'access_token' } data = { 'name': 'Babatope Ajepe', 'country_id': 105, 'child_ids': [ { 'name': 'Contact', 'type': 'contact' }, { 'name': 'Invoice', 'type': 'invoice' } ], 'category_id': [{'id': 9}, {'id': 10}] } req = requests.post('%s/api/res.partner/' % base_url, headers=headers, data=data) """ The record is created but child_ids and category_id are not there.


Odoo
by on

have you an example with java code please that use restfull api


Odoo
by on

who can help me how to use this modul .. some steps useful .. thank you

Odoo
Re:
by on

Check out the documentation here https://ajepe.github.io/posts/restful-api-for-odoo/


Odoo
Error on GET crm.lead
by on

req = requests.get('{}/api/crm.lead'.format(base_url), headers=headers, data={'limit': 1, 'domain': []}) ``` File "/media/ricardo/Dados/Codidos/Python/odoo/custom_addons/restful/common.py", line 22, in valid_response response=json.dumps(data, default=datetime.datetime.isoformat), File "/media/ricardo/Dados/Codidos/Python/odoo/venv/lib/python3.5/site-packages/simplejson/__init__.py", line 399, in dumps **kw).encode(obj) File "/media/ricardo/Dados/Codidos/Python/odoo/venv/lib/python3.5/site-packages/simplejson/encoder.py", line 296, in encode chunks = self.iterencode(o, _one_shot=True) File "/media/ricardo/Dados/Codidos/Python/odoo/venv/lib/python3.5/site-packages/simplejson/encoder.py", line 378, in iterencode return _iterencode(o, 0) TypeError: descriptor 'isoformat' requires a 'datetime.datetime' object but received a 'datetime.date' - - - ```


Odoo
@Betty
by on

Object of type datetime is not JSON serializable error is now fixed


Odoo
Error after request
by on

Hello Ajepe, I got an error after url/api/res.partner search: File "/odoo/custom/addons/restful/controllers/main.py", line 26, in wrap "access_token_not_found", "missing access token in request header", 401 File "/odoo/custom/addons/restful/common.py", line 33, in invalid_response response=json.dumps( NameError: name 'json' is not defined - - - Please help to sort this issue? My regards.

Odoo
Re: Error after request
by on

You need to always send access token with every request check https://github.com/ajepe/odoo-addons/tree/12.0/restful for how to send correct request.


Odoo
Having Issues
by on

Hello Ajepe, I'm having an issue when attempting to read a model. url = "https://url/api/sale.order" headers = { 'access-token': "access_token_43d090f52c9aaa72a73480e0bd1b06530d0c933c", } response = requests.request("GET", url, headers=headers) odoo log says: File "/home/odoo/src/user/ajepe/odoo-addons/restful/controllers/main.py", line 92, in get return valid_response(data) File "/home/odoo/src/user/ajepe/odoo-addons/restful/common.py", line 21, in valid_response response=json.dumps(data), File "/home/odoo/.local/lib/python3.6/site-packages/simplejson/__init__.py", line 382, in dumps return _default_encoder.encode(obj) File "/home/odoo/.local/lib/python3.6/site-packages/simplejson/encoder.py", line 296, in encode chunks = self.iterencode(o, _one_shot=True) File "/home/odoo/.local/lib/python3.6/site-packages/simplejson/encoder.py", line 378, in iterencode return _iterencode(o, 0) File "/home/odoo/.local/lib/python3.6/site-packages/simplejson/encoder.py", line 273, in default o.__class__.__name__) TypeError: Object of type datetime is not JSON serializable - - - This occurs when attempting to read any model. Is there any fix for this?

Odoo
Re: Having Issues
by on

What version are you referring to? I guess it will version 12.0.


Odoo
Thanks it work
by on

This is work for me


Odoo
the answer
by on

Here is the answer for the previous issue: https://stackoverflow.com/questions/45466814/odoo-url-not-found-if-not-auth Regards.


Odoo
not working if no session_id is specified
by on

Hi, (checking this https://ajepe.github.io/posts/restful-api-for-odoo/). It throws 404 if not session_id is specified. What is the correct way to connect without needing to include sessino_id? Thank you.


Odoo
404 Not Foujd
by on

Hi, good module. I'm trying to test this module but it never connects to the url. It only connects if I include 'Cookie': 'session_id=a40de38883ddbf04ab9d070ab950d0216f710a67'. What is the correct way to use this module, I don't want to spedify a session_id into the header. Thank you.


Odoo
by on

@ibyref and @Otto Kalme Can you describe what you are trying to achieve that is giving you an error with the code snippets with that I should be able to help you guys.


Odoo
by on

Odoo
by on

The database name is not valid Access denied


Odoo
fake addon
by on

Doesn't work neither reading nor creating


Odoo
Fix this error please
by on

I just made Read [GET] request in python exactly from your docs in new database with demo data and I got this error: 2018-11-15 13:13:03,595 12853 INFO testmoham odoo.addons.base.models.res_users: Login successful for db:testmoham login:admin from 127.0.0.1 2018-11-15 13:13:03,632 12853 INFO testmoham werkzeug: 127.0.0.1 - - [15/Nov/2018 13:13:03] "GET /api/auth/token HTTP/1.1" 200 - 45 0.019 0.068 2018-11-15 13:13:03,746 12853 INFO testmoham werkzeug: 127.0.0.1 - - [15/Nov/2018 13:13:03] "GET /api/sale.order/ HTTP/1.1" 500 - 76 0.038 0.073 2018-11-15 13:13:03,755 12853 ERROR testmoham werkzeug: Error on request: Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/werkzeug/serving.py", line 209, in run_wsgi execute(self.server.app) File "/usr/lib/python3.6/site-packages/werkzeug/serving.py", line 197, in execute application_iter = app(environ, start_response) File "/home/odoo/odoo12/odoo/service/server.py", line 255, in app return self.app(e, s) File "/home/odoo/odoo12/odoo/service/wsgi_server.py", line 128, in application return application_unproxied(environ, start_response) File "/home/odoo/odoo12/odoo/service/wsgi_server.py", line 117, in application_unproxied result = odoo.http.root(environ, start_response) File "/home/odoo/odoo12/odoo/http.py", line 1317, in __call__ return self.dispatch(environ, start_response) File "/home/odoo/odoo12/odoo/http.py", line 1290, in __call__ return self.app(environ, start_wrapped) File "/usr/lib/python3.6/site-packages/werkzeug/wsgi.py", line 600, in __call__ return self.app(environ, start_response) File "/home/odoo/odoo12/odoo/http.py", line 1485, in dispatch result = ir_http._dispatch() File "/home/odoo/odoo12/addons/auth_signup/models/ir_http.py", line 19, in _dispatch return super(Http, cls)._dispatch() File "/home/odoo/odoo12/addons/web_editor/models/ir_http.py", line 22, in _dispatch return super(IrHttp, cls)._dispatch() File "/home/odoo/odoo12/addons/http_routing/models/ir_http.py", line 394, in _dispatch result = super(IrHttp, cls)._dispatch() File "/home/odoo/odoo12/addons/utm/models/ir_http.py", line 26, in _dispatch response = super(IrHttp, cls)._dispatch() File "/home/odoo/odoo12/odoo/addons/base/models/ir_http.py", line 207, in _dispatch return cls._handle_exception(e) File "/home/odoo/odoo12/addons/utm/models/ir_http.py", line 31, in _handle_exception response = super(IrHttp, cls)._handle_exception(exc) File "/home/odoo/odoo12/odoo/addons/base/models/ir_http.py", line 177, in _handle_exception return request._handle_exception(exception) File "/home/odoo/odoo12/odoo/http.py", line 773, in _handle_exception return super(HttpRequest, self)._handle_exception(exception) File "/home/odoo/odoo12/odoo/http.py", line 312, in _handle_exception raise pycompat.reraise(type(exception), exception, sys.exc_info()[2]) File "/home/odoo/odoo12/odoo/tools/pycompat.py", line 87, in reraise raise value File "/home/odoo/odoo12/odoo/addons/base/models/ir_http.py", line 203, in _dispatch result = request.dispatch() File "/home/odoo/odoo12/odoo/http.py", line 832, in dispatch r = self._call_function(**self.params) File "/home/odoo/odoo12/odoo/http.py", line 344, in _call_function return checked_call(self.db, *args, **kwargs) File "/home/odoo/odoo12/odoo/service/model.py", line 97, in wrapper return f(dbname, *args, **kwargs) File "/home/odoo/odoo12/odoo/http.py", line 337, in checked_call result = self.endpoint(*a, **kw) File "/home/odoo/odoo12/odoo/http.py", line 938, in __call__ return self.method(*args, **kw) File "/home/odoo/addons12/restful/controllers/main.py", line 28, in wrap return func(self, *args, **kwargs) File "/home/odoo/odoo12/odoo/http.py", line 517, in response_wrap response = f(*args, **kw) File "/home/odoo/addons12/restful/controllers/main.py", line 55, in get domain=domain, fields=fields, offset=offset, limit=limit, order=order) File "/home/odoo/odoo12/odoo/models.py", line 4516, in search_read result = records.read(fields) File "/home/odoo/odoo12/odoo/models.py", line 2768, in read values[name] = field.convert_to_read(record[name], record, use_name_get) File "/home/odoo/odoo12/odoo/models.py", line 5042, in __getitem__ return self._fields[key].__get__(self, type(self)) File "/home/odoo/odoo12/odoo/fields.py", line 974, in __get__ self.determine_value(record) File "/home/odoo/odoo12/odoo/fields.py", line 1085, in determine_value self.compute_value(recs) File "/home/odoo/odoo12/odoo/fields.py", line 1041, in compute_value self._compute_value(records) File "/home/odoo/odoo12/odoo/fields.py", line 1032, in _compute_value getattr(records, self.compute)() File "/home/odoo/odoo12/addons/sale/models/sale.py", line 262, in _compute_type_name record.type_name = _('Quotation') if self.state in ('draft', 'sent', 'cancel') else _('Sales Order') File "/home/odoo/odoo12/odoo/fields.py", line 968, in __get__ record.ensure_one() File "/home/odoo/odoo12/odoo/models.py", line 4643, in ensure_one raise ValueError("Expected singleton: %s" % self) ValueError: Expected singleton: sale.order(8, 3, 4, 6, 7, 9, 10, 14, 15, 16) - - -

Odoo
Re: Fix this error please
by on

The error is actually coming from your code