Web Services: Additional information

Last modified by arst on Fri, June 25, 2010 10:02
Source|Old Revisions  

This is an old revision of the document!

The basic info on Magento API through web services jumps past some important points. It took me some time to figure this out, so I’ll share some points here.

First steps

  • Web services API is only available in Magento version 1.1.0 and later.
  • To use it one should first install the Zend Framework (for XmlRpc). It can be downloaded from http://framework.zend.com/download. The Minimal version is enough.
  • Copy the Zend directory to somewhere the webserver can see it and update the PHP variable ‘include_path’. On Linux, all include paths traversed by the php need to have x permission (for group and other).

Create a user and role in Admin panel

Then some work in the Magento admin panel is required:

  • A user for the API must be created in System > Web Services > Users
  • The username and password is required for logging in from the client script (”apiuser” , “apipass”).
  • A role for the API must be created in System > Web Services > Roles
  • Assign permissions to the role: The simplest is to select “All” in the “Resource Access” selector.
  • Bind the new user to the new role.

Running an XmlRpc sample

Then, a basic script using XmlRpc can be run from a client. My test shop is at “localhost/magento”. Let’s retrieve the customer list:

      require 'Zend/XmlRpc/Client.php';
      $client = new Zend_XmlRpc_Client('http://localhost/magento/api/xmlrpc/');
      // If somestuff requires api authentification,
      // we should get session token
      $session = $client->call('login', array('apiuser', 'apipass'));
      $r = $client->call('call', array($session, 'customer.list'));
      // If you don't need the session anymore
      $client->call('endSession', array($session));


It seems trickier to get WSDL powered calls to work properly. I’ve followed the instructions (AFAIK) and the WSDL sample hangs for a long time when trying to create the SoapClient. Eventually it times out and throws an exception.

I manage to retrieve the WSDL file, but on creating a SoapClient:

Warning: SoapClient::SoapClient() [function.SoapClient-SoapClient]: I/O warning : failed to load external entity "http://localhost/magento/api/?wsdl" in /var/www/test_api.php on line 3

Retrieving the WSDL URL manually goes fine, but Magento doesn’t get past that point on my Linux system.