The use of SOAP in Magento

SOAP provides a very simple, fast and secure communication between Magento and external systems such as ERP systems or mobile applications. The language of an external application does not matter when you use SOAP. We can do both – send and receive information about products, customers, orders etc.. With a little work , it is also possible to prepare own methods that will provide us with the required data in a suitably formatted way.

Before we start

Magento supports SOAP in both versions (version 1 and 2). The methods and the addresses differ from each other depending on the used version.

Address for SOAP v1

Address for SOAP v2

Example of a method for SOAP v1

The same method for SOAP v2

The methods used above are suitable for SOAP v1, however they can also be used for SOAP v2.

Create a user

At the very beginning you should create a user and assign the appropriate rights. This can be done in the Magento admin panel at:

System Web Services SOAP/XML-RPC Users

In the next step click Add New User. When creating a new user, you must fill in all the fields. Please note that the API Key and API Key Confirmation is later your password used when connecting to the API.

You can assign the new user to a desired set of rights in User Roles. This can be done and later edited as follows:

System Web Services SOAP/XML-RPC Roles

Does everything work?

Once you have already created a user, you can write a simple PHP script, in order to check whether everything works as it should :

The answer should look as follows:

If you have received the correct answer, we can be sure that the API has been configured properly and is ready to use.

The use of SOAP

Using SOAP to communicate with Magento is extremely simple.

Example 1.

Let’s assume that we need a list of all products of data such as ProductId , Name , Sku , Type. In order to obtain these data, simply use a method catalog_product.list.

$result contains all the information that we want to receive in an array.

Example 2.

Let’s assume that we want to create a new category and assign it to an existing, which has CategoryID=10

Where are the methods and examples of SOAP available?

All the methods and simple examples of their use, can be found on Magento website . Page is still being developed, so it seems to be a good idea to visit once in a while and pbserve the news and changes.

Extension of functionality

Sometimes the default methods turn out to be insufficient. In such a situation, it is possible to extend API magento and add own methods that will perform codes that we provide.

First of all, a new module has to be added. The Creativestyle_Newapi module has been used for the purpose of this article.

Create a new model called Api.php in the added module.

ATTENTION ! For SOAP v2, an additional module V2.php is needed.

api.xml file needs to be added to the module’s etc/ catalogue.

ATTENTION! For SOAP v2, we need to create one more file – wsdl.xml, which needs to be put to a module catalogue etc/ .

In case of adding another functions, it is just enough to add information about tchem to the already existing wsdl.xml file. Good luck!