Magento – Web Service Calls / API

At Fluid Branding we recently moved our website over to Magento. This all went very successfully, so one of the things we’re doing now is integrating our back office systems with Magento:

Fluid Branding Website - May 2012
Fluid Branding Website – May 2012

The first thing I needed to do was to retrieve details of a specified product from Magento. The back office system is on a different server from the website itself, so I needed to set up an API to be able to get the data. A simplified version of the API code that I set up follows, this code being present on the Magento server and the call being made using Curl from the back office system:

As you can see, the data is returned in JSON format, which is then just de-coded on the client side. One thing to note in this example are the following chunks of code:

…which, in the example above, is used to obtain the name of the manufacturer rather than just its id. I later found that a simpler way to do this is to use the following code:

Having set up this API I then found out that Magento had its own API system. Given that I needed to do another API call to search for some products and then return their details, I thought I’d try using Magento’s API system. The code that follows shows a test that I set up to do this and it demonstrates a few things beyond the simple examples given in the Magento documentation:

  • Searching for products using a ‘complex’ filter
  • Retrieving additional and custom product data attributes
  • Retrieving the option name for a dropdown field (manufacturer name in this case)
  • Retrieving main product image

Note that to get all the info I needed I had to call the following APIs:

  • catalogProductList
  • catalogProductInfo
  • catalogProductAttributeOptions
  • catalogProductAttributeMediaList
  • catalogProductAttributeList


What I found in my case is that the API calls just took too long (I think it was around 10 seconds to get details on around 30 products that met the search criteria!). I therefore ended up coding my own API which did the same thing in a fraction of a second.

I’d be interested in hearing about other people’s experiences with Magento API and how you’ve approached similar requirements.