Rest API in Odoo 15

HARSHAD
February 24, 2022

REST APIs (also called RESTful APIs) are programming interfaces (API or web API) that adhere to REST’s constraints. It is designed to interact with RESTful web services.

What is an API?

APIs are a set of definitions and protocols for developing and integrating applications. Sometimes, it’s called a contract between an information provider and an information consumer – establishing the content required by the consumer (the request) and the content required by the producer (the response). APIs allow you to communicate what you want to a computer or system so it can understand and fulfill your request if you want to retrieve information or perform a task. Organizations can also share resources and information using this method while maintaining security, control, and authentication — deciding who has access to what.

Features of Odoo REST API

You can create RESTful APIs for Odoo using the REST API Module. It allows access to and modification of data through HTTP requests.

  •  Accessing Endpoints is made easy by creating API keys.
  •  Endpoint users are provided with their own API key.
  •  Access rights can be assigned to multiple API keys in different ways.
  •  A record is created and retrieved from the database.
  •  In a Database, records can be updated or even deleted.
  •  Database records can be searched easily.
  •  Find out how a table’s schema is structured.
  • You can trigger your Odoo actions.
  • In the Endpoint response, you will find a message about access rights.

We can easily create rest Api’s on odoo with the use of controllers. Controllers are basically used to route a request to a function in the system.

Creating a folder called ‘controllers’ in the module is the first step in working with controllers. Then, add this folder to the init file. Then, in the controller’s folder, one can put the init file and Python files for the models.

Here is an example of a simple get API to get all the purchase orders from odoo:


from odoo import HTTP from odoo.http import request

class Purchase(http.Controller):

@http.route('/api/get-po',type='json', auth="public", methods=['GET'], csrf=False)
def po_details(self , **kwargs):
response = []
purchase_details = env[‘purchase.order’].sudo().search([])
for rec in purchase_details:
response.append({
‘po_name’:rec.name,
‘po_date’:rec.date
})
return json.dumps({‘po_name’:rec.name,’po_date’:rec.date})

This is a get api that returns the details of the PO from the system. Just like this, we can create an API of any RESTFUL method.

If you plan a new ERP Software implementation and you have heard about Odoo and got attracted by the Odoo ERP platform, used it but don’t have time, resources, or knowledge to manage this yourself, looking for professional assistance, then you have come to a right place. Bassam Infotech has implemented scores of Odoo ERP all around the world. In addition, we have also developed and delivered our own customized Odoo applications with minimal Odoo implementation cost.

DOWNLOAD OdooSoftware

Bassam Infotech is a company of Official Odoo Certified Experts with 24 years of expertise. We are a one-stop shop for all your business needs, including Odoo Implementation, customization, integration, and support. We’re available by phone or email, with a 24-hour response time in case you need immediate Odoo ERP support. For more details, Call us on +91 88912 49995 or +91 70250 75566 email us at info@bassaminfotech.com or fill out the form to get a free consultation

"Unlock the Full Potential of Your Business with Odoo ERP!"

"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"

Get a Free Quote

Leave a Reply

Your email address will not be published. Required fields are marked *