Json API v1.1 for Odoo

by
Odoo

50.36

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 2885
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 2885
Technical Name easy_jsonapi
LicenseOPL-1
Websitehttps://ekika.co
Versions 17.0 16.0 15.0
Background Image

Introduction

JSON API is a specification for how a client should request resources to be fetched or modified, and how a server should respond to those requests. It provides a consistent and standardized way to structure JSON responses and requests, making it easier to develop and consume APIs.

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.

You'll see every requests in detail with step by step guidance below.

JSON API Get Request Overview:

A GET Request in JSON API is a request to retrieve data from a server, in here it's retrieve data from odoo. It typically involves specifying the endpoint URL along with optional query parameters to filter or shape the response data. The response from the server is usually in JSON format, containing the requested data or an error message.

GET
{domain[:port]}/{endpoint}/{model}
  • This is the main query parameters which is mandatory to write when you are working with APIs.
  • Use "HTTP Get Method" to retrieve specific record from odoo.
  • Domain is specified your wesite's domain address. The port number is optional.
  • Endpoint is the specific path within the API that identifies the particular resource or action. This part of the URL tells the server what type of operation is being requested.
  • Model is Odoo's technical name of entities and also known as model name, record's model or entities. You can identify it from the URL shown below.
  • Domain Image
  • To insert query we have to add "?" after the model, so it will indicates that query parameters is starting.
  • All other query parameters are included after model that you can see on next tabs.
  • Headers in an API request are key-value pairs sent between the client and the server, providing additional information about the request or the client itself. They are part of the HTTP protocol and can carry various types of metadata.
  • Add "Content-Type" and "x-api-key" keys with their specific values. JSON API's media type designation is "application/vnd.api+json". Add this in Content-Type's value field and also add your API Key.
  • Ekika Header Image

Get Record with ID:

GET
{domain[:port]}/{endpoint}/{model}/{id}
  • The id indicates that specific record we want to retrieve.

See the Example(1) & Example(2) with Query Parameters and Output:

Example(1): This JSON API query fetches data for the sale.order model with ID 16 from the specified endpoint demotestapi.

Query: http://api.17.dev.ekika.co/demotestapi/sale.order/16

Query Parameters Output
Ekika JSON API Get Records with ID Query
Ekika JSON API Get Records with ID Output

Example(2): This JSON API query fetches data for the res.partner model with ID 14 from the specified endpoint demotestapi.

Query: http://api.17.dev.ekika.co/demotestapi/res.partner/14

Query Parameters Output
Ekika JSON API Get Records with ID Query
Ekika JSON API Get Records with ID Output

Get Record with Fields:

GET
{domain[:port]}/{endpoint}/{model}?fields[{model}]=field_name
  • The fields parameter is used to specify which fields of the model you want to retrieve. It's structured as "fields[{model}]=field_name"

See the Example(1) & Example(2) with Query Parameters and Output:

Example(1): This JSON API query retrieves specific fields name and date_order for all sale orders from the endpoint demotestapi.

Query: http://api.17.dev.ekika.co/demotestapi/sale.order?fields[sale.order]=name,date_order

Query Parameters Output
Ekika JSON API Get Records with Fields Query
Ekika JSON API Get Records with Fields Output

Example(2): This JSON API query retrieves only the name and email fields for all res partners from the specified endpoint demotestapi.

Query: http://api.17.dev.ekika.co/demotestapi/res.partner?fields[res.partner]=name,email

Query Parameters Output
Ekika JSON API Get Records with Fields Query
Ekika JSON API Get Records with Fields Output

Get Record with Pagination:

GET
{domain[:port]}/{endpoint}/{model}?page[number]=1&page[size]=4
  • The page number parameter specifies the page number of the records you want to retrieve. The "page[number]=1" indicates the first page.
  • The page size parameter determines the number of records to be returned per page. The "page[size]=4" means that each page should contain four records.

