Web Services: Additional information

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

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));


After a lot of trial and error I find the reason why I have problems getting SOAP calls to work:

... and in having the two different URLs (which both point back to the local machine), PHP session handling breaks down, and the sample halts forever.

The solution was to use the same URL for anything that represents the same session:

Now it works!

On measuring performance on my local machine, it seems that SOAP is around 3 times slower than XmlRpc. The nested callback to render the WSDL is not really necessary, it will just go back to the server. It is quite time consuming.