Odoo Json API

by
Odoo

61.93

v 17.0 Third Party 4
Live Preview
Availability
Odoo Online
Odoo.sh
On Premise
Odoo Apps Dependencies Discuss (mail)
Community Apps Dependencies
Lines of code 2562
Technical Name easy_jsonapi
LicenseOPL-1
Websitehttps://ekika.co
Versions 17.0 16.0 15.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 2562
Technical Name easy_jsonapi
LicenseOPL-1
Websitehttps://ekika.co
Versions 17.0 16.0 15.0

{ json:api }

Introduction

JSON API is a specification for building APIs (Application Programming Interfaces) in JSON format. It provides guidelines for how client applications can request and receive data from a server. Know more

How It Works

JSON API works by defining a specific structure for API requests and responses, allowing for consistency and ease of use. Here’s how it works:

Request:

  1. Endpoint: Clients make requests to specific endpoints (URLs) on the server to retrieve or manipulate resources. For example, a client might request a list of articles from the “/articles” endpoint.
  2. HTTP Methods: JSON API uses standard HTTP methods like GET, POST, PATCH, and DELETE for different operations. GET is used to retrieve data, POST to create new resources, PATCH to update existing resources, and DELETE to remove resources.
  3. Parameters: Clients can include query parameters in the request URL to specify filtering, sorting, pagination, sparse fieldsets, or include related resources. For instance, clients can request only specific fields of a resource, or request related data to be included in the response.

Example of a JsonAPI Requests:

  • GET Requests:
  1. Sparse Fieldsets: Get sale.order with only the “name”, “partner_id”, “date_order” fields included in the response. GET /sale.order?fields[sale.order]=name,partner_id,date_order
  2. Including Related Resources: Get sale.order and include the related partner_id in the response. /sale.order?fields[sale.order]=partner_id&include=partner_id
  3. Pagination: Get the second page of sale.order with 5 records per page. GET /sale.order?page[number]=2&page[size]=5
  4. Sort: Get sale.order sorted by their date_order in descending order. GET /sale.order?sort=-date_order
  5. Filter: Get sale.order filter by standard odoo domain, consider below example. GET /sale.order?filter=[AND, OR, ('state', '=', 'sale'), OR, ('state', '=', 'cancel'), ('team_id', '=', 5), OR, AND, ('amount_total', '>', 1000), ('team_id', '=', 1), OR, ('partner_id', '=', 11), ('user_id', '=', 6)]
  • Read Records Example:

JsonAPI-Read

import requests
import json

url = "https://easyapi.ekika.app/user-jsonapi-apikey/res.partner?fields[res.partner]=name,is_company,email,phone,country_id,user_id,company_id&fields[res.country]=name,code&fields[res.users]=name,active&include=country_id,user_id,company_id&fields[res.company]=name&page[number]=1&page[size]=5&sort=name,-id&filter=[('is_company', '=', true)]"

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

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

print(response.text)
  • Read Single Record Example:

JsonAPI-Read-Single-Record

import requests
import json

url = "https://easyapi.ekika.app/user-jsonapi-apikey/res.partner/33?fields[res.partner]=name,is_company,email,phone,country_id,user_id,company_id&fields[res.country]=name,code&fields[res.users]=name,active&include=country_id,user_id,company_id&fields[res.company]=name"

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

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

print(response.text)
  • POST Requests:
  • Create Request Example:

JsonAPI-Create

import requests
import json

url = "https://easyapi.ekika.app/user-jsonapi-apikey/res.partner"

payload = json.dumps({
  "data": {
    "type": "res.partner",
    "attributes": {
      "active": True,
      "name": "Ekika Corporation",
      "company_type": "company",
      "city": "Gandhinagar",
      "street": "Gandhinagar",
      "zip": "382421",
      "comment": "<p>Comment Here</p>",
      "phone": "5554444555444",
      "mobile": "1010101",
      "website": "http://www.ekika.co",
      "email": "hello@ekika.co"
    },
    "relationships": {
      "category_id": {
        "data": [
          {
            "type": "res.partner.category",
            "id": "4"
          },
          {
            "type": "res.partner.category",
            "id": "3"
          }
        ]
      },
      "bank_ids": {
        "data": [
          {
            "type": "res.partner.bank",
            "attributes": {
              "sequence": 10,
              "bank_id": 2,
              "acc_number": "11212121212",
              "allow_out_payment": True,
              "acc_holder_name": False
            }
          },
          {
            "type": "res.partner.bank",
            "attributes": {
              "sequence": 11,
              "bank_id": 3,
              "acc_number": "3434343434343434",
              "allow_out_payment": True,
              "acc_holder_name": False
            }
          }
        ]
      }
    }
  }
})
headers = {
  'Content-Type': 'application/vnd.api+json',
  'x-api-key': 'YOUR-API-KEY'
}

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

print(response.text)
  • PATCH Requests:

  • Update Request Example:

JsonAPI-Update

import requests
import json

url = "https://easyapi.ekika.app/user-jsonapi-apikey/res.partner/1061"

payload = json.dumps({
  "data": {
    "type": "res.partner",
    "id": 1061,
    "attributes": {
      "active": True,
      "name": "Ekika Corporation Pvt Ltd.",
      "company_type": "company",
      "city": "Gandhinagar",
      "street": "Gandhinagar",
      "zip": "000000",
      "comment": "<p>Comment Here</p>",
      "phone": "5554444555444",
      "mobile": "1010101",
      "website": "http://www.ekika.co",
      "email": "hello@ekika.co"
    },
    "relationships": {
      "category_id": {
        "data": []
      },
      "bank_ids": {
        "data": [
          {
            "type": "res.partner.bank",
            "id": 26,
            "attributes": {
              "sequence": 25,
              "bank_id": 2,
              "acc_number": "999999",
              "allow_out_payment": True,
              "acc_holder_name": False
            }
          }
        ]
      }
    }
  }
})
headers = {
  'Content-Type': 'application/vnd.api+json',
  'x-api-key': 'YOUR-API-KEY'
}

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

print(response.text)
  • DELETE Requests:

  • Delete Request Example:

JsonAPI-Delete

import requests
import json

url = "https://easyapi.ekika.app/user-jsonapi-apikey/res.partner/1061"

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

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

print(response.text)

References:

  • Visit Json-API Specification
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.