See the Example(1) & Example(2) with Query Parameters and Output:

Example(1): This JSON API query fetches the first page of sale orders with a page size of 4 from the specified endpoint demotestapi.

Query: http://api.17.dev.ekika.co/demotestapi/sale.order?page[number]=1&page[size]=4

Query Parameters Output
Ekika JSON API Get Records with Pagination Query
Ekika JSON API Get Records with Pagination Output

Example(2): This JSON API query retrieves the fifth page of res partners, with each page containing 3 res partners, from the specified endpoint demotestapi.

Query: http://api.17.dev.ekika.co/demotestapi/res.partner?page[number]=5&page[size]=3

Query Parameters Output
Ekika JSON API Get Records with Pagination Query
Ekika JSON API Get Records with Pagination Output

Get Record with Sorting:

GET
{domain[:port]}/{endpoint}/{model}?sort={fields_name}
  • The sort indicates the records to be sorts based on the specified field in ascending order sort={fields_name}. For Descending use "-", sort=-{fields_name}.

See the Example(1) & Example(2) with Query Parameters and Output:

Example(1): This JSON API query fetches sale orders from the endpoint demotestapi sorted by the name field in ascending order.

Query: http://api.17.dev.ekika.co/demotestapi/sale.order?sort=name

Query Parameters Output
Ekika JSON API Get Records with Sorting Query
Ekika JSON API Get Records with Sorting Output

Example(2): This JSON API query fetches sale orders from the endpoint demotestapi sorted primarily by the date_order field in ascending order, and then by the name field in ascending order as a secondary sorting criteria.

Query: http://api.17.dev.ekika.co/demotestapi/sale.order?sort=date_order,name

Query Parameters Output
Ekika JSON API Get Records with Sorting Query
Ekika JSON API Get Records with Sorting Output

Get Record with Filter:

GET
{domain[:port]}/{endpoint}/{model}?filter={domain}
  • The filter parameter is used to specify the filtering criteria in Odoo domain notation filter={domain}.
  • In Odoo domain notation, filtering conditions are represented as lists. The basic structure typically involves a combination of logical operators (AND, OR) and tuples representing field, operator, and value conditions. Using Odoo domain notation allows for advanced filtering capabilities, enabling the retrieval of specific records that meet complex criteria.

See the Example(1) with Query Parameters and Output:

Example(1): This JSON API query filters sale orders based on the conditions:

  • State is either 'sale' or 'cancel'.
  • Team ID is either 5 or 1.
  • Amount total is greater than 1000 and team ID is 1.
  • Partner ID is 11 or user ID is 6.

Query: http://api.17.dev.ekika.co/demotestapi/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)]

Query Parameters Output
Ekika JSON API Get Records with Filter Query
Ekika JSON API Get Records with Filter Output

Get Record with Relational Fields:

GET
{domain[:port]}/{endpoint}/{model}?fields[{model}]=field_name
  • The fields[{model}]=field_name parameter allows the selection of specific fields from the model, including relational fields.
  • Relational fields in a database model establish relationships between different entities or models. For example, in the "sale.order" model, partner_id represent a relationship with the res.partner model.

See the Example(1) & Example(2) with Query Parameters and Output:

Example(1): This JSON API query fetches only the specified fields name, partner_id, and payment_term_id for all sale orders from the specified endpoint demotestapi.

Query: http://api.17.dev.ekika.co/demotestapi/sale.order?fields[sale.order]=name,partner_id,payment_term_id

Query Parameters Output
Ekika JSON API Get Records with Relational Fields Query
Ekika JSON API Get Records with Relational Fields Output

Example(2): This JSON API query retrieves the specified fields name, parent_id, and child_ids for all partners from the provided endpoint demotestapi.

Query: http://api.17.dev.ekika.co/demotestapi/res.partner?fields[res.partner]=name,parent_id,child_ids

