Locoia
  • Overview
  • Account and User Settings
    • User types
    • Adding Users
    • Teams
    • Access Permissions
    • 2 Factor Authentication 2FA
    • Versioning and Snapshots
    • Activity Log
  • Reset your Password
  • Invoices and Payments
  • Automation
    • Flow Builder
      • Flow Building Best Practices
      • Jinja Template Language
        • Jinja: (Custom) variables, wildcards and functions
        • Magic Code Samples
      • Connectors & APIs
        • Titles and References
        • Referencing data of objects, lists, arrays - how to pass data dynamically
        • Accessing Objects with JSONPath
        • Merging nested JSON objects
        • Parsing JSONs from String
        • Response Headers & Status Codes
        • Custom Data Fields
        • Wildcard API calls and actions
        • Response cleaning
      • Text Strings, Date & Time, Numbers and Currencies
        • Text and Strings
        • Dates & Time
        • Numbers (Thousand Separators, Currencies)
      • Email-formatting
      • Code Fields
      • Running single Flow steps
      • Flow run data retention, logging, and error notifications
      • Advanced View
      • Dynamic Title
      • Custom Error Handling
      • Error Handling Flows
      • Automatic Pagination
    • Flow Debugger
      • Automatic Retrying
      • Run Flows again
      • Troubleshooting Flows
    • Community Library
  • Connectors & Helpers
    • Connectors
      • Monday.com
      • ActiveCampaign
      • Aircall
      • Allthings
      • Amplitude
      • Animus
      • Assetti
      • Awork
      • AWS RDS Database - How to connect
      • bubble.io
      • Casavi
      • Chargebee
      • CleverReach
      • comgy
      • commercetools
      • Everreal
      • Exact Online
      • Facebook Marketing
      • Fahrländer Partner
      • FastBill
      • FILESTAGE.io
      • Freshdesk
      • Freshsales
      • Google Ads
      • Google Ads Lead Form
      • Google Analytics
      • Google Chat
      • Google Drive
      • Google Sheets
      • Gmail
      • HubSpot
      • Heyflow
      • iDWELL
      • ImmobilienScout24
      • Instagram Ads
      • Intercom
      • klaviyo
      • Kiwi Opening Doors
      • Klenty
      • Klipfolio
      • Kolibri CRM
      • konfipay
      • KUGU
      • Shopify
      • S3 AWS
      • SQS AWS
      • Lambda AWS
      • Learnster
      • lexoffice
      • LineMetrics
      • Linkedin
      • Locoia
      • Notion
      • MailGun
      • Makula
      • Microsoft Dynamics 365
      • Microsoft OneDrive
      • MixPanel
      • MongoDB
      • Odoo
      • OnFleet
      • OnOffice
      • Oracle NetSuite
      • Outbrain
      • Quickbooks
      • Trello
      • PandaDoc
      • Personio
      • Pinterest Ads
      • Pipedrive
      • Plentific
      • PriceHubble
      • relay
      • REALCUBE
      • Sage ERP
      • Salesforce
      • SAP
      • Scoro
      • Seafile
      • sevDesk
      • SharePoint
      • SharpSpring
      • Slack
      • Snapchat Marketing
      • Snowflake
      • Teamleader Focus
      • Teamwork.com
      • Tableau
      • TikTok
      • TinQwise
      • The Trade Desk
      • Twitter
      • Typeform
      • WordPress
      • Xero
      • Youtube
      • Zendesk
      • Zoho CRM
      • Zoom
    • Helpers
      • Scheduler
      • Webhook
      • Dict Helper
      • Spreadsheet Helper
      • REST Helper
      • Boolean Helper
      • Multi Case Helper
      • Looper
      • FTP Helper
      • CSV Helper
      • XLSX Helper
      • Mail Sender
      • Flow Trigger
      • File Storage Helper
      • Terminate Helper
      • Delay Helper
      • SQL Connector
      • PDF Helper
      • Zip Helper
      • Data Warehouse Helper
      • XML Helper
      • Form Helper
      • Arrow
      • Error Arrow
    • Authentication Types Available
      • Setting up authentication
      • OAuth1
      • OAuth2
      • Refreshable token
      • AWS Signature
      • Basic Auth and Other Simple Authentication Methods
      • How are API versioning and API updates handeled?
      • Custom OAuth2 clients (apps)
    • Building Connectors
      • Base Connector Setup
        • Connector Auth Validation
        • GraphQL APIs
        • Rendering with User Input
      • Building Connector Actions
        • Actions Examples
      • Search Automation
      • Pagination Automation
      • Uploading Files in Actions
      • Working with SOAP APIs
    • Super Actions
    • Webhook Trigger for Connectors
    • Data Mapping and Env Variables
  • Embed - White Label Portal
    • Embed Overview
      • 1. Embed Flow
        • 1.1 Creating Embed Flows
        • 1.2 Updating Embed Flows
        • 1.3 Embed Error Handling
        • 1.4 Setting up Callbacks for Integration activation/deactivation
        • 1.5 Setting up Remote search
        • 1.6 Setting up End User logs
      • 2. Configure Embed
        • 2.1 Embed Integration via SSO
        • 2.2 Proprietary connector setup
        • 2.3 Sharing level
        • 2.4 Consent screen
        • 2.5 Account Secrets
        • 2.7 Further settings
      • 3. Integrate Embed
        • 3.1 iframe vs native embed
        • 3.2 Customizing CSS
        • 3.3 Events emitted from iframe to parent window
      • 4. Embed for End User
        • 4.1 Embed Remote Search
        • 4.2 Embed End User Logs
      • 5. Test Embed Configuration
        • Testing example
      • 6. Embed Integrations and Connector Auths
    • Embed FAQs
  • Data and Dashboards
    • Dashboards & Insights
      • Introduction to Dashboards
      • Introduction to Insights
      • Introduction to Data Sources
      • Dashboard Filters
      • Insight Marketplace - Using Pre-Built Insights
      • Writing SQL Queries
      • Useful SQL Examples
      • Charts
        • Line Chart
        • Bar and Horizontal Bar Chart
        • Stat Card
        • Pie Chart
        • Gauge Chart
        • Donut Chart
        • Stacked Bar, Horizontal Stacked Bar, and Normalized Horizontal Stacked Bar
        • Multiple Line Chart
        • Pivot Table
        • Map Chart
  • Best Practice Guides
    • Integration Best Practices
    • Integration Check List
    • CSV Files in Excel
    • Multi-Tenant Flows
    • On-Premise Integrations
    • Database Connection Setup
    • Data and General Security
    • Using Tags
    • FAQ
  • API
    • Locoia API Authentication - Personal Access Token
    • Create Connector Authentication
  • Contact us
  • Status of Service
  • Data Privacy
  • Imprint
