« Back to Blogs

Working with odoo web services

Odoo exposes its API over XML-RPC. You can execute odoo API from variety of tools and languages by calling its XML-RPC based web services.

 

What is XML-RPC Web Service ?

Sometime you want to exchange one application information to another application over the internet. XML-RPC Web Services supports to do that.

Following diagram showing an actual XML-RPC conversation between a client (requesting the login RPC) and a listener who is returning the results of that procedure.

 

 

Here, I have described the steps how you can logging in your odoo database, perform CRUD operation through XML-RPC Web Services (here I am using Postman tool to make request in odoo application).

Before starting, you need to understand the basic knowledge about XML-RPC API, For that please visit https://odoorestapi.azurewebsites.net/Help
 

Postman Configuration

To Install Postman in your system, please visit https://www.getpostman.com/docs/introduction

  • Go to Postman, set your application url with xmlrpc API, Header information as below.

 


Provide url to authenticate with odoo database :  http://127.0.0.1:8069/xmlrpc/2/common

  • Method : Post

  • Your IP Address : 127.0.0.1

  • Port number where odoo is running : 8069

  • Xmlrpc/2/common: Execute the login and returns the authentication token

Header configuration :

  • Key : Content-Type

  • Value: application/xml

 

Database Connectivity:

  • Write the following request code on body and send the request to logging in your odoo database.

 

<methodCall>
    <methodName>login</methodName> <!-- method name -->
    <params>
        <param>
            <value><string>post_db</string></value> <!-- database name -->
        </param>    
        <param>
            <value><string>admin</string></value> <!-- username -->
        </param>   
        <param>
            <value><string>a</string></value> <!-- user’s password -->
        </param>   
       </params>
</methodCall>

 

  • If provided authentication information for odoo database is correct, you get response as shown in below image.

Response body format

 

Perform CRUD Operations:

To call odoo methods you have to use Xmlrpc/2/object API.

  • Create Record: Record is created via the create() method.

 

<methodCall>
    <!-- used to call methods of odoo models -->
    <methodName>execute</methodName>
        <params>
            <param>
                <!-- database name -->
                <value><string>odoo_db</string></value>
            </param>
            <param>
                <!-- user id -->
                <value><int>1</int></value>
            </param>
            <param>
                <!-- user’s password-->
                <value>
                    <string>admin</string>
                </value>
            </param>
            <param>
                <!-- model name -->
                <value>
                    <string>res.partner</string>
                </value>
            </param>
            <param>
                <!-- method name -->
                <value>
                    <string>create</string>
                </value>
            </param>
            <param>
                <!-- create a struct where you identify the field name,
thefield type and the value you want to insert in it -->
                <value>
                    <struct>
                        <member>
                            <name>name</name> <!-- field name -->
                            <value>
                                <!-- field’s type and value -->
                                <string>Test Customer</string>
                            </value>
                        </member>
                    </struct>
                </value>
            </param>
        </params>
</methodCall>

 

  • Read Record: Record data is accessible via the read() method, which takes a list of ids.

 

<methodCall>
    <!-- used to call methods of odoo models -->
    <methodName>execute</methodName>
    <params>
        <param>
            <!-- database name -->
            <value><string>odoo_db</string></value>
        </param>
        <param>
             <!-- user id -->
               <value><int>1</int></value>
        </param>
        <param>
             <!-- password -->
               <value><string>admin</string></value>
        </param>
        <param>
            <!-- model name -->
            <value><string>res.partner</string></value>
        </param>
        <param>
             <!-- method name -->
            <value><string>read</string></value>
        </param>
        <param>
            <!-- record id of which data you want to read -->
            <value><int>46</int></value>        
        </param>
    </params>
</methodCall>

  • Update Record: Records can be updated using write(), it takes a list of records to update and a mapping of updated fields to values similar to create().

 

<methodCall>
    <!-- used to call methods of odoo models -->
    <methodName>execute</methodName>
    <params>
        <param>
            <!-- database name -->
            <value><string>odoo_db</string></value>
        </param>
        <param>
            <!-- user id -->
               <value><int>1</int></value>
        </param>
        <param>
            <!-- password -->
               <value><string>admin</string></value>
        </param>
           <param>
             <!-- model name -->
               <value><string>res.partner</string></value>
        </param>
        <param>
            <!-- method name -->
            <value><string>write</string></value>
        </param>
        <param>
            <!-- record id of which data you want to update-->
            <value><int>49</int></value>        
        </param>
        <param>
            <value>
                <struct>
                    <member>
                        <name>name</name> <!-- field name -->
                        <!-- field’s value-->
                        <value><string>Test Customer1</string></value>
                   </member>
               </struct>
            </value>
        </param>
    </params>
</methodCall>

 

  • Delete Record: Records can be deleted by providing their ids to unlink().

 

<methodCall>
    <!-- used to call methods of odoo models -->
    <methodName>execute</methodName>
    <params>
        <param>
            <!-- database name -->
            <value><string>odoo_db</string></value>
        </param>
        <param>
             <!-- user id -->
            <value><int>1</int></value>
        </param>
        <param>
             <!-- password -->
            <value><string>admin</string></value>
        </param>
        <param>
            <!-- model name -->
            <value><string>res.partner</string></value>
        </param>
        <param>
             <!-- method name -->
            <value><string>unlink</string></value>
        </param>
        <param>
            <!-- record id of which data you want to delete -->
            <value><int>46</int></value>
        </param>
    </params>
</methodCall>


For more implementation details or support, you may contact us at enquiry@surekhatech.com

 

 

Comments
Naran M
How to add parameters in read or search method call
Posted on 9/20/17 6:06 PM.
shivprasad khandapure
In read method, I want to get multiple customers record rather than single Customer data. what kind of changes i have to do?
Posted on 8/4/18 5:06 PM.
shivprasad khandapure
In read method, I want to get multiple customers record rather than single Customer data. what kind of changes i have to do?
Posted on 8/4/18 5:06 PM.
shivprasad khandapure
In read method, I want to get multiple customers record rather than single Customer data. what kind of changes i have to do?
Posted on 8/4/18 5:07 PM in reply to Naran M.
SI THU
How to add parameters in read or search method call
Posted on 9/23/18 4:34 PM.
iTor Fernández
This was super useful, thank you very much.

Just for anyone to know, after authentication, one can just take the id of the user and use it in any subsequent calls.
Posted on 7/16/19 9:11 PM.
contact-us Request a callback