Query Parameters Output
Ekika JSON API Get Records with Relational Fields Query
Ekika JSON API Get Records with Relational Fields Output

Get Record with Relational Fields with Include:

GET
{domain[:port]}/{endpoint}/{model}?fields[{model}]=field_name&include=relational_field
  • The fields[{model}]=field_name parameter allows the selection of specific fields from the model, including relational fields.
  • The include parameter instructs the API to include the related data for the specified relational field in the response.
  • Relational fields establish connections or relationships between different entities or models.

See the Example(1) & Example(2) with Query Parameters and Output:

Example(1): This JSON API query fetches sale orders with fields name, partner_id, and date_order, and includes related partner information for each sale order.

Query: http://api.17.dev.ekika.co/demotestapi/sale.order?fields[sale.order]=name,partner_id,date_order&include=partner_id

Query Parameters Output
Ekika JSON API Get Records with Relational Fields with Include Query
Ekika JSON API Get Records with Relational Fields with Include Output

Example(2): This JSON API query retrieves partner data with fields name, parent_id, and child_ids, while also including information about the parent partner for each partner entry.

Query: http://api.17.dev.ekika.co/demotestapi/res.partner?fields[res.partner]=name,parent_id,child_ids&include=parent_id

Query Parameters Output
Ekika JSON API Get Records with Relational Fields with Include Query
Ekika JSON API Get Records with Relational Fields with Include Output

Get Record with Relational Fields, Include and Relational Include Data:

GET
{domain[:port]}/{endpoint}/{model}?fields[{model}]=field_name&include=relational_field&fields[{relation_model}]=field_name
  • The fields[{model}]=field_name parameter allows the selection of specific fields from the model, including relational fields.
  • The fields[{relation_model}]=field_name parameter allows the selection of specific fields from related models.
  • The include parameter instructs the API to include the related data for the specified relational field in the response.
  • Relational fields establish connections or relationships between different entities or models.

See the Example(1) & Example(2) with Query Parameters and Output:

Example(1): This JSON API query fetches sale order data with fields name, partner_id, and date_order, including partner information for each sale order with fields name and email.

Query: https://api.17.dev.ekika.co/demotestapi/sale.order?fields[sale.order]=name,partner_id,date_order&include=partner_id&fields[res.partner]=name,email

Query Parameters
Ekika JSON API Get Records with Relational Fields, Include and Relational Include Data Query
Output
Ekika JSON API Get Records with Relational Fields, Include and Relational Include Data Output
Ekika JSON API Get Records with Relational Fields, Include and Relational Include Data Output

Example(2): This JSON API query retrieves sale order data with specific fields name, partner_id, order_line, and tag_ids, including related order lines and tags. Additionally, it fetches partner information with fields name and email, along with product quantity details for each order line, and tag names for each tag.

Query: https://api.17.dev.ekika.co/demotestapi/sale.order?fields[sale.order]=name,partner_id,order_line,tag_ids&include=order_line,partner_id,tag_ids&fields[res.partner]=name,email&fields[sale.order.line]=name,product_uom_qty&fields[crm.tag]=name

Query Parameters
Ekika JSON API Get Records with Relational Fields, Include and Relational Include Data Query
Output
Ekika JSON API Get Records with Relational Fields, Include and Relational Include Data Output
Ekika JSON API Get Records with Relational Fields, Include and Relational Include Data Output

JSON API Create Request Overview:

A POST Request in a JSON API is a way to send data to odoo to create a new resource. In a POST request, the data to be created is typically sent in the body of the request in JSON format.

