Accessing the Magento V2 API
Note: This article was originally published at Planet PHP on 24 June 2010.Magento at work, and in particular with integrating with their API. Now, before I say anything more, I must say that I am always pleased when I see that these products do include some kind of API. The Magento one is a bit interesting, although there is some half-decent API documentation for the original API.
However they have then released a new version of the API, with very little documentation. So here are two calls - one to the v1 API and one to the v2 - which I hope will help illustrate the differences. The example I'll give is the customer list functionality, including filtering the result set - because this was a total mystery when I started working with the v2 API!
A A $options = array(
A A A A "location" = 'http://magentoinstall.local/index.php/api/index/index/',
A A A A "uri" = 'http://magentoinstall.local/api/'
A A A A);
A A $client = new SoapClient(NULL, $options);
A A $session = $client-login('user', 'pass');
A A $list = $client-call($session, 'customer.list', array(array("customer_id" = "42")));
To make the same call with API version 2, we need to address the method in a different way, using the structure in the underlying code as the method name that we call, and CamelCasing those, like this:
A A$client = new SoapClient('http:/magentoinstall.local/api/v2_soap?wsdl=1');
A A$session = $client-login('user', 'pass');
A A $filter = new StdClass();
A A $filter-filter = array(array("key" = "customer_id", "value" = "42"));
A A $list = $client-customerCustomerList($session, $filter
Truncated by Planet PHP, read more at the original (another 526 bytes)