Powered by GitBook
On this page
  • API versions of Odoo
  • Initial API setup
  • JSON-RPC Connection
  • Searching and Search Operators in Odoo
  • The difference between =, like and ilike

Was this helpful?

  1. Connectors & Helpers
  2. Connectors

Odoo

Odoo jsonrpc API connections.

PreviousMongoDBNextOnFleet

Last updated 3 years ago

Was this helpful?

API versions of Odoo

The Odoo API is an XML-RPC or JSON-RPC API. There are multiple REST API plugins that can be purchased and installed in on top of the regular Odoo APIs mentioned before. Locoia covers only the JSON-RPC API as it is free of charge and requests can easily be built by viewing the requests made in the Odoo web app's Developer Tools > Network tab and using those payloads for JSON-RPC as described below.

Initial API setup

To start using the Odoo API, one needs to get the these three parameters from the Odoo account database name and a user's id and password.

1. Database

The database name can easily be found, if Odoo is set into debug mode. By adding debug=1 to the web app url, the web app is set it to debug mode, e.g. https://mycompanyname.odoo.com/web?debug=1

Once in debug mode, the database name is visible on the right next to the account name in brackets:

Note: Odoo can be installed locally (e.g. on an AWS cloud instance) or setup via Odoo.sh in the Odoo-cloud. The later avoids and manual installation.

2. User ID

Follow the steps to get it:

  1. Open the developer console of your browser on the Network tab.

  2. In Odoo click on the upper right corner, then click on "Preferences".

  3. Find the request like *your subdomain*.odoo.com/web/dataset/call_kw/res.users/read

  4. Go to the payload tab and open the payload as per the JSON-path: params.kwargs.context.uid

  5. You found the uid e.g. something 2