POST
{domain[:port]}/{endpoint}/{model}
  • This is the main query parameters which is mandatory to write when you are working with APIs.
  • Use "HTTP POST Method" to create records in odoo.
  • Domain is specified your wesite's domain address. The port number is optional.
  • Endpoint is the specific path within the API that identifies the particular resource or action. This part of the URL tells the server what type of operation is being requested.
  • Model is Odoo's technical name of entities and also known as model name, record's model or entities. You can identify it from the URL shown below.
  • Domain Image
  • In Post Request Method you don't have to write any query parameters in the request field like in Get Request Method, you simply write the queries in JSON Format in the body field.
  • Headers in an API request are key-value pairs sent between the client and the server, providing additional information about the request or the client itself. They are part of the HTTP protocol and can carry various types of metadata.
  • Add "Content-Type" and "x-api-key" keys with their specific values. JSON API's media type designation is "application/vnd.api+json". Add this in Content-Type's value field and also add your API Key.
  • Ekika Header Image
Odoo's ORM (Object-Relational Mapping) & Field Types:

Odoo's ORM (Object-Relational Mapping) system allows you to define relationships between different models in your application. These relationships can be established using many2many, many2one, and one2many fields.

  • One2many: A one2many field creates a one-to-many relationship between the current model and another model. This means a single record of the current model is linked to multiple records of another model. It is defined as the inverse of a many2one field.
  • Many2one: A many2one field creates a many-to-one relationship between the current model and another model. This means multiple records of the current model can be linked to a single record of another model. It is essentially a foreign key.
  • Many2many: A many2many field creates a many-to-many relationship between two models. This means multiple records of the current model can be linked to multiple records of another model. This relationship is usually managed through a join table.

Create Record with attributes:

Query:
    {
    "data": {
    "type": "res.partner",
    "attributes": {
    "name": "Demo Corporation Pvt Ltd.",
    "email": "demo@mail.com"
    "mobile": "1020304050",
    "company_type": "company",
    }
    }
    }
    

Example(1): This JSON API query Creates new res.partner with mentioned attributes like name, email, mobile, and company type.

Query Parameters Output
Ekika JSON API Create Records with Attributes Query
Ekika JSON API Create Records with Attributes Output

Create Record with relationship One2many Field:

  • Relationships: Defines any related resources associated with the partner entity being created. In this case, there is a relationship named "bank_ids" representing the bank accounts associated with the partner entity.
Query:
    {
    "data": {
    "type": "res.partner",
    "attributes": {
    "name": "Demo Corporation Pvt Ltd.",
    "email": "demo@mail.com",
    "mobile": "1020304050",
    "company_type": "company"
    },
    "relationships": {
    "bank_ids":{
        "data": [
            {
            "type": "res.partner.bank",
            "attributes": {
                "sequence": 10,
                "bank_id": 2,
                "acc_number": "11212121212",
                "allow_out_payment": true,
                "acc_holder_name": false
                }
            }
        ]
    }
    }
    }
    }
    

Example(1): This request is structured according to JSON API conventions, facilitating the creation of a partner entity with associated bank accounts in a standardized manner.

Query Parameters Output
Ekika JSON API Create Records with Relationship One2many Field Query
Ekika JSON API Create Records with Relationship One2many Field Output

Create Record with relationship Many2One Field:

  • Relationships: Defines any related resources associated with the partner entity being created. In this case, there is a relationship named "user_id" representing the user accounts associated with the partner entity.
Query:
    {
    "data": {
    "type": "res.partner",
    "attributes": {
    "name": "Demo Corporation Pvt Ltd.",
    "email": "demo@mail.com",
    "mobile": "1020304050",
    "company_type": "company"
    },
    "relationships": {
    "user_id": {
      "data": {
          "type": "res.users",
          "id": 2
        }
    }
    }
    }
    }
    

Example(1): This request is structured according to JSON API conventions, facilitating the creation of a partner entity with associated user accounts in a standardized manner.

Query Parameters Output
Ekika JSON API Create Records with Relationship Many2One Field Query
Ekika JSON API Create Records with Relationship Many2One Field Output

Create Record with relationship Many2Many Field:

  • Relationships: Defines any related resources associated with the partner entity being created. In this case, there is a relationship named "category_id" representing the categories associated with the partner entity.
