Odoo Help

Welcome!

This community 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.

0

xmlrpc PHP: need a functional "read" example

By
Thierry Godin
on 7/5/14, 12:29 PM 4,972 views

Hello all,

I try to get "read" working thru xmlrpc with PHP but the only response I get is this kind of stuff  (PHP print_r):

xmlrpcresp Object ( [val] => xmlrpcval Object ( [me] => Array ( [struct] => Array ( [id] => xmlrpcval Object ( [me] => Array ( [string] => 0 ) [mytype] => 1 [_php_class] => ) ) ) [mytype] => 3 [_php_class] => ) [valtyp] => xmlrpcvals [errno] => 0 [errstr] => [payload] => [hdrs] => Array ( [content-type] => text/xml [content-length] => 196 [server] => Werkzeug/0.8.3 Python/2.7.3 [date] => Sat, 05 Jul 2014 16:25:04 GMT ) [_cookies] => Array ( ) [content_type] => text/xml [raw_data] => HTTP/1.0 200 OK Content-Type: text/xml Content-Length: 196 Server: Werkzeug/0.8.3 Python/2.7.3 Date: Sat, 05 Jul 2014 16:25:04 GMT id 0 )

Response is empty (I mean, does not return fields)

For now I managed to login + search or create methods.

Does somebody have a short example for read method that works ?

Thank You

Hello, try this $msg = new xmlrpcmsg('execute'); $msg->addParam(new xmlrpcval($dbname, "string")); $msg->addParam(new xmlrpcval($userId, "int")); $msg->addParam(new xmlrpcval($password, "string")); $msg->addParam(new xmlrpcval($relation, "string")); $msg->addParam(new xmlrpcval("read", "string")); $msg->addParam(new xmlrpcval($id, "array")); $msg->addParam(new xmlrpcval($fields, "array")); With fields are array of fields you want

DelphineL
on 7/7/14, 3:54 AM

And when you try the response is this? It must have a mistake.The good response is something like an array of struct or an array of array i don t remember exactly. With id is the key and the struct is make of field1=value1 field2=value2 etc

DelphineL
on 7/7/14, 2:16 PM

Yes response is the one above. But this is an array of arrays . The "struct" one is already on first line but it does not contain the fields I read ("name")

Thierry Godin
on 7/8/14, 2:55 AM

$partner_id = "10"; $id_list = array(new xmlrpcval($partner_id, "int")); $key = array( new xmlrpcval("name", "string"), ); $msg = new xmlrpcmsg('execute'); $msg->addParam(new xmlrpcval($dbname, "string")); $msg->addParam(new xmlrpcval($uid, "int")); $msg->addParam(new xmlrpcval($password, "string")); $msg->addParam(new xmlrpcval("res.partner", "string")); $msg->addParam(new xmlrpcval("read", "string")); $msg->addParam(new xmlrpcval($id_list, "array")); $msg->addParam(new xmlrpcval($key, "array"));

DelphineL
on 7/8/14, 4:13 AM
1
DelphineL
On 7/8/14, 4:21 AM

For me: 

        $val = $res->value()->scalarval();
            
            $ides = array();
            $client = new xmlrpc_client($serverUri.'object');
            $ides[0]=new xmlrpcval(1, "int"); 
            $fields = array(new xmlrpcval("name", "string"), new xmlrpcval("email", "string"));
            
            $msg = new xmlrpcmsg('execute');
            $msg->addParam(new xmlrpcval($db, "string"));
            $msg->addParam(new xmlrpcval($id, "int"));
            $msg->addParam(new xmlrpcval($password, "string"));
            $msg->addParam(new xmlrpcval("res.partner","string"));
            $msg->addParam(new xmlrpcval("read", "string"));
            $msg->addParam(new xmlrpcval($ides, "array"));
            $msg->addParam(new xmlrpcval($fields, "array"));

            $res = &$client->send($msg);

$res give : 

xmlrpcresp Object ( [val] => xmlrpcval Object ( [me] => Array ( [array] => Array ( [0] => xmlrpcval Object ( [me] => Array ( [struct] => Array ( [id] => xmlrpcval Object ( [me] => Array ( [int] => 1 ) [mytype] => 1 [_php_class] => ) [name] => xmlrpcval Object ( [me] => Array ( [string] => Delphine Lemire ) [mytype] => 1 [_php_class] => ) [email] => xmlrpcval Object ( [me] => Array ( [string] => delphine.lemire@gmail.com ) [mytype] => 1 [_php_class] => ) ) ) [mytype] => 3 [_php_class] => ) ) ) [mytype] => 2 [_php_class] => ) [valtyp] => phpvals [errno] => 0 [errstr] => [hdrs] => Array ( [content-type] => text/xml [content-length] => 416 [server] => Werkzeug/0.9.4 Python/2.7.6 [date] => Tue, 08 Jul 2014 08:18:01 GMT ) [_cookies] => Array ( ) [content_type] => text/xml )

 

Oh sorry Delphine, You were right. My fault. I had to write "array" instead of "struct". Thanks a lot for your help ;o)

Thierry Godin
on 7/8/14, 5:19 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 7/5/14, 12:29 PM
Seen: 4972 times
Last updated: 3/16/15, 8:10 AM