Skip to Content
Menu

REST API - Odoo 14

by
Odoo

11.11

v 14.0 Third Party 28
Availability
Odoo Online
Odoo.sh
On Premise
Lines of code 484
Technical Name api_restful_odoo
You bought this module and need support? Click here!
Availability
Odoo Online
Odoo.sh
On Premise
Lines of code 484
Technical Name api_restful_odoo

Authentication

  • Login
  • Logout

In order to be able to access any entity an access token needs to generated which serves as session cookies in a regular web language. The token will be needed for every subsequent requests. Except for /api/login enpoint that accept multipart/form-data as the Content type every other endpoints accept application/json as the 'Content Type'.
Token will give the user access only to models which he have access to.
The period which the token needs to be expired is parametrable and you can modify it.

Login (Request access token)

Python request

To retrive an access token these following parameters needs to be set.

  • the database name as db
  • the connecting username as login
  • the user password as password
The above request will return a response like below.

Logout

To logout of the system the token needs to be destroyed i.e deleted, by doing that the user/application making the request on behalf of the user will have not futher access to Odoo. The token /api/logout listen to both GET and DELETE requests, GET will fetch the token while delete request will deleted the token.

Python request:

CRUD on model.model: Example: sale.order

To get or fetch existing sale order

There is posibilty of applying some record filters in order to get just the specific record.

  • limit: This define the total number of record we are expecting
  • offset: where the query will start from
  • fields: this is the list of field that we wanted to return, this can be leave empty if we wanted to return all the fields.
  • domain: domain is like a filter it is always a list of tuples (field, operator, value)
These payload applies to all records in Odoo.
We can perform create, update and delete operation on any records using corresponding HTTP request headers.
  • GET: For retriving existing records
  • POST: For creating new records
  • PATCH: Call an action button on a record
  • DELETE: To delete a record
All the API of currently installed modules or any module that may be installed has already cattered for dynamically. The API follows this sematic pattern
/api{api route}/modelP{model name}/id{optional id for delete request} e.g for sale order Get request to api/sale.order endpoint will return all the sale order in the system.

Get specific element

  • Get request
  • Response

The reponse with all the fields, but the return fields can specified along side the request, and also, specific records can be specified by sending along the request Odoo domain as json body.

The above will only return 2 maximum records, id, partner and sale order name, that have an ID in the given list [10,11,12,13,14], the offset can be set also.

POST request

PUT request

Put request is meant for updating fields in a record. e.g updating partner name.

In the above request, we send a json body like this {"name":"partner name edited"}, calling the put request updated the res.partrner with id = 15 with new data.

PATCH request

Patch request is meant for calling an action button on a record. example: validating sale order.

In the above request, we send a json body like this {"_method":"action_confirm"} The _method is the action/button name in odoo. This is similar to clicking Confirm Button on sale order with ID 37

DELETE request

We only need to make a delete request to the resource.

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.
It doesn't work
by
Mohamed
on 9/29/21, 3:52 AM

hello,

this is not working, I installed it locally and on a server, it installed without errors but when trying to login like the example it gives me error 404,

I handled to use rpc instead of it.


by
Kben
on 10/25/24, 5:09 AM Confirmed Purchase

Hello,

When I install the module in Odoo 14 CE locally, I get the error 404; with http://localhost:8069/api/login

What could be the problem?


by
linyaohui
on 1/21/22, 2:47 AM Confirmed Purchase

The token /api/logout listen to both GET and DELETE requests, GET will fetch the token while delete request will deleted the token.
get not working for fresh

{"type": "invalid object model", "message": "The model logout is not available in the registry."}


Will it work with Odoo.sh
by
webshop.admin@zafco.com
on 10/11/21, 3:16 AM

Hi,


Can we use this with Odoo.sh or only with On-Prim databases?


by
Jorge Washington Cáceres Campana
on 8/9/21, 3:15 PM Confirmed Purchase

Hi

 I installed this module in Odoo 14 CE, but when I send with curl like the example, I get the error 404; when I send wit postman with "content-type=application/json" I have error 200 from odoo Server, please I need your help


thank you


by
Mikhail Ivanov
on 5/29/21, 9:05 PM Confirmed Purchase

Hei, my dear collegues! I guess, you also know that no one of you methods except Get, Login and Logout do not work, right? Neither POST nor PUT

Contact me asap, please!


by
vijay gwala
on 5/22/21, 7:15 AM

Are you sure this will handle cross origin requests (CORS) because my purpose is to use authentication from react side.


APi documentation et al.
by
WMSSoft Pty Ltd
on 3/9/21, 1:36 AM

Do you have further documentation for this rest api for odoo.  Does it allow CRUD to all objects in Odoo?  One thing I wanted to do was update a draft delivery, then validate it and then create a back order delivery if one was required.  Do you think your API would allow me to do this? (what api calls would be required)