Query:
    {
    "data": {
    "type": "res.partner",
    "attributes": {
    "name": "Demo Corporation Pvt Ltd.",
    "email": "demo@mail.com",
    "mobile": "1020304050",
    "company_type": "company"
    },
    "relationships": {
    "category_id": {
      "data": [
          {
          "type": "res.partner.category",
          "id": "4"
          },
          {
          "type": "res.partner.category",
          "id": "5"
          }
        ]
    }
    }
    }
    }
    

Example(1): This request is structured according to JSON API conventions, facilitating the creation of a partner entity with associated categories in a standardized manner.

Query Parameters Output
Ekika JSON API Create Records with Relationship Many2Many Field Query
Ekika JSON API Create Records with Relationship Many2Many Field Output

Create Record with Odoo's field types "One2Many", "Many2One", and "Many2Many" together:

  • Use odoo field types, "One2Many", "Many2One", and "Many2Many" all in 1 request.
Query:
    {
    "data": {
    "type": "res.partner",
    "attributes": {
    "name": "Jannie wills",
    "email": "jannie@mail.com",
    "mobile": "1002003005"
    "function": "CTO",
    "city": "London",
    "street": "London st139"
    },
    "relationships": {
    "bank_ids":{
        "data": [
            {
            "type": "res.partner.bank",
            "attributes": {
                "sequence": 20,
                "bank_id": 2,
                "acc_number": "1230321",
                "allow_out_payment": true,
                "acc_holder_name": true
                }
            }
        ]
    },
    "user_id": {
        "data": {
            "type": "res.users",
            "id": 2
        }
    },
    "category_id": {
        "data": [
            {
            "type": "res.partner.category",
            "id": "4"
            },
            {
            "type": "res.partner.category",
            "id": "5"
            }
        ]
    }
    }
    }
    }
    

Example(1): This request is structured according to JSON API conventions, facilitating the creation of a partner entity with associated Bank Accounts as One2many in a standardized manner and also a Sales Person assign to it as "Many2one" field type, and gave multile Tags to that person as "Many2many" field type.

Query Parameters Output
Ekika JSON API Create Records with Multiple Relationships Query
Ekika JSON API Create Records with Multiple Relationships Query

Record's created in dashboard.

Output Output
Ekika JSON API Create Records with Multiple Relationships Output
Ekika JSON API Create Records with Multiple Relationships Output

Date & Time format in Odoo:

  • In Odoo, date fields are used to store date and datetime values in the models. These fields are essential for tracking and managing time-related data, such as order dates, due dates, creation dates, etc. Odoo provides specific field types to handle date and datetime data effectively.
  • By default Odoo handles time zones by storing all datetime values in the database in Coordinated Universal Time (UTC).
How Odoo Handles Time Zones?
  1. Storage in UTC:
    • All datetime values are stored in UTC in the database. This approach ensures a single, consistent time reference.
  2. Conversion to User's Local Time Zone:
    • When a datetime value is displayed to a user, Odoo automatically converts it from UTC to the user's local time zone. The user's time zone can be set in their preferences.
  3. Setting User Time Zone:
    • Each user in Odoo can have their own time zone setting. This can be configured in the user's preferences under the "Preferences" menu.
Query:
    {
    "data": {
    "type": "sale.order",
    "attributes": {
    "date_order": "2023-06-12 10:22:57"
    },
    "relationships": {
    "partner_id": {
    "data": {
    "type": "res.partner",
    "id": "80"
    }
    },
    "tag_ids": {
    "data": [
    {
      "type": "crm.tags",
      "id": "2"
    },
    {
      "type": "crm.tags",
      "id": "1"
    }
    ]
    },
    "order_line": {
    "data": [
    {
      "type": "sample",
      "attributes": {
        "product_id": "36",
        "product_uom_qty": 6,
        "price_unit": "650.50"
      }
    },
    {
      "type": "sample",
      "attributes": {
        "product_id": "16",
        "product_uom_qty": 3,
        "price_unit": "680.75"
      }
    }
    ]
    }
    }
    }
    }
    

