Magento – Magento XML RPC Error

modulezend-framework

I have created an XML-RPC User and I've assigned a role (with all resources) from admin panel: System/Web Services/XML-Rpc Users and Roles.

Now I want to dump all cart products and send them to an external server.

I'm using this code in app/design/frontend/default/theme/template/catalog/product/view.phtml:

$client = new Zend_XmlRpc_Client('http://mysite/api/xmlrpc/', 80);
$session = $client->call('login', array('myuser', 'myapi'));
$filterData = array('type' => array('in' => 'simple'));
$product = $client->call('call', array($session, 'category_product.list', array($filterData)));
var_dump($product);
$server = new Zend_XmlRpc_Client('/xmlServer.php','www.server-site.com', 80);
$result = $server->send($product); 

The problem is that I receive this error:

Fatal error: Call to a member function getUri() on a non-object in /var/www/html/zzz/lib/Zend/XmlRpc/Client.php on line 265 

This is the code from line 265:

if($http->getUri() === null) {
        $http->setUri($this->_serverAddress);
    }

I think that the problem comes from here:

$session = $client->call('login', array('myuser', 'myapi'));

But the user and api are valid. So I don't know what could it be.
What is wrong in my code?

Anticipated thanks!

Best Answer

The problem is with:

$client = new Zend_XmlRpc_Client('http://mysite/api/xmlrpc/', 80);

The second param of Zend_XmlRpc_Client is a Zend_Http_Client object, not the port number. Change your code to:

$client = new Zend_XmlRpc_Client('http://mysite/api/xmlrpc/');
Related Topic