Enable Dark Mode!
how-to-configure-odoo-rest-api-module-in-odoo-18.jpg
By: Unnimaya CO

How to Configure Odoo REST API Module in Odoo 18

Technical

The Odoo REST API module in Odoo 18 provides a powerful way to interact with the Odoo database using HTTP methods like GET, POST, PUT, and DELETE. This module is essential for businesses and developers looking to integrate third-party applications, automate workflows, and streamline data management within Odoo.

With secure API key-based authentication, users can perform various operations on models such as product templates, customers, and sales orders without needing direct access to the Odoo backend. Whether fetching records, creating new entries, updating existing data, or deleting unnecessary records, the REST API simplifies communication with Odoo while ensuring data security and efficiency.

This guide provides a detailed walkthrough of configuring, authenticating, and utilizing the Odoo REST API to maximize the flexibility and automation of your Odoo environment.

Key Features

1. API Key Generation

* The API key is generated using database authentication.

* This key is used to authenticate and authorize API requests.

* Each user in Odoo gets a unique API key that needs to be included in the request headers.

* API keys enhance security by preventing unauthorized access.

2. Create Records

* Allows the creation of records in various models.

* Uses POST requests to insert new data into the database.

* Helps automate the process of adding new entries without manual intervention.

3. Supported Methods

a. The module supports multiple HTTP methods, including:

* GET – Retrieve records from the database.

* POST – Create new records in Odoo models.

* PUT – Update existing records.

* DELETE – Remove records from the database.

b. Supports filtering and querying data using URL parameters.

4. Create & Update Records

* Users can create new records and update existing ones using API calls.

* Reduces manual workload and improves data consistency.

* Ensures secure transactions by validating data before processing.

5. Delete Records

* The DELETE method allows the removal of records, ensuring data is managed effectively.

* Prevents redundant or obsolete data accumulation.

To enable the REST API module in Odoo 18, update the Odoo configuration file by adding the following

server_wide_modules = web, base, rest_api_odoo

How to Configure Odoo REST API Module in Odoo 18-cybrosys

This setting ensures that API requests can be processed automatically without requiring manual database selection.

Important Notes:

* If you uninstall the REST API module, remove rest_api_odoo from server_wide_modules to prevent errors.

Once the configuration file is updated, the next step is to install the REST API Odoo module.

How to Configure Odoo REST API Module in Odoo 18-cybrosys

After successfully installing the module, a new API Key field will appear in the User Settings. This field allows each user to generate a unique API key, which will be used for authentication when making API requests.

How to Configure Odoo REST API Module in Odoo 18-cybrosys

To access the API securely, users must generate an API Key before making any requests. This key acts as a secure token, ensuring that only authenticated and authorized users can access and interact with the Odoo database through API calls.

Authentication & API Key Generation

Find the Postman collections in the given app folder. Within the extracted module folder, locate the Postman collections file in JSON format.

How to Configure Odoo REST API Module in Odoo 18-cybrosys

To begin using the Odoo REST API with Postman, first need to import the provided API collection into Postman. This will allow you to quickly access pre-configured API requests without manually setting them up.

How to Configure Odoo REST API Module in Odoo 18-cybrosys

After successfully importing the API collection, you will be able to see the imported collections listed under the "Collections" tab in Postman.

How to Configure Odoo REST API Module in Odoo 18-cybrosys

API Authentication

You need to update the Base URL, Database Name (db), Database Username (login), and Database Password (password) in the request headers.

The URL should follow this format:

http://cybrounnimaya:8018/odoo_connect

Replace cybrounnimaya:8018 with your actual localhost port number.

When sending a request, include the database name, username, and password in the headers.

How to Configure Odoo REST API Module in Odoo 18-cybrosys

If authentication is successful, an API key will be generated for the current user.

How to Configure Odoo REST API Module in Odoo 18-cybrosys

The API key that is generated will be automatically stored in the API Key field within the User Form View in Odoo. This ensures that each user has a unique authentication token associated with their account. The stored API key can then be used for secure authentication when making API requests, eliminating the need to repeatedly enter login credentials.

How to Configure Odoo REST API Module in Odoo 18-cybrosys

Next, we need to generate REST API records to ensure that the methods are enabled for the selected model. Here, we can add a model and enable the allowed methods, such as GET, POST, PUT, and DELETE. Only the allowed model data can be accessed or modified through API calls, ensuring controlled and secure operations.

* GET: Retrieves records from the database, allowing users to fetch specific or multiple records based on filters.