This JSON request is designed to create a new sale.order record in Odoo. It includes:

  • The order date and time.
  • A relationship to a customer (res.partner with ID 80).
  • Associations with two tags (crm.tags with IDs 2 and 1).
  • Two order lines, each specifying product details, quantities, and prices.

For better understanding, we added the example images below.

Query Parameters Output
Ekika JSON API Create Records Date & Time Format Query
Ekika JSON API Create Records Date & Time Format Output

You can see that in below image, we add the time 10:22:57 when writing the query, and it is showing the time 03:52:57 as the timezone which selected by us(IST). So, Odoo takes the time as UTC timezone.

Ekika JSON API Create Records Date & Time Format Output

Selection Field in Odoo:

  • Selection fields in Odoo are fields that allow users to choose from a predefined list of options.
Query:
    {
    "data": {
    "type": "res.partner",
    "attributes": {
    "name": "Maggie",
    "email": "maggie@mail.com",
    "mobile": "1002003005",
    "function": "CTO",
    "city": "London",
    "street": "London st139",
    "ubl_cii_format": "ubl_bis3"
    }
    }
    }
    

We added the example images below for better understanding.

Note: Write the Key of the specific values in query while you are creating a new record. Refer the query parameters image.

Query Parameters Output
Ekika JSON API Create Records Selection Field Query
Ekika JSON API Create Records Selection Field Output

Below is the created record image which shows the selection field options list. You can add the option diectly while creating a new record, just make sure to write the Key Field in the query not the value.

Ekika JSON API Create Records Selection Field Output

JSON API Update Request Overview:

A Update Request JSON API is used to modify existing resources on odoo. This typically involves sending an HTTP PATCH request to the API endpoint demotestapi that corresponds to the resource you want to update.

PATCH
{domain[:port]}/{endpoint}/{model}
  • This is the main query parameters which is mandatory to write when you are working with APIs.
  • Use "HTTP PATCH Method" to update the records in odoo.
  • Domain is specified your wesite's domain address. The port number is optional.
  • Endpoint is the specific path within the API that identifies the particular resource or action. This part of the URL tells the server what type of operation is being requested.
  • Model is Odoo's technical name of entities and also known as model name, record's model or entities. You can identify it from the URL shown below.
  • Domain Image
  • In PATCH Request Method you have to write some query parameters in the request field like in Get Request Method, you will learn about that in next tabs when you move forwad in this documentation.
  • Headers in an API request are key-value pairs sent between the client and the server, providing additional information about the request or the client itself. They are part of the HTTP protocol and can carry various types of metadata.
  • Add "Content-Type" and "x-api-key" keys with their specific values. JSON API's media type designation is "application/vnd.api+json". Add this in Content-Type's value field and also add your API Key.
  • Ekika Header Image
Odoo's ORM (Object-Relational Mapping) & Field Types:

Odoo's ORM (Object-Relational Mapping) system allows you to define relationships between different models in your application. These relationships can be established using many2many, many2one, and one2many fields.

  • One2many: A one2many field creates a one-to-many relationship between the current model and another model. This means a single record of the current model is linked to multiple records of another model. It is defined as the inverse of a many2one field.
  • Many2one: A many2one field creates a many-to-one relationship between the current model and another model. This means multiple records of the current model can be linked to a single record of another model. It is essentially a foreign key.
  • Many2many: A many2many field creates a many-to-many relationship between two models. This means multiple records of the current model can be linked to multiple records of another model. This relationship is usually managed through a join table.

Update Record with Attributes:

Here, we already created a res partner ID 96, in which we are going to perform update records query to upadate the records.

