Working With Odoo Web Services

blog-banner

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.

XML-RPC Web Service

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://learning.postman.com/docs/getting-started/basics/navigating-postman/

  • 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>

Contact us

For Your Business Requirements

Text to Identify Refresh CAPTCHA
Background Image Close Button

2 - 4 October 2024

Hall: 10, Booth: #B8 Brussels, Belgium