On 10/10/2014 09:21, frederic.lange...@coopengo.com wrote:
> I m trying to call a tryton web service (for example create) via XML
> RPC from php but encountered somme issues. If someone already succeed
> in calling tryton from php, can you please provide an example?

Here are two examples using XML-RPC:

<?php

/*
 * XML-RPC calls to trytond using https://github.com/gggeek/phpxmlrpc/
 */

set_include_path(get_include_path() . PATH_SEPARATOR .
    './phpxmlrpc.git/lib');
require_once 'xmlrpc.inc' ;
require_once 'xmlrpcs.inc' ;
require_once 'xmlrpc_wrappers.inc' ;

function getVersion($url, $user, $pass) {
    $server = new xmlrpc_client($url);
    $message = new xmlrpcmsg(
        'common.server.version',
        array(new xmlrpcval(0, 'int'), new xmlrpcval(0, 'int'))
    );
    $message = new xmlrpcmsg('common.server.version');
    // With XML-RPC, authentication is mandatory, see
    // https://bugs.tryton.org/issue4148
    $server->setCredentials($user, $pass);

    $server->return_type = 'phpvals';
    $result = $server->send($message);
    print "\nTrytond version: " . $result->value() . "\n";
}


function readModel($url, $user, $pass) {
    $server = new xmlrpc_client($url);
    $server->setCredentials($user, $pass);
    $message = new xmlrpcmsg(
        // method
        'model.ir.model.read',
        // parameters
        array(
            new xmlrpcval(
                // ids
                array(
                    new xmlrpcval(1, 'int'),
                    new xmlrpcval(2, 'int')),
                'array'
            ),
            new xmlrpcval(
                // fields
                array(
                    new xmlrpcval('info', 'string'),
                    new xmlrpcval('model', 'string'),
                    new xmlrpcval('name', 'string'),
                    new xmlrpcval('module', 'string')),
                'array'
            ),
            // context
            new xmlrpcval([], 'struct')
        )
    );
    $server->return_type = 'xml';
    $result = $server->send($message);
    print "\nRead call returns: \n" . $result->value() . "\n";
}

$url = 'http://localhost:8069/';
$db = 'xml34';
$user = 'admin';
$pass = 'admin';

getVersion($url . $db, $user, $pass);
readModel($url . $db, $user, $pass);

?>

--
Pierre-Louis

Reply via email to