This is our blog

We have a few tips for you.

The Magento SOAP v1 API provides you with the ability to manage your eCommerce stores by providing calls for working with resources such as customers, categories, products, and sales orders. It also allows you to manage shopping carts and inventory. Gives you ability to manage customers, categories, products, sales and checkout process.

When to use Magento API?
• You want to integrate with third party application.
• Why use Magento API?
• More stable than underlying code
• Less code implementation
• Tons of examples and documentation around API

What is SOAP?
SOAP is a XML-based protocol that allows applications to send messages in a standarized way over the Internet. The communication with SOAP boils down to a SOAP server and a SOAP client. Magento offers a SOAP server that allows you to communicate with Magento on a level that allows you to integrate Magento into your own application.

The benefit of using SOAP (or its rival XML-RPC) is that first of the communication is done through HTTP, so you don’t need any extra holes in the firewall. Also there are numerous SOAP-clients and XML-RPC-clients out there, and with most of them you don’t have to worry how the actual communication between your client and the Magento server is handled: The only thing you have to worry about is calling the right server-side API-method, which will return some kind of result, and knowing how to handle this result.

A: Create a Magento API user:

Step1 :Create a Web Service Role:
1) From the Admin menu, select System-> Web Services-> Roles.

2) Click the Add New Role button:

3) In the Role Information section, enter a Role Name such as “API”:

4)_In the panel on the left, select Role Resources. Then do one of the following:
– To enable full access to customer, catalog, and sales information, set Resource Access to “All.”
– To provide limited access to data, set Resource Access to “Custom.” Then, tick the “Sales”.
– checkbox from the list that appears below.

5) When complete, click the Save Role button.

Step2: Create a Web Service User:
1) From the Admin menu, select System-> Services-> Users

2) Click the Add New User button.
3) Complete the following fields: User Name, First Name, Last Name, Email.
4) In the API Key field, enter a password/token of your choice. This will be used to when linking your account.
5) To confirm, re-enter the key in the API Key Confirmation field.
6) In the panel on the left, select User Role. Then, select the “API” Role created earlier.
7) When complete, click the Save User button.

Now we got magento API username and API Key, which is used to connect Magento with other application.

Example: Logging with the SOAP client
So let’s create a simple PHP-script that allows us to login into Magento through SOAP. The logic is here that we first need to initialize a new SoapClient object with as argument the Magento SOAP URL.

Magento login information
$mage_url = ‘http://MAGENTO/api/?wsdl’;
$mage_user = ‘soap_user’;
$mage_api_key = ‘********’;

Initialize the SOAP client
$soap = new SoapClient( $mage_url );

Login to Magento
$session_id = $soap->login( $mage_user, $mage_api_key );

After we have initialized the $soap-object we login with the API user-credentials created earlier. This will return a session-ID which we will need to reuse when calling other API-methods. The login() method is actually not part of the SoapClient-class. The class transforms this method-call into another call to the magic method __soapCall() with the first argument set to “login” and as second argument an array of the arguments given to the original method “login()” (in this case the user credentials).

This structure allows us to easily call any SOAP-method:
$response = $soap->getSomethingSpecific($arguments);

Example: A simple API-call
The listing shows us the various API-resources that can be used. These resources do not represent SOAP-methods themselves, but they can be fetched only through the SOAP-method “call()”. For instance the list of resources mentions the Country Api that has a method to fetch a list of countries. This method has a path “directory_country.list” and an alias “country.list”. To fetch this list of countries, we can use either the path or one the aliases:

Again the result is a large array.

The Product API allows us to specify a product through its database ID or its SKU:

For instance if the Product ID is specified in the URL, you should prevent for exploits by making sure it is a number:

Giving multiple arguments is just as easy as giving one argument. The clue here is that if we want to pass a single argument to the API-call we can just add that single argument, but if we want to add multiple arguments we need an array:

Example: Changing data through the API
Now we can setup a SOAP client and use it retreive data from the Magento API. Changing data is done in exactly the same way as fetching data. The difference is that the arguments now hold not only the indicator “what we want to change” but also the data that contains the change:

Example: Using lists and filters
If we want to collect a list of products the Product API gives us the “list()” method:

This API-method has an extra argument $filters which allows for very cool possibilities. For instance the following adds a filter to show only products with the status set to 1, in other words products which are enabled:

But the $filters can be made more advanced as well. The following filters select all enabled products that are of type “simple” (so neither configurable products nor grouped products) which have a SKU starting with the letters “ma”.

Example: Making multiple calls at once
With the available “list()” methods you can succesfully collect a list of items (products, categories, customers), but further inspection of the returned data will show that it does not include the full item-data. For instance when returning products the “description” is missing.

The logic is here that you can use “list()” to give a full-list of items (or for instance a list based upon filters) but that you will still need the “info()” method to get the full information for every item in that list.
Instead of making a “” call for every product in the list (which will cost a lot of extra HTTP-traffic) you can combine multiple call in one SOAP-call through the “multiCall” method.

A simple example below:

You can also combine multiple API-methods of different types in the same call:

Hope you get me !