How to use Magento SOAP API
In this tutorial I show you how to use Magento SOAP API. For this you should use a software called SoapUI, which helps to test SOAP calls.
How to use Magento SOAP API
All work with your Magento SOAP API starts with a file called WSDL. This is a XML Document with all available calls you can use to get data from the shop. You can find SOAP V2 WSDL with this URL. Please replace www.domain.com with your domain!
1 | http://www.domain.com/index.php/api/v2_soap?wsdl=1 |
In you browser you will get a very long xml file which looks as follows:
Per default Magento has a very large number of useful calls to get a lot of usable data. Modules can extend those calls or create new ones, so that your Magento stores wsdl may looks different.
Working with this xml view of a wsdl is difficult. A nice tool to speed up your development is SoapUI. I show you in detail how to use it and to test if special calls deliver the correct information. First we need to download and install SoapUI. This program is written in Java so it is operation system independent. It runs on Windows, Linux, Mac OSX.
SOAP UI
SoapUI is a very easy to use programm. You can create a new SOAP Project with a single button. There you only need to copy your WSDL Url into the “Initial WSDL” field.
Next this wsdl gets analyzed and all possible actions will be detected. After some seconds you may get a fill list of all actions. Next I show you how to work with SOAP UI and you Magento SOAP interface.
Login
First basic action is login. You can’t do anything with SOAP if you have not session id. The only way to get a valid session id is to run login with correct login parameters. So for this task open login Request 1 as shown in next screenshot. You will get a new window opened with some soap xml code. As you can see, there are two tags that need input:
- username
- apiKey
both tags are pre filled with “?”, which indicates a field to change. If you run this without a change, you will get an “Access denied.” error message in your response window.
You can define valid SOAP API users in your Magento backend. Under System -> Web Services -> SOAP/XML – RPC Users you find a list of all configured users for you API. This list is initially empty, so you need to create a new user. But wait, each user has to be attached to a user role. You can define user roles under System -> Web Services -> SOAP/XML – RPC Roles. As you can see, this list is also initially empty. Before creating a new user we create a default admin role. For Role Resources tab please choose All. If you have more experience you can define users with special access rights for example only for customers, products or orders. For this first example choose all, for all Magento SOAP actions.
Now you can create your first SOAP API user. I created a user with name “testuser” and an apiKey “test123”. Don’t forget do set you created admin role in User Role tab. This is mandatory. If you forget this, you have no rights to access SOAP API functions!
You can now fill out all tags in you SOAP UI Request window and run this request. You should get back a long number of digits and characters. This is you session id. Copy and store it. It is valid for some minutes without activity.
Conclusion
SoapUI is a wonderful tool to work with your Magento SOAP API. In this tutorial I showed you first steps for Magento SOAP API and how to use login to get a valid session id for further requests. I also showed how to create a new API user and role in your Magento backend. In the next article we will use the session id and Magento SOAP API to get more information out of this e-commerce system. I will get orders from Magento SOAP API.
Its not working for Magento 2. How to do it for magento 2?
Yes! There is no SOAP API for Magento 2. Magento 2 uses a new REST interface, all endpoints are documented here: http://devdocs.magento.com/swagger/index_20.html
Thanks for the detailed guide, Here’s another which helped me in V1 and V2, cloudways.com/blog/magento-soap-api