* POST: Creates new records in Odoo models, automating data entry and integration with external applications.

* PUT: Updates existing records, ensuring data consistency by modifying specific fields while retaining the record structure.

* DELETE: Removes records from the database, preventing the accumulation of irrelevant or redundant data.

How to Configure Odoo REST API Module in Odoo 18-cybrosys

Retrieving Records Using the GET Method

To retrieve data from specified models, we can use the GET method, which is already included in the imported Postman collections.

Authentication:

Add the required authentication details in the request headers:

* login: The database username

* password: The database password

* api-key: The API key generated for authentication

Request URL:

Construct the request URL by specifying the model to retrieve records from. Example:

http://cybrounnimaya:8018/send_request?model=product.template&Id=10

This request fetches records from the product.template model.

Ensure GET Method is Enabled:

Before making the request, verify that the GET method is enabled for the selected model in the REST API configuration. Only models with this method enabled can be accessed via API calls.

How to Configure Odoo REST API Module in Odoo 18-cybrosys

Body:

{
   "fields": ["name", "barcode", "description"]
}

Add body and click the Send button to get the records.

How to Configure Odoo REST API Module in Odoo 18-cybrosys

Creating Records Using the POST Method

The POST method allows you to create new records in the Odoo database via API requests. Before making a request, ensure that the POST method is enabled for the model in the REST API configuration. Otherwise, you will receive a "method not allowed" error.

To create a record, provide the required JSON data along with the model name. You can use the Postman collection provided with the application files for easy execution.

Example: Creating a Product in the product.template Model

To create a new product template, use the following request format:

http://cybrounnimaya:8018/send_request?model=product.template

How to Configure Odoo REST API Module in Odoo 18-cybrosys

Body:

{
   "fields" :["name","list_price", "type"] ,
   "values": {"name": "New Product",
              "type":"consu",
              "list_price":250.0,
             }
}

Add body and click the Send button to create the records.

How to Configure Odoo REST API Module in Odoo 18-cybrosys

This request will successfully add a new product to the product.template model with the specified name, price, and type.

How to Configure Odoo REST API Module in Odoo 18-cybrosys

Updating Records Using the PUT Method

The PUT method is used to update existing records in the Odoo database via API requests. To update a record, you need to specify the model name and the ID of the record you want to modify.

Before making a request, ensure that you are authenticated using your login credentials (db, login, password, api-key) in the request headers. If authentication is missing, the request will be denied.

Example: Updating a Product in the product.template Model

How to Configure Odoo REST API Module in Odoo 18-cybrosys

To update a product in the product.template model, use the following request format:

http://cybrounnimaya:8018/send_request?model=product.template&Id=37

Body: 

{
   "fields" :["name","list_price"] ,
   "values": {"name": "Updated Product",
              "list_price":300.0
             }
}

How to Configure Odoo REST API Module in Odoo 18-cybrosys

This request will successfully update the name and price of the specified product in the product.template model.

How to Configure Odoo REST API Module in Odoo 18-cybrosys

Deleting Records Using the DELETE Method

The DELETE method is used to remove existing records from the Odoo database via API requests. To delete a record, you must specify the model name and the ID of the record to be deleted.

Before sending the request, ensure that you have the necessary permissions to delete records for the selected model in the REST API configuration.

Example: Deleting a Product from the product.template Model

How to Configure Odoo REST API Module in Odoo 18-cybrosys

To delete a product from the product.template model, use the following request format:

http://cybrounnimaya:8018/send_request?model=product.template&Id=37

This request will permanently remove the specified product from the product.template model.

How to Configure Odoo REST API Module in Odoo 18-cybrosys

The Odoo REST API module in Odoo 18 provides a seamless and secure way to interact with the Odoo database using standard HTTP methods like GET, POST, PUT, and DELETE. This enables businesses to efficiently integrate third-party applications, automate workflows, and enhance overall system accessibility.

By leveraging API authentication with API keys, users can securely manage database operations without exposing sensitive credentials. The ability to create, update, retrieve, and delete records ensures streamlined data management, reducing manual effort and improving efficiency.

For developers and system administrators, this module offers a powerful tool to extend Odoo’s capabilities, automate tasks, and build scalable integrations. With proper configuration and authentication, the Odoo REST API enhances data accessibility while maintaining robust security controls, making it an essential component for modern business operations.

To read more about How to Connect to an Odoo 16 Using RESTful API, refer to our blog How to Connect to an Odoo 16 Using RESTful API.


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message