JWT Authentication & REST Web Services

by
Odoo

91.32

v 12.0 Third Party 2
Availability
Odoo Online
Odoo.sh
On Premise
Technical Name restful-api-jwt-auth
LicenseOPL-1
You bought this module and need support? Click here!
Availability
Odoo Online
Odoo.sh
On Premise
Technical Name restful-api-jwt-auth
LicenseOPL-1

JWT Authentication & REST Web Services

Useful for integration with third-party applications.

This module allows to create a secure external authentication method using Json Web Tokens and provide access to Odoo's models through REST APIs.

Fisrt...
You need to install: PyJWT.
pip install PyJWT
Secure authentication trough Json Web Tokens...
https://{server-url}/jwt/auth

Return a secure token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1NTEwMzkxNjUsImlhdCI6MTU1MTAzNTU2NSwic3ViIjp7Im5hbWUiOiJNaXRjaGVsbCBBZG1pbiIsImlkIjoyfX0.LfnvU16FOTgT9cNClu8t08n6EXMZMzluyZBxP70Afaw

This token will be used in the subsequent api calls...

(Search) - Using API to get resources

[HTTP method GET]: To obtain the resources list of a given model use:
https://{server-url}/jwt/rest_api/{model_name}

For example: http://localhost:8069/jwt/rest_api/res.partner
Also you can use: limit, args, offset, order and count, as if you were working with the ORM...
For example:
  • http://localhost:8069/jwt/rest_api/res.partner?limit=2&args=[('name', '=', 'Antoine Langlais Langlais')]&offset=0&count=0
  • http://localhost:8069/jwt/rest_api/res.partner?limit=2&args=[]&offset=0&count=0&order='name'
You can define the fields you wish to show, by means the parameter "fields" added on the request header.

basics fields ['id', 'name', 'street']
Many2one ['id', 'name', 'street', ('country_id', ['id', 'name'])]
Many2many & One2many ['id', 'name', 'street', ('country_id', ['id', 'name']), ['child_ids', ['id', 'name', ('title', ['id', 'name', 'shortcut']), 'function', 'email', 'phone', 'mobile', 'comment']]]

(Creation) - Using API to create resources

[HTTP method POST]: To create a resource of a given model use:
https://{server-url}/jwt/rest_api/{model_name}

For example: http://localhost:8069/jwt/rest_api/res.partner
You will have the possibility to create simple objects, but you can also create objects with internal relationships (in other words with related fields Many2one, Many2many and One2many). And you can control the uniqueness of the objects according to fields defined by you.

Suppose you need to create a "res.partner" record but you need to define by creation its country (Many2one => res.country) and its contacts (One2many => res.partner).

The way you can do that is using the following data:
                            {
                                "name": "Res Partner 3", "phone": "+000000000", "mobile": "+000000000",
                                "fax": "0958416995", "email": "test@gmail.com", "website": "http://as.com",
                                "child_ids": [
                                    3,
                                    {"name": "Contact 1", "phone": "+000000111", "constraint": "barcode,name"}
                                ],
                                "relational_fields": [('child_ids', 'res.partner'), ('country_id', 'res.country')],
                                "constraint": "barcode,name",
                                "country_id": {"name": "Country Test", "constraint": "name"}
                            }

Details...
  • relational_fields: Define the name of the relational type and its model's name. (list of tuples).
  • constraint: Define the field to use to avoid data duplications. (string coma separated).
  • data: Object data to create de resource.
Other details about relational fields.

Many2one If you know the id of the resource use it. ("country_id": 50 instead "country_id": {"name": "Country Test", "constraint": "name"})
Many2many & One2many You can use both: resource id or resource creation in place. (Remember this is a list of elements). "child_ids": [3, {"name": "Contact 1", "phone": "+000000111", "constraint": "barcode,name"}],
The response contain the record id.

(Update) - Using API to update resources

[HTTP method PUT]: To update resources of a given model and specific id use:
https://{server-url}/jwt/rest_api/{model_name}

For example: http://localhost:8069/jwt/rest_api/res.partner
Details...
  • ids: (list of resources id).
  • data: Object data to update on the resources.

(Deletion) - Using API to delete resources

[HTTP method DELETE]: To delete a resource of a given model and specific id use:
https://{server-url}/jwt/rest_api/{model_name}

For example: http://localhost:8069/jwt/rest_api/res.partner
Successful delete.
Unsuccessful operation if the id not exist.

SKE Developer
ske.developer@gmail.com


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.