Skip to Content
Menu

GraphQL API for Odoo

by
Odoo

62.81

v 17.0 Third Party 45
Availability
Odoo Online
Odoo.sh
On Premise
Odoo Apps Dependencies Discuss (mail)
Community Apps Dependencies
Lines of code 2508
Technical Name easy_graphql
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 2508
Technical Name easy_graphql
LicenseOPL-1
Websitehttps://ekika.co
Versions 12.0 13.0 14.0 15.0 16.0 17.0 18.0
Background Image

Introduction

GraphQL is an open-source data query language for APIs and a runtime for executing those queries by using a type system you define for your data. It allows clients to request exactly the data they need. This query is a set of parameters used in a GraphQL API request. These parameters define how the API should respond and what data should be included.

Two key features of GraphQL:

  • Declarative Data Fetching: GraphQL allows clients to request only the data they need and nothing more. Clients can specify the shape and structure of the response, reducing the over-fetching and under-fetching of data that often occurs in REST APIs.
  • Hierarchical Structure: GraphQL queries have a hierarchical structure, mirroring the shape of the response data. Clients can request nested fields, and the server responds with a JSON object that matches the requested structure.

How It Works:

In GraphQL, queries and mutations are two types of operations used to interact with the API:

  • Query Operation: A query in GraphQL is used to read or fetch data from the server. Clients can specify exactly what data they need, and the server will return only the requested data, no more and no less. Queries are similar to GET requests in REST APIs.
  • Mutation Operation: A mutation in GraphQL is used to modify data on the server. Mutations are similar to POST, PUT, PATCH, or DELETE requests in REST APIs. Mutations can be used for creating, updating, or deleting records.

You'll see this both operations in detail below.

GraphQL API Get Request Overview:

A GraphQL query is used to fetch specific data from a server, like retrieving records from Odoo. Instead of specifying an endpoint, you define the fields and data structure in the query, allowing precise control over the response. The server returns only the requested fields in JSON format or an error message.

