5

I am trying to get some data from Odoo through XMLRPC, and I am working with PHP and its Ripcord library (recommended on https://www.odoo.com/documentation/8.0/api_integration.html).

So I am following the steps written on that page.

Firstly, I downloaded the Ripcord files from https://github.com/poef/ripcord.git. I saved them in a folder named ripcord, located at the index directory of my PHP page.

Secondly, I enabled the OpenSSL and XMLRPC extensions for PHP7. I think I did it well because if I execute the next sentence:

$modules = get_loaded_extensions();
foreach ($modules as $module) {
    echo $module.', ';
}

I get this result:

Core, date, libxml, openssl, pcre, zlib, filter, hash, Reflection, SPL, session, standard, apache2handler, mysqlnd, PDO, xml, calendar, ctype, curl, dom, mbstring, fileinfo, ftp, gd, gettext, iconv, json, exif, mcrypt, mysqli, pdo_mysql, Phar, posix, readline, shmop, SimpleXML, sockets, sysvmsg, sysvsem, sysvshm, tokenizer, wddx, xmlreader, xmlrpc, xmlwriter, xsl, Zend OPcache,

Now, this is the code of my index.php:

$url = 'http://localhost:30080';
$db = 'db_v80_test_01';
$username = 'admin';
$password = 'adminpwd';

require_once('ripcord/ripcord.php');

// $info = ripcord::client($url)->start(); 
// list($url, $db, $username, $password) = array($info['host'], $info['database'], $info['user'], $info['password']);

$common = ripcord::client($url.'/xmlrpc/2/common');

$uid = $common->authenticate($db, $username, $password, array());
die($uid);

The problem is that I am getting nothing in $uid variable. Can anyone tell me what is happening?

NOTE

May be this question is duplicated: Odoo API web service doesn't return anything

But as it had no answers, I tried to give more information on mine.

forvas
  • 9,801
  • 7
  • 62
  • 158

1 Answers1

5

Ok, I had not error log enabled in php.ini, so I always get nothing. If I had enabled it earlier, I would have seen that the error was that I was trying to print a kind of value I cannot print, so the problem was in the die command.

Now, it is working perfectly with this code:

$url = 'http://localhost:30080';
$db = 'db_v80_test_01';
$username = 'admin';
$password = 'adminpwd';

require_once('ripcord/ripcord.php');

$common = ripcord::client($url.'/xmlrpc/2/common');
$uid = $common->authenticate($db, $username, $password, array());
$models = ripcord::client("$url/xmlrpc/2/object");
$partners = $models->execute_kw(
    $db,
    $uid,
    $password,
    'res.partner',
    'search',
    array(
        array(
            array('is_company', '=', true),
            array('customer', '=', true)
        )
    )
);

echo('RESULT:<br/>');
foreach ($partners as $partner) {
    echo $partner.'<br/>';
}
forvas
  • 9,801
  • 7
  • 62
  • 158
  • forvas, how did you managed to get it work ? What was the error you've got ? When I var_dump($partners) , then I always keep getting this array { "faultCode"=> 3, "faultString"=> "Access Denied" } . Also, when I call the ripcord::client($url)->start() method, I get Fatal error: Uncaught Ripcord_TransportException: Could not access – Victor Attila Breelle Jan 27 '21 at 08:31
  • I remember nothing about this, except for it worked. Does the user you selected for the connection have enough Odoo access rights to see all the partners you are getting with your query? – forvas Jan 27 '21 at 10:29
  • Yes I think it has the access rights, since I use the Odoo Trial. I even used your code above for testing, but I can't make it work. Here is where I asked my question, if you want to take a further look : https://stackoverflow.com/questions/65916457/cannot-access-to-odoo-external-api-using-php-7-xml-rpc-access-denied-fatal-er – Victor Attila Breelle Jan 27 '21 at 12:20
  • 1
    So, I decided to purchase some modules, and opened the 8069 port for the IP address of my new database, and it worked :) Now I can deduce that Odoo Demo DO NOT work. – Victor Attila Breelle Feb 05 '21 at 15:52