Query:
    {
    "data": {
    "type": "res.partner",
    "id": 96,
    "attributes": {
    "name": "Joey Tribbiani",
    "email": "Joey@mail.com",
    "mobile": 1299129900,
    "city": "Gandhinagar",
    "website": "http://www.demosite.com",
    "function": "CTO"
    }
    }
    }
    

Example(1): This JSON object represents a PATCH request to update the details of a specific resource ID 96 in an API that uses the JSON.

Query Parameters Output
Ekika JSON API Update Records with Attributes Query
Ekika JSON API Update Records with Attributes Query
  • We created a res partner. Then we add the data of that person with the id which is assign to that person, in this case it's ID 96.
  • The request changes several attributes of this partner, such as their name, email, mobile number, city, website, and function showed in below image.
Ekika JSON API Update Records with Attributes Output

Update Record with relationship One2many Field:

  • Relationships: Defines any related resources associated with the partner entity being updated. In this case, there is a relationship named "bank_ids" representing the bank accounts associated with the partner entity.
Query:
    {
    "data": {
    "type": "res.partner",
    "id": 96,
    "attributes": {
    "name": "Joey Tribbiani",
    "email": "Joey@mail.com",
    "mobile": 1299129900,
    "city": "Gandhinagar",
    "website": "http://www.demosite.com",
    "function": "CTO"
    },
    "relationships": {
    "bank_ids":{
        "data": [
            {
            "type": "res.partner.bank",
            "attributes": {
                "sequence": 10,
                "bank_id": 2,
                "acc_number": "23002300",
                "allow_out_payment": true,
                "acc_holder_name": true
                }
            }
        ]
    }
    }
    }
    }
    

Example(1): This request is update the bank account details of the user with ID 96.

Query when create record Query after update record
Ekika JSON API Update Records with Relationship One2many Field Query
Ekika JSON API Update Records with Relationship One2many Field Query
  • The request changes the relationship data of related bank account details of the person showed in below images.
Account number when created Account number after updated
Ekika JSON API Update Records with Relationship One2many Field Output
Ekika JSON API Update Records with Relationship One2many Field Output

Update Record with relationship Many2One Field:

  • Relationships: Defines any related resources associated with the partner entity being updated In this case, there is a relationship named "user_id" representing the user accounts associated with the partner entity.
Query:
    {
    "data": {
    "type": "res.partner",
    "attributes": {
    "name": "Joey Tribbiani",
    "email": "Joey@mail.com",
    "mobile": 1299129900,
    "city": "Gandhinagar",
    "website": "http://www.demosite.com",
    "function": "CTO"
    },
    "relationships": {
    "user_id": {
      "data": {
          "type": "res.users",
          "id": 1
        }
    }
    }
    }
    }
    

Example(1): This request is update the sales person of the user with ID 96.

Query when create record Query after update record
Ekika JSON API Update Records with Relationship Many2One Field Query
Ekika JSON API Update Records with Relationship Many2One Field Query
  • The request changes the relationship data of related sales person details of the person showed in below images.
Sales person when created Sales person after updated
Ekika JSON API Update Records with Relationship Many2One Field Output
Ekika JSON API Update Records with Relationship Many2One Field Output

Update Record with relationship Many2Many Field:

  • Relationships: Defines any related resources associated with the partner entity being updated. In this case, there is a relationship named "category_id" representing the categories associated with the partner entity.
Query:
    {
    "data": {
    "type": "res.partner",
    "attributes": {
    "name": "Joey Tribbiani",
    "email": "Joey@mail.com",
    "mobile": 1299129900,
    "city": "Gandhinagar",
    "website": "http://www.demosite.com",
    "function": "CTO"
    },
    "relationships": {
    "category_id": {
      "data": [
          {
          "type": "res.partner.category",
          "id": "3"
          },
          {
          "type": "res.partner.category",
          "id": "6"
          }
        ]
    }
    }
    }
    }
    

Example(1): This request is update the tags field value of the user with ID 96.

