Help

5

Web Services Tutorial Odoo/PHP

Avatar
Thierry Godin

Hello all,

I just published a new tutorial about Web Services.

For now, it's only in french. US translation 's coming soon.

http://thierry-godin.developpez.com/openerp/openerp-xmlrpc-php-fr/

2 Comments
Avatar
Discard

@Thierry, what would be the best way to work from Android to Odoo? Could you then best direct from Android to mySQL / PHP and then too Odoo? Or would there be a way to send from Android to Odoo instantly? Thanks for the tutorial, its great.

Avatar
Thierry Godin
-

@Yenthe , Sorry mate, I don't know Android programming. I cannot help you for this :(

2 Answers
7
Avatar
Thierry Godin
Best Answer

The english version of the tutorial is here :

http://thierry-godin.developpez.com/openerp/openerp-xmlrpc-php-en/

The files of the scripts can be downloaded here :

http://www.lapinmoutardepommedauphine.com/openerp/odoo_xmlrpc_php_files.zip

3 Comments
Avatar
Discard
Avatar
ThackerS (ts)
-

Good job Thierry. I wait the tutorial on odoo interface customization.

Thank you for sharing this Thierry! This is a goldmine of basic information to learn from.

Avatar
Ashish Singh
-

Thnaks Thierry Godin ...

0
Avatar
charles
Best Answer

Hi Godin,

I'm new to odoo and have just successfully installed odoo under Ubuntu in Oracle Virtual Box (virtual machine), which is running under windows 8. Luckily, everything is fine by using the application. 

Your tutorial is great, thanks a lot. I followed your example code (copied below) to practice. Unfortunately, the PHP program stopped at this statement "$connexion = new xmlrpc_client($server_url . "/xmlrpc/common");". And there were no error messages shown at all. 

Can you provide further help?

1. Are there any error messages to trace what happen?

2. Are there any system settings in odoo before I can use PHP XML-RPC?

Thanks a lot for your help in advance.

 

----------------------------------------------------------------------------------------------------------------------------------------------------------------

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
echo '<h2>XML-RPC AVEC OPENERP/ODOO ET PHP</h2>';

include("xmlrpc_lib/xmlrpc.inc.php");
include("xmlrpc_lib/xmlrpcs.inc.php");
$GLOBALS['xmlrpc_internalencoding']='UTF-8';

$user = 'admin';
$password = 'mY5up3rPwd';
$dbname = 'test';

$server_url = 'http://192.168.1.120:8069'; 
$connexion = new xmlrpc_client($server_url . "/xmlrpc/common");
$connexion->setSSLVerifyPeer(0);

$c_msg = new xmlrpcmsg('login');
$c_msg->addParam(new xmlrpcval($dbname, "string"));
$c_msg->addParam(new xmlrpcval($user, "string"));
$c_msg->addParam(new xmlrpcval($password, "string"));
$c_response = $connexion->send($c_msg);

if ($c_response->errno != 0){
    echo  '<p>error : ' . $c_response->faultString() . '</p>';
}
else{
    
    $uid = $c_response->value()->scalarval();

    $val = array ( 
        "name"    => new xmlrpcval("Godin Thierry", "string"),
        "street"  => new xmlrpcval("Au fond à gauche", "string"),
        "city"    => new xmlrpcval("Marne la Vallée", "string"),
        "zip"     => new xmlrpcval("77000", "string"),
        "website" => new xmlrpcval("http://www.lapinmoutardepommedauphine.com", "string"),
        "lang"    => new xmlrpcval("fr_FR", "string"),
        "tz"      => new xmlrpcval("Europe/Paris", "string"),
        ); 
    
    $client = new xmlrpc_client($server_url . "/xmlrpc/object");
    $client->setSSLVerifyPeer(0);

    $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("create", "string")); 
    $msg->addParam(new xmlrpcval($val, "struct")); 
    $response = $client->send($msg);
    
    echo 'Partner created - partner_id = ' . $response->value()->scalarval();
}
?>

4 Comments
Avatar
Discard
Avatar
Thierry Godin
-

Hi Charles, You have to set the proper IP address of your own server, you have to set the proper dbname you use and your own credentials (username + password). Also, ensure you have copied the xmlrpc lib in the right path.

Avatar
charles
-

Hi Thierry, Thank you very much for your reply. I'm sorry that I didn't make it clear. I did set the IP address, dbname, login and password correctly. For the xmlrpc lib, I copy it to a folder by following your comments in your tutorial. Please my code extract below. By the way, my odoo version is 8. Are there any settings in the odoo server side? echo '

XML-RPC AVEC OPENERP/ODOO ET PHP

'; include("xmlrpc/lib/xmlrpc.inc.php"); include("xmlrpc/lib/xmlrpcs.inc.php"); $GLOBALS['xmlrpc_internalencoding']='UTF-8'; $user = 'admin'; $password = 'password'; $dbname = 'mydb'; $server_url = 'http://192.168.56.101:8069';
Avatar
charles
-

Hi Thierry, I've found a problem. In my version of xmlrpc, the file names of xmlrpc.inc and xmlrpcs.inc are without .php. In other words, the file names are xmlrpc.inc and xmlrpcs.inc only. In addition, there is typo in the program. It should be $c_response (not $response) of the following statement : echo 'Partner created - partner_id = ' . $response->value()->scalarval(); Although the program can be run successfully now, I can't find the record in odoo. Will check again tomorrow. Good night.

Avatar
Thierry Godin
-

Your 're right Charles, right typo is $c_response. Thanks for the info. About adding .php to .inc file is a security stuff to avoid diplaying inc file in browser.