0

I want to use Odoo webservices using PHP as the examples on Odoo documentation (Odoo External API), link is here: Odoo External API

I have tried python examples on above page which works fine... even from another machine's same vm (both vm's are Ubuntu 18.04 Desktop, running Odoo 14) I have not any idea of using/writing code in PHP, on my Windows host machine, I have downloaded XAMPP portable, enable xmlrpc in php.ini, installed ripcord library through composer, (as it uses in PHP examples in above official guide) started XAMPP controller + Apache, created a .php file in d:\xampp\htdocs\mytest\test.php with code below:

<?php

//url = my ubuntu vm ipv4 with odoo default port
$url = "http://192.168.18.71:8069"; 
$db = 'odb';
$username = 'odoouser@myhost.com';
$password = 'admin';

require_once('ripcord.php');
$common = Ripcord::client($url'/xmlrpc/2/common');
$ver = $common->version();
echo $ver;
$uid = $common->authenticate($db, $username, $password, array());
echo $uid;
?>

run the page in Chrome, it says Warning: require_once(ripcord.php): failed to open stream: No such file or directory in D:\xampp\htdocs\mytest\test.php is there anything else i missed or have to configs/settings or i have to have xmlrpc.php too? if yes, where it should be copied? please help as I am searching and trying since last Sunday and still failed. if any related info required, please ask for to have enough information to resolve the problem.

Ahmed Haroon
  • 69
  • 1
  • 12
  • https://stackoverflow.com/questions/41440978/how-to-use-php7-ripcord-library-to-get-odoo-data – Ajay Apr 07 '21 at 06:07
  • thanks @Ajay, during my search, i have seen it but the problem is i don't know where to place this downloaded ripcord related files in my xampp portable environment? also not mentioned in that question. already i have mentioned that i have no idea how to in PHP. – Ahmed Haroon Apr 07 '21 at 06:34
  • save it in a folder named ripcord, located at the index directory of your PHP page.`C:/xampp/htdocs` – Ajay Apr 07 '21 at 06:39
  • @Ajay copied the downloaded folder (Ripcord-master) in D:\xampp\htdocs\mytest\ and re-started xampp + Apache, it is showing almost same error. – Ahmed Haroon Apr 07 '21 at 06:56
  • Warning: require_once(ripcord.php): failed to open stream: No such file or directory in D:\xampp\htdocs\mytest\test.php Fatal error: require_once(): Failed opening required 'ripcord.php' (include_path='\xampp\php\PEAR') in D:\xampp\htdocs\mytest\tests.php – Ahmed Haroon Apr 07 '21 at 07:37

1 Answers1

0

final code which works fine, retrieve data ('name') from res_partner. just to inform, i have Odoo 14 installed on a ubuntu 18.04 desktop, sets its network as Bridge and used Odo's default port. have XAMPP portable on my Win'7 host machine, created a project folder in D:\xampp\htdocs\mytest and cloned "ripcord" library with GitBash: git clone https://github.com/poef/ripcord

created .php file (below) and test it in Chrome, it is showing name column data from res_partner... as expected.

<?php
// Login information
$url = 'http://192.168.18.71:8069';
$url_auth = $url . '/xmlrpc/2/common';
$url_exec = $url . '/xmlrpc/2/object';
$db = 'odb14';
$username = 'odoouser@myhost.com';
$password = 'admin';
// Ripcord can be cloned from https://github.com/poef/ripcord
require_once('ripcord\ripcord.php');
// Login
$common = ripcord::client($url_auth);
$uid = $common->authenticate($db, $username, $password, array());
print("<p>Your current user id is '${uid}'</p>");
$models = ripcord::client($url_exec);
$models                 // The (Ripcord) client
    ->execute_kw(       // Execute command
    'table.reference',  // Referenced model, e.g. 'res.partner' or 'account.invoice'
    'search',           // Search method of the referenced model
    array()             // Search domain
);
$customer_ids = $models->execute_kw(
    $db, // DB name
    $uid, // User id, user login name won't work here
    $password, // User password
    'res.partner', // Model name
    'search', // Function name
    array( // Search domain
        array( // Search domain conditions
            array('active', '=', true))
        )
 );
$customers = $models->execute_kw($db, $uid, $password, 'res.partner',
    'read',  // Function name
    array($customer_ids), // An array of record ids
    array('fields'=>array('name')) // Array of wanted fields
);
print("<p><strong>Found customers:</strong><br/>");
foreach ($customers as $customer){
    print("{$customer['name']}<br/>");
}
print("</p>");
?>

happy coding :)

Ahmed Haroon
  • 69
  • 1
  • 12