POST
{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
  • 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. GraphQL API's media type designation is "application/json". Add this in Content-Type's value field and also add your API Key.
  • Variables are defined separately from the query itself and are typically passed as a JSON object when executing the query. GraphQL supports passing variables in formats other than JSON, although JSON is the most common format used in practice.
  • GraphQL API Query Headers

Get Records:

POST
https://api.17.dev.ekika.co/user-graphql-apikey

See the Example with Query, Variables & Output:

Query
GraphQL Query
Output
GraphQL Query Output
Query:
query MyQuery($offset: Int, $limit: Int, $order: String, $domain: [[Any]]) {
  ResPartner(
    offset: $offset
    limit: $limit
    order: $order
    domain: $domain
  )
  {
    id
    name
    phone
    email
    is_company
    country_id{
      name
      code
    }
    user_id{
      name
      active
    }
    company_id{
      name
    }
  }
}
GraphQL Variables:
{
  "offset": 0,
  "limit": 6,
  "order": "name,id desc",
  "domain": [["is_company","=",true]]
}
GraphQL Variables Explanation::
  • offset: 0: This sets the offset to 0, meaning that the query will start fetching records from the beginning.
  • limit: 6: This sets the limit to 6, indicating that the query should return a maximum of 6 records.
  • order: "name,id decs": This means "order the data by name, and if names are the same, order them by id in descending order.
  • domain: This means "filter the data to include only records where the 'is_company' field is equal to true."

Get Single Record:

POST
https://api.17.dev.ekika.co/user-graphql-apikey

See the Example with Query & Output:

Query
GraphQL Query
Output
GraphQL Query Output
Query:
query MyQuery($offset: Int, $limit: Int, $order: String, $domain: [[Any]]) {
  ResPartner(
    offset: $offset
    limit: $limit
    order: $order
    domain: $domain
  )
  {
    id
    name
    phone
    email
    is_company
    country_id{
      name
      code
    }
    user_id{
      name
      active
    }
    company_id{
      name
    }
  }
}

Create Record:

POST
https://api.17.dev.ekika.co/user-graphql-apikey

Mutation Create: A mutation in GraphQL is a type of request used to modify data on the server. It's often used to perform operations such as creating, updating, or deleting data. Unlike queries, which are used for fetching data, mutations are used for making modifications to the data.

See the Example with Query & Output:

Query
GraphQL Query
GraphQL Query
Output
GraphQL Query Output
Query:
mutation Create {
  createResPartner: ResPartner(
      ResPartnerValues: {
          active: true,
          name: "Ekika Corporation New",
          category_id: [4, 3]
          company_type: "company",
          bank_ids: [
        [0, 0, {
          sequence: 10,
          bank_id: 2,
          acc_number: "11212121212",
          allow_out_payment: true,
          acc_holder_name: false
        }],
        [0, 0, {
          sequence: 11,
          bank_id: 3,
          acc_number: "3434343434343434",
          allow_out_payment: true,
          acc_holder_name: false
        }]
      ]
          city: "Gandhinagar",
          street: "Gandhinagar",
          street2: "",
          zip: "382421",
          comment: "<p>Comment Here</p>",
          phone: "5554444555444",
          mobile: "1010101",
          website: "http://www.ekika.co",
          email: "hello@ekika.co",
      }
  )
  {
      active
      category_id
      bank_ids
      city
      comment
      company_type
      id
      name
      phone
      mobile
      email
      street
      zip
  }
}

Update Records:

POST
https://api.17.dev.ekika.co/user-graphql-apikey

See the Example with Query & Output:

Query
GraphQL Query
Output
GraphQL Query Output
Query:
query MyQuery($offset: Int, $limit: Int, $order: String, $domain: [[Any]]) {
  ResPartner(
    offset: $offset
    limit: $limit
    order: $order
    domain: $domain
  )
  {
    id
    name
    phone
    email
    is_company
    country_id{
      name
      code
    }
    user_id{
      name
      active
    }
    company_id{
      name
    }
  }
}

Delete Records:

POST
https://api.17.dev.ekika.co/user-graphql-apikey

See the Example with Query & Output:

Query
GraphQL Query
Output
GraphQL Query Output
Query:
mutation Delete {
  deleteResPartner: ResPartner(
      id: 50, 
  )
}
        

Export:

POST
https://api.17.dev.ekika.co/demotest-graphql

See the Example with Query & Output:

Example: This GraphQL API query enables users to retrieve Excel export data from the server.

Query
Ekika GraphQL API Exports Query
Ekika GraphQL API Exports Query
Output
Ekika GraphQL API Exports Query Output
Query:
query ExportQuery {
  ExportData(
      values: $export_data
  )
}
        
GraphQL Variables:
{
  "export_data":{
  "import_compat": false,
  "context": {
    "lang": "en_US",
    "tz": "Asia/Calcutta",
    "uid": 2,
    "allowed_company_ids": [
      1
    ]
  },
  "domain": [
    [
      "user_id",
      "=",
      2
    ]
  ],
  "fields": [
    {
      "name": "name",
      "label": "Order Reference",
      "type": "char"
    },
    {
      "name": "display_name",
      "label": "Display Name",
      "type": "char"
    },
    {
      "name": "activity_ids",
      "label": "Activities",
      "type": "one2many"
    },
    {
      "name": "create_date",
      "label": "Creation Date",
      "type": "datetime"
    },
    {
      "name": "partner_id",
      "label": "Customer",
      "type": "many2one"
    },
    {
      "name": "user_id",
      "label": "Salesperson",
      "type": "many2one"
    },
    {
      "name": "user_id/name",
      "label": "Salesperson/Name",
      "type": "char"
    },
    {
      "name": "state",
      "label": "Status",
      "type": "selection"
    },
    {
      "name": "amount_total",
      "label": "Total",
      "type": "monetary"
    }
  ],
  "groupby": [],
  "ids": [
    7,
    6
  ],
  "model": "sale.order"
  }
}
        

Method Execution:

In GraphQL, method execution refers to calling a predefined function or method on the server to perform a specific action. This is commonly done using mutations in GraphQL, which are designed to execute actions, such as updating, creating, or deleting data.

POST
https://api.17.dev.ekika.co/demotest-graphql

See the Example with Query & Output:

Example: This GraphQL API query executes the action_draft method, and change the quotation from draft state to quotation state.

Query Output
GraphQL API Method Execution Query
GraphQL API Method Execution Query Output
Before, the quotation is on Draft State.
GraphQL API Draft State Method Execution
After, the quotation is on Quotation State.
GraphQL API Quotation State Method Execution
Query:
mutation Method {
    methodSaleOrder: SaleOrder(
        id: 6, 
        method_name: "action_draft",
        method_parameters: {}
    ){
    id
  }
}
        

Search Read:

In GraphQL, search_read is used to retrieve records by combining search and read operations in one method execution. search_read is purely for reading data and can be customized to return targeted information based on the request.

POST
https://api.17.dev.ekika.co/demotest-graphql

See the Example with Query & Output:

Example: This GraphQL API query executes the search_read method, to retrieve the fields like id, name etc, from the res.partner model.

Query Output
Method Execution Search Read Method Query
Method Execution Search Read Method Query Output
Query:
mutation Method {
  methodResPartner: ResPartner(
      method_name: "search_read",
      method_parameters: {
          domain:[["is_company", "=", true]]
          fields: ["id", "name", "email", "is_company"]
          limit: 4
      }
  )
}

Read:

In GraphQL, the read operation retrieves detailed information directly from specific records in the database based on given record IDs. In Odoo, read is used to obtain precise data for requested fields, providing in-depth details about each record without additional search or filtering.

POST
https://api.17.dev.ekika.co/demotest-graphql

See the Example with Query & Output:

Example: This GraphQL API query read the specified record fields using id.

Query
Method Execution Read Method
Query:
mutation Method {
  methodResPartner: ResPartner(
      id: 10
      method_name: "read",
      method_parameters: {
          fields: ["name", "email", "is_company", "country_id"]
      }
  )
}

Read Group:

In GraphQL, the read_group operation is used to aggregate and group data records based on specified fields. In Odoo, read_group allows you to retrieve summarized data, such as counts, sums, or averages, grouped by particular fields or categories.

POST
https://api.17.dev.ekika.co/demotest-graphql

See the Example with Query & Output:

Example: This GraphQL API query executes the read_group method, to retrieve specified fileds and group them using groupby country_id.

Query Output
Method Execution Read Group Query
Method Execution Read Group Query Output
Query:
mutation Method {
  methodResPartner: ResPartner(
      method_name: "read_group",
      method_parameters: {
          domain: [["is_company", "=", false]],
          fields: ["name", "country_id", "comment", "is_company"],
          groupby: country_id
    },
      
  )
}

Search Count:

In GraphQL, the search_count operation is used to quickly determine the number of records that match specific search criteria without retrieving the actual data. In Odoo, search_count allows you to count the total number of records that meet certain conditions, providing an efficient way to assess the size of a dataset.

POST
https://api.17.dev.ekika.co/demotest-graphql

See the Example with Query & Output:

Example: This GraphQL API query give count of the records where the parameter is_company = true.

Query
Method Execution Search Count Method
Query:
mutation Method {
    methodResPartner: ResPartner(
        method_name: "search_count",
        method_parameters: {
            domain:[["is_company", "=", true]]
        }
    )
}

Fields Get:

In GraphQL, the fields_get operation is used to retrieve metadata about the fields available in a specific model, including details like field names, types, and possible selection options. In Odoo, fields_get provides information about the structure and configuration of the fields in a model, allowing users to understand the data schema.

POST
https://api.17.dev.ekika.co/demotest-graphql

See the Example with Query & Output:

Example: This GraphQL API query shows the list of fields in res.partner model.

Query
Method Execution Fileds Get Method
Query:
mutation Method {
  methodAccessRights: ResPartner(
    method_name: "fields_get",
    method_parameters: {
        attributes: ["type", "string"]
    },
  )
}

Check Access Rights:

In GraphQL, the check_access_rights operation is used to verify whether a user has the necessary permissions to access or perform actions on a specific resource. In Odoo, check_access_rights is used to validate whether the current user has the appropriate rights to read, write, or modify records in a given model.

POST
https://api.17.dev.ekika.co/demotest-graphql

See the Example with Query & Output:

Example: This GraphQL API query shows the access rights, if the user have the rights to access the res.partner model.

Query
Method Execution Check Access Rights Method
Query:
mutation Method {
  methodAccessRights: ResPartner(
    method_name: "check_access_rights",
    method_parameters: {
        operation: "read",
    },
  )
}

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.