Odoo Help


How to connect a Google Script to Openerp(odoo) using XML RPC?

Anabela Damas
on 11/19/14, 6:33 AM 2,628 views


I've made a python script using XML  RPC to connect to openerp and create res.partners and it works fine.

Now I wonder if the same is possible in a google script?

I've tried but I can't connect to openerp!

Do you know the library to use, or a clue to start implementing the connection through XML RPC in a google script? 

I've tried to use this code https://github.com/ikikko/Mimic-for-Google-Apps-Script/blob/master/mimic-gas.js , and then this :

function teste() {
  var method = "login" ; 
  var request = new XmlRpcRequest("", method); 
  //var request_aut = request.setAuthentication('admin','vi!aveirofast#69');
  var response = request.send(); 
  //var response = request_aut.send(); 
  return response.parseXML(); 


But I always get the error : 

Unable to parse the text. (line 253, file "Code")

253:    return new XmlRpcResponse(Xml.parse(response.getContentText()));


Doing Logger.log(response); the log is empthy... 


On 7/16/16, 3:37 AM


Here is a very simple / small GSCript to connect to Odoo but using JSONRPC :

function OdooJSONRPC2(db_settings)



* Random client id generation. To be provided in jsonrpc calls and returned to differentiate requests if necessary.


this._guid = function() {

function s4() {

return Math.floor((1 + Math.random()) * 0x10000)




return s4() + s4() + "-" + s4() + "-" + s4() + "-" +

s4() + "-" + s4() + s4() + s4();



* Jsonrpc2 call (internal function)

* @param jsonrpc_method : type of jsonrpc method (ex: call)

* @param url : url on which jsonrpc needs to be called

* @param params : json object with the API parameters


this._jsonrpc2_call = function(jsonrpc_method,url,params)


var json = JSON.stringify({

"jsonrpc": "2.0",

"method" : jsonrpc_method,

"id" : this.id,

"params": params


var headers = {

"Content-Type" : "application/json",

"Accept" : "application/json",



{ //adds the session_id in the request (in a cookie). Optional because doesn"t exist on the first call (authentication)



var options = {

method: "post",

payload : json,

headers : headers,

contentLength : json.length


return JSON.parse(UrlFetchApp.fetch(url,options).getContentText());


this.search_read = function(model,params)



return this._jsonrpc2_call("call",db_settings.base_location + "/web/dataset/search_read",params).result.records;


/* constructor : after the methods declaration because some methods are used by constructor */

this.db_settings = db_settings;

this.id = this._guid();

if(this.db_settings["db"] && this.db_settings["login"] && this.db_settings["password"] && this.db_settings["base_location"])


this.sid = this._jsonrpc2_call("call",db_settings.base_location + "/web/session/authenticate",db_settings).result.session_id;




throw "Incomplete DB settings required keys are : db, login, password, base_location";




  var odoo = new OdooJSONRPC2({"db": "?", "login": "?","password": "?","base_location": "?"});

var rental_products = odoo.search_read("product.template",{"domain" : [["rental_ok","=","true"]], "fields":["id"]});

var specific_product = odoo.search_read("product.template",{"domain" : [["id","=",52]], "fields":["display_name"]});

var product_by_id = odoo.search_read("product.template",{"domain" : [["id","in",[50,51,52]]], "fields":["display_name"]});

Fausto R.
On 11/28/14, 7:36 AM

I will be workiing on this approach next week, so I am very interested.

However, note that GAS (Google Apps Script) is runing on Google servers, so they cannot access an Odoo server in your local network.

This aproach might / should work with Odoo online, though I am still struggling with the right url:port to use.

ps. I am new to this forum, so I cannot post a question yet

Hope that my "like" helps you to get karma ;) For you to post questions about GAS.

Versão Integral, Anabela Damas
on 11/28/14, 9:39 AM
thanks Anabela
yes, it helped !!
I already posted my question, thanks

ps. this is the link, still dealing with Python sample scripts before working from GAS

Regards, Fausto | 416-821-3185 | go.theXS.ca/now | simplifying IT

On Fri, Nov 28, 2014 at 9:39 AM, Anabela Damas <adamas-versaointegral-pt@mail.odoo.com> wrote:

Hope that my "like" helps you to get karma ;) For you to post questions about GAS.

Anabela Damas
Sent by Odoo S.A. using Odoo about Forum Post False

Fausto R.
on 11/28/14, 9:48 AM

Ludo - 21South

--Ludo - 21South--
| 2 2 5
Zwijndrecht, Netherlands
--Ludo - 21South--


Ludo - 21South
On 11/19/14, 7:10 AM

What have you tried? Where did your script stop and what was the error? 

I am by no means an expert in google script, but the error might be explained from the OpenERP point of view.


One thing I noticed is that the url of your connection is pointing to port 8086. Have you tried port 8069, which is the default for XML-RPC in OpenERP?

Other than that, the parse error usually means that you are trying to parse something using the wrong format OR the field itself does not exist.

I've update my answer. Thanks for try to help =)

Versão Integral, Anabela Damas
on 11/19/14, 7:55 AM


Versão Integral, Anabela Damas
on 11/19/14, 7:56 AM

Updated the answer. Perhaps someone with some more experience can answer the question better.

21south, Ludo - 21South
on 11/19/14, 7:59 AM

cat /etc/openerp-server.conf | grep xmlrpc xmlrpcs = False xmlrpcs_interface = xmlrpcs_port = 8087 xmlrpc_interface = xmlrpc_port = 8086 xmlrpc = True I'm using the correct port. Thanks

Versão Integral, Anabela Damas
on 11/19/14, 9:06 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 11/19/14, 6:33 AM
Seen: 2628 times
Last updated: 7/16/16, 3:37 AM