Query when create record Query after update record
Ekika JSON API Update Records with Relationship Many2Many Field Query
Ekika JSON API Update Records with Relationship Many2Many Field Query
  • The request changes the tag values details of the person showed in below images.
Tags when created Tags after updated
Ekika JSON API Update Records with Relationship Many2Many Field Output
Ekika JSON API Update Records with Relationship Many2Many Field Output

Update Record with Odoo's field types "One2Many", "Many2One", and "Many2Many" together:

  • Use odoo field types, "One2Many", "Many2One", and "Many2Many" all in 1 request.
Query:
    {
    "data": {
    "type": "res.partner",
    "id": 96,
    "attributes": {
    "name": "Joey Tribbiani",
    "email": "Joeyupdated@mail.com",
    "mobile": 1299129900,
    "city": "Ahmedabad",
    "website": "http://www.demosite.com",
    "function": "CFO"
    },
    "relationships": {
    "bank_ids":{
        "data": [
            {
            "type": "res.partner.bank",
            "attributes": {
                "sequence": 20,
                "bank_id": 1,
                "acc_number": "999000999",
                "allow_out_payment": true,
                "acc_holder_name": true
                }
            }
        ]
    },
    "user_id": {
        "data": {
            "type": "res.users",
            "id": 1
        }
    },
    "category_id": {
        "data": [
            {
            "type": "res.partner.category",
            "id": "4"
            },
            {
            "type": "res.partner.category",
            "id": "5"
            }
        ]
    }
    }
    }
    }
    

Example(1): This request is structured according to JSON API conventions, facilitating the updation of a partner entity with associated Bank Accounts as One2many type in a standardized manner and also a Sales Person assign to it as "Many2one" field type, and gave multile Tags to that person as "Many2many" field type.

Query Parameters Query Parameters Continued
Ekika JSON API Update Records with Multiple Relationships Query
JSON API Update Records with Multiple Relationships Query

This is the all changes which is made through this PATCH Request. Refer the images below.

JSON API Update Records with Multiple Relationships Output
JSON API Update Records with Multiple Relationships Output

JSON API Delete Request:

A Delete Request in JSON API is used to remove a resource from odoo. This typically involves sending an HTTP DELETE request to the API endpoint corresponding to the resource you want to delete.

Delete
{domain[:port]}/{endpoint}/{model}/{id}
  • This is the main query parameters which is mandatory to write when you are working with APIs.
  • Use "HTTP DELETE Method" to delete the records in odoo.
  • Domain is specified your wesite's domain address. The port number is optional.
  • Endpoint is the specific path within the API that identifies the particular resource or action. This part of the URL tells the server what type of operation is being requested.
  • Model is Odoo's technical name of entities and also known as model name, record's model or entities. You can identify it from the URL shown below.
  • Domain Image
  • ID
  • indicates that specific record we want to delete.
  • Headers in an API request are key-value pairs sent between the client and the server, providing additional information about the request or the client itself. They are part of the HTTP protocol and can carry various types of metadata.
  • Add "Content-Type" and "x-api-key" keys with their specific values. JSON API's media type designation is "application/vnd.api+json". Add this in Content-Type's value field and also add your API Key.
  • Ekika Header Image

This is the query in below image shows the query of specific record you want to delete from odoo & the header section also.

Ekika JSON API Delete Query

RoundGET Records

  • 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
  • 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
  • Pagination: Get the second page of sale.order with 5 records per page. GET /sale.order?page[number]=2&page[size]=5
  • Sort: Get sale.order sorted by their date_order in descending order. GET /sale.order?sort=-date_order
  • 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)]
Ekika JSON API Get Records Image
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)
    

RoundGET Single Record

Ekika JSON API Get Single Record Image
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)
    

RoundCREATE POST Record

Ekika JSON API Create Record Image
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)
    

RoundUPDATE PATCH Record

Ekika JSON API Update Record Image
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)
    

RoundDELETE Record

Ekika JSON API Delete Record Image
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)
    

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.