Skip to Content
Menu

Odoo Custom APIs with REST json Studio

by
Odoo

137.17

v 13.0 Third Party 12
Live Preview
Availability
Odoo Online
Odoo.sh
On Premise
Odoo Apps Dependencies Discuss (mail)
Community Apps Dependencies
Lines of code 2443
Technical Name restjson_studio
LicenseOPL-1
Websitehttps://ekika.co
Versions 12.0 13.0 14.0 15.0 16.0 17.0 18.0
You bought this module and need support? Click here!
Availability
Odoo Online
Odoo.sh
On Premise
Odoo Apps Dependencies Discuss (mail)
Community Apps Dependencies
Lines of code 2443
Technical Name restjson_studio
LicenseOPL-1
Websitehttps://ekika.co
Versions 12.0 13.0 14.0 15.0 16.0 17.0 18.0
Supported Versions 12.0 13.0 14.0 15.0 16.0 17.0 18.0
Community
Enterprise

https://www.ekika.co/support

Odoo Custom REST API Studio

with

EKIKA's "api_framework"

Create, manage, and customize REST API endpoints in Odoo using the API Framework Orchestration. This module empowers developers to build dynamic APIs while maintaining Odoo's standard schema-all without complex coding.

Background Image

Configuring API

RestJson Studio Configuration

How It Works:

  • Code your custom endpoint: Define API methods inside the module.
  • Declare it: Register the endpoint in the system.
  • Publish your API: Enable the Studio feature and deploy your API.
  • Access it externally: Securely call your custom endpoints from any application.

How to Document Your Custom APIs?

  • Create documentation automatically using predefined Swagger-based methods.
  • Use _doc_{yourCustomEndpointMethod} to generate structured API docs.
  • Include details like tags, descriptions, parameters, and responses.

Create Endpoint

  • To create a custom API endpoint, define your methods within the easy.restjson.customstudio model. The corresponding file can be found at: "/models/custom_restjson_studio.py".
  • Use the def my_custom_restjson(cls) method to define your API endpoint. Ensure that the method returns a dictionary of endpoints. You can refer to an example in: "/models/custom_restjson_studio.py".
  • Define a method with a name that matches one of the keys in the dictionary mentioned above. Ensure that the method includes params as a parameter.
  • The methods you implement must return either a dictionary object or a response.
  • Access your defined custom endpoints using the following format: {your-web-domain[:port]}/{your-api-endpoint}/{your-custom-endpoint}.

Create your own documentation

Note: Default documentation generated automatically for your custom endpoints with open api (swagger) spec.

  • To achieve this, create a method in the easy.restjson.customstudio model. The relevant file can be found at: "/models/custom_restjson_studio.py". Name the method starting with "_doc_" followed by your custom endpoint method name, such as "_doc_{yourCustomEndpointMethod}".
  • This method should return a dictionary in the Swagger format, including keys like "tags, summary, description, parameters, responses," etc. You can refer to an example in "/models/custom_restjson_studio.py".

For more detail please refer below examples

*** python ***

import json
from werkzeug.datastructures import Headers
from odoo import models
from odoo.http import request, Response


class MyRestJsonCustomStudio(models.AbstractModel):
    _inherit = 'easy.restjson.customstudio'

    @classmethod
    def my_custom_restjson(cls):
        res = super().my_custom_restjson()
        res.update(
            {
                'getContacts': {'method': 'GET'},
                'getContactDetails': {'method': 'GET'},
                'createContact': {'method': 'POST'},
                'resetPasswordMail': {'method': 'POST'},
            }
          )
        return res

    @classmethod
    def getContacts(cls, params) -> dict:
        """Get list of contacts
        return list of contacts with name, email fields.
        """
        try:
            partners = request.env['res.partner'].search_read([], fields=['name', 'email'])
            result = {'data': {'contacts': partners}}
        except Exception as exc:
            result = {'errors': exc.args}
        return result

    @classmethod
    def getContactDetails(cls, params) -> dict:
        try:
            partner = request.env['res.partner'].browse(int(params['partner_id']))
            result = {'data': {'contactDetails': partner.read(fields=['name', 'email', 'phone'])}}
            data = json.dumps(result, ensure_ascii=False)
            headers = Headers()
            headers['Content-Length'] = len(data)
            headers['Content-Type'] = 'application/json; charset=utf-8'
            return Response(data, headers=headers ,status=200)
        except Exception as exc:
            result = {'errors': exc.args}
        return result

    @classmethod
    def createContact(cls, params) -> dict:
        try:
            partner = request.env['res.partner'].create({'name': params['name'], 'email': params['email']})
            result = {'data': {'contactDetails': partner.read(fields=['name', 'email'])}}
        except Exception as exc:
            result = {'errors': exc.args}
        return result

    @classmethod
    def _doc_createContact(cls) -> dict:
        return {
            'tags': ['Create Contact'],
            'summary': 'Create Partner Contact',
            'description': 'Create partner using name and email',
            'parameters': [
              {
                "in": "body",
                "name": "create-contact",
                "description": "Create Contact Body",
                "required": True,
                "schema": {
                  "type": "object",
                    "properties": {
                      "name": {
                        "type": "string"
                      },
                      "email": {
                        "type": "string"
                      },
                    },
                }
              }
            ],
            'responses': cls._swagger_default_responses()
        }

    @classmethod
    def resetPasswordMail(cls, params) -> dict:
        try:
            user = request.env['res.users'].browse(int(params['user_id']))
            user.action_reset_password()
            result = {'data': {'message': 'Password reset email sent successfully.'}}
        except Exception as exc:
            result = {'errors': {'message': 'Failed to send the password reset email.'}}
        return result