3. Password:

Password is your user's password of the user you logged in with. Any user can be used to get access.

JSON-RPC Connection

# Based on: https://www.odoo.com/documentation/15.0/developer/howtos/backend.html#json-rpc-library

import json
import random
import requests

HOST = "mycompanyname.odoo.com"
PORT = 443 # Default port for the Odoo.sh cloud version.
url = f"https://{HOST}:{PORT}/jsonrpc"
DB = "mycompanydb-name"
USER = "support+resmio@locoia.com"
PASSWORD = "some secret PW"


def json_rpc(url, method, params):
    data = {
        "jsonrpc": "2.0",
        "method": method,
        "params": params,
        "id": random.randint(0, 1000000000),
    }
    headers={
        "Content-Type":"application/json",
    }

    reply = requests.get(url=url, data=json.dumps(data).encode(), headers=headers)
    json_response = reply.json()
    error = None
    error = json_response.get("error")
    
    if error is not None:
        raise Exception(json_response["error"])
    return json_response["result"]

def make_request(url, service, method, *args):
    return json_rpc(url, "call", {"service": service, "method": method, "args": args})


# Get the user is for further calls.
uid = make_request(url, "common", "login", DB, USER, PASS)

To make individual calls, one needs to make further requests, based on the above snippet with the below called.

  • url = the request url as defined above

  • object = TBD

  • execute = stay the same

  • uid = the user id as defined above

  • PASSWORD = as defined initially (alternatively the api-key)

  • "res.partner" = The object to be manipulated

  • "search" = the request method

  • args = arguments specifying the request (similar to query string parameters)

args = [("phone", "ilike", "+491232...")]
phpne user = make_request(url, "object", "execute", DB, uid, PASSWORD, "res.partner", "search", args)

Note that Locoia can only send request payloads (body) on POST, PUT or PATCH requests. So for any JSON or XML-RPC requests, POST is to be used.

Searching and Search Operators in Odoo

Each tuple in the search domain needs to have 3 elements, in the form: **('field_name', 'operator', value)**, where:

            * **field_name** must be a valid name of field of the object model, possibly following many-to-one relationships using dot-notation, e.g 'street' or 'partner_id.country' are valid values.
            * **operator** must be a string with a valid comparison operator from this list: ``=, !=, >, >=, <, <=, like, ilike, in, not in, child_of, parent_left, parent_right``
              The semantics of most of these operators are obvious.
              The ``child_of`` operator will look for records who are children or grand-children of a given record,
              according to the semantics of this model (i.e following the relationship field named by
              ``self._parent_name``, by default ``parent_id``.
            * **value** must be a valid value to compare with the values of **field_name**, depending on its type.

When using the Odoo Connector, you might come across simple, specific search actions (such as "Search Partner by Phone), which will make the process as easy as possible for you. However, if you want to execute more elaborate search queries, you can use the custom search endpoints, e.g. "Search Partner by Custom". These Actions allow you to pass your own Tuples (as elaborated above) in as search parameter. Be aware that, as we are using JSON to communicate with your Odoo instance, instead of using simple parenthesis ( , you will have to use square brackets ( [ ) in your tuples, like so:

[['name','=','ABC'],'!',['language.code','=','en_US']]

The difference between =, like and ilike

The = operator will look for a perfect match, the like operator will add wildcards to the beginning and end of your search term, but is case sensitive, and the ilike operator is case insensitive.

By adding a = in front of like and ilike (=like, =ilike), you can prevent the search from adding wildcards, but can control the case-sensitivity (e.g. ["name", "ilike", "dog"] will match dog, bulldog, DOGS, ["name", "=ilike", "dog"] will only match dog, Dog, DOG, etc.).

JSON-RPC is an easy way to connect to OdooB. Below one can find a slightly adjusted script based on the one to make initial testing calls:

If you want to search records using custom search operators, a (not too helpful) list of logical and search operators can be found in the . The most important take-aways:

provided from Odoo
source code
Odoo App in "debug mode" enabled will show the small bug in the upper left corner.
Database name as visible in debug mode.