PHP xml-rpc problem using ripcord library

A

Anonymous

Guest
hi all, please if this is not appropriate place to post this question, kindly move it to and inform to have track.

I want to use Odoo (previsouly OpenERP) webservices using PHP as the examples on Odoo documentation (Odoo External API), link is here: https://www.odoo.com/documentation/14.0/webservices/odoo.html

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 "ripcord" used 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:
Code:
<?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 Fatal error: require_once(): Failed opening required 'ripcord.php' (include_path='\xampp\php\PEAR') in D:\xampp\htdocs\mytest\tests.php
Is there anything else i missed or have to configs/settings or should i have xmlrpc.php too? if yes, where it should be copied? please help as I am stuck. if any related info required, please ask for to have enough information to resolve the problem.
regards
 
PHP uses a user defined autoload function to find the code for classes as you instantiate them. If you're using composer, the autoload for your included packages is probably at "vendor/autoload.php". Change you require_once line as follows:

Code:
require_once('vendor/autoload.php');

And let us know how that works.
 
thanks @simonbrahan for reply. i modified the code as per instruction but it is showing same error
Warning: require_once(vendor/autoload.php): failed to open stream: No such file or directory in D:\xampp\htdocs\mytest\tests.php on line 10

Fatal error: require_once(): Failed opening required 'vendor/autoload.php' (include_path='\xampp\php\PEAR') in D:\xampp\htdocs\mytest\tests.php on line 10

tests.php
Code:
<?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('vendor/autoload.php');
$common = ripcord::client($url'/xmlrpc/2/common');
$ver = $common->version();
echo $ver;
$uid = $common->authenticate($db, $username, $password, array());
echo $uid;
?>
 
Do you have a vendor folder in your codebase? Composer should have created one, and the path in your require_once command should point to it.
 
simonbrahan said:
Do you have a vendor folder in your codebase? Composer should have created one, and the path in your require_once command should point to it.
thanks for your passions to help me.

Do you have a vendor folder in your codebase?
sorry, i don't know what it here means "codebase", if its my project folder then no, i just have a tests.php file and nothing in my D:\xampp\htdocs\mytest\ folder

when searched for name vendor in my xampp (portable) folder, it shows me as below:
some folders:
D:\xampp\composer\vendor
D:\xampp\phpMyAdmin\js
D:\xampp\perl

some files like:
D:\xampp\phpMyAdmin\libraries\vendor_config.php
D:\xampp\phpMyAdmin\doc\html\vendors.html
D:\xampp\phpMyAdmin\doc\html\vendors.rst.txt
etc.

is it you meand that it needs to copy D:\xampp\composer\vendor folder in D:\xampp\htdocs\mytest folder?
or something else?

after copying "vendor" folder from composer to my project folder and put the same code as mentioned in your earlier post [ require_once('vendor\autoload.php') it is showing now
Fatal error: Uncaught Error: Class 'ripcord' not found in D:\xampp\htdocs\mytest\tests.php:11 Stack trace: #0 {main} thrown in D:\xampp\htdocs\mytest\tests.php on line 11

about path: is it should be require_once('D:\xampp\htdocs\mytest\vendor\darkaonline\ripcord\src\Ripcord\ripcord.php')?
or something else?
regards
 
@simonbrahan
thanks for your all efforts to help me :)
its done, i received response from Odoo database.
i cloned ripcord library from github using GitBash while I was in my project directory "mytest" with command below:
git clone https://github.com/poef/ripcord

my php file:
Code:
<?php

$url = "http://192.168.18.71:8069";  // my vm url -- note its http NOT https 
$db = 'odb';  // database name in Odoo -- Odoo uses PostgreSQL
$username = 'odoouser@myhost.com';  // Odoo user 
$password = 'admin';  // password for user 

require_once('ripcord\ripcord.php'); // ripcord library included here with path starts from project directory
$common = ripcord::client($url.'/xmlrpc/2/common'); 
$ver = $common->version();
$uid = $common->authenticate($db, $username, $password, array()); // authentication successful if uid contains a positive value
echo $uid;  // print uid value in browser 

?>
i am getting user id in chrome browser. now will go further to get data... actually CRUD operations.
thanks again.
regards

( now you can close this topic. i copy/pasted here the solution which can be beneficial for any one who want it )
 
Back
Top