Request Considering above Examples:

RoundGet Contacts

Get Partner List Request
*** python ***

import requests
import json

url = "http://localhost:8018/restjson-apikey/getContacts"

payload = {}
headers = {
  'Content-Type': 'application/json',
  'x-api-key': 'YOUR-API-KEY'
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

RoundGet Contact Details

Get Partner Details Request
*** python ***

import requests
import json

url = "http://localhost:8018/restjson-apikey/getContactDetails?partner_id=3"

payload = {}
headers = {
  'Content-Type': 'application/json',
  'x-api-key': 'YOUR-API-KEY'
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

RoundCreate Contact

Create Partner Request
*** python ***

import requests
import json

url = "http://localhost:8018/restjson-apikey/createContact"

payload = json.dumps({
  "name": "sample partner 1",
  "email": "sample-partner-1@example.com"
})
headers = {
  'Content-Type': 'application/json',
  'x-api-key': 'YOUR-API-KEY'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

RoundReset Password Mail

Reset Password Mail
*** python ***

import requests
import json

url = "http://localhost:8018/restjson-apikey/resetPasswordMail?user_id=2"

payload = {}
headers = {
  'Content-Type': 'application/json',
  'x-api-key': 'YOUR-API-KEY'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Swagger Documentation

Document View Setting 1 Document View Setting 2

Frequently Asked Questions (FAQs)

Find answers of common questions you might have about this addon. If you don't see your question addressed here, feel free to contact us!

Contact Us:

  • Whats App / Phone: +919510031431 -- URGENT
  • EMail: hello@ekika.co
  • Skype: amshukla17
  • Website: https://ekika.co
  • Support Ticket: https://ekika.co/support -- Get Notifications of Progress.
  • 24 x 7 Available! Contact us NOW.

We love hearing your ideas for improvement! If you have a feature in mind that would make your Odoo experience even better, simply contact us. We're happy to discuss your needs and explore the best way to implement them.

We offer a wide range of Odoo services to help you at any stage, from initial setup ("implementation") to ongoing customization and support. This includes:

  • Adding new features and functionalities ("addons development")
  • Changing behaviour of whole system ("server and structure level changes")
  • Server maintenance and configuration changes ("nginx / filestores / size issues etc.")
  • Integration with other systems
  • RESTful APIs, WebHooks, Slave-Master DB, Real-time data communication ("socket connection") etc.
  • Improving app performance and user experience ("performance tuning" and "UI/UX design")
  • Secure and reliable managed hosting solutions
  • Annual maintenance contracts to keep your Odoo running smoothly and so much more...

Basically, we're your one-stop shop for all things Odoo! We offer premium services at competitive rates.

Need Help?

EKIKA Has Your Back - 24/7 Support.

We're just a message away, no matter the time zone.

90 Days Free Support

We understand that even with great documentation, you might have questions or need additional assistance. That's why we offer exceptional support for "api_framework".

https://ekika.co/api
Documentation & User Guide
(copy link to clipboard)
https://www.youtube.com/@ekika_co/videos
Video Guide
(copy link to clipboard)
https://ekika.co/support
Support
(copy link to clipboard)

Services EKIKA Provides

EKIKA is your destination for expert Odoo ERP implementation and customization. We pride ourselves on building reliable, trust-based partnerships that give you full transparency and control over your business processes.

With over 12 years of experience, we can assist you with eCommerce platforms, production planning, point-of-sale systems, managing inventory adjustments, and providing advanced field worker tracking solutions to optimize your workflows and boost operational efficiency.

Ekika Odoo Implementation

Implementation

Utilise Odoo ERP tailored for your business needs for smooth operations.

Ekika Odoo Customization

Customization

Personalized adjustments to Odoo modules for seamless management.

Ekika Odoo Support

Support

Ongoing assistance and maintenance to optimize your Odoo system's performance.

Are you struggling with disorganized operations, high operational costs, or lack of transparency in your processes? What sets us apart is our commitment to personalized solutions tailored to your unique business needs and our proactive support, ensuring seamless integration and ongoing success.

Would you like to explore Odoo ERP for your business? Schedule a free consultation with EKIKA today!

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.