Skip to Content
Menu
This question has been flagged
1 Reply
10097 Views

I 'd like to use rest api to exchange data with Odoo.


I tried to connect to Odoo through the rest api but the password to use is not api token but user password.

How to force or which route I need to use to force api token instead of user password ?


Best Regards

Avatar
Discard
Author

Thanks Dear for your answer,

It works with jsonrpc 2.0 with basic authentication, need to check if I could use oauth2.0.

Best Regards,

Best Answer

Odoo's REST API authentication system, by default, requires the usage of a username and password combination. You may, however, setup the system to accept authentication with an API token rather than a password.

To enable API token authentication in Odoo 15, you will need to follow these steps:

Create an API user with the required permissions. This user will be used to generate the API token that will be used for authentication.

Generate an API token for the API user. You can do this by navigating to the user's profile in Odoo, selecting the "Access Rights" tab, and clicking on the "Generate" button next to the API token field.

Once you have generated the API token, you can use it in place of the user's password to authenticate your API requests. You will need to include the token in the "Authorization" header of your API requests, using the following format: "Bearer [token]".

You can now use the Odoo REST API with the API token to authenticate your requests.

Please note that you will need to configure the Odoo server to allow API token authentication. To do this, you will need to set the "api_key" configuration parameter to "True" in the Odoo configuration file. You can find more information about configuring the Odoo server in the official Odoo documentation. https://www.odoo.com/documentation/master/developer/reference/external_api.html

Avatar
Discard
Author

Dear Thanks for your quick answer.

Author

Dear,
Do you have the jsonrpc 2.0 structure to control CRUD ?
Best Regards

Yes, Odoo v15 uses the JSON-RPC 2.0 protocol for remote procedure calls, including CRUD operations. Here is an example of the JSON-RPC 2.0 request structure for a basic CRUD operation (in this example, we'll use the res.partner model):

Let's break down this example request:

jsonrpc: The JSON-RPC protocol version. In this case, it's set to "2.0".
method: The remote method to be called. In this case, we're using the call method.
params: The parameters for the remote method. In this case, we're specifying:
model: The name of the Odoo model to interact with. In this case, it's res.partner.
method: The method to be called on the model. In this case, it's create, which will create a new record.
args: An array of arguments to be passed to the method. In this case, we're passing a dictionary of field values for the new res.partner record.
id: An identifier for the request. This can be any JSON value and is used to match requests to responses.

For other CRUD operations, such as read, update, and delete, you would simply change the method parameter to the appropriate method (read, write, or unlink, respectively) and adjust the args parameter accordingly.

Note that you'll need to authenticate with the Odoo server before making any requests. Odoo supports several authentication methods, including session-based authentication and OAuth 2.0. You can find more information on authentication in the Odoo documentation.

Related Posts Replies Views Activity
1
May 25
386
3
May 21
3607
4
May 18
3366
0
Aug 16
4045
1
Jan 25
490