Ever wonder why Magento doesn’t stink? Well, it’s because they use SOAP! Ok, I know I should lay off the jokes but I couldn’t resist this one. So, for those of you that don’t really understand what the Magento SOAP API is all about, it’s basically a way to retrieve information from your store via an application.
You can retrieve a lot of information using this API and you can even perform actions. The API gives you access to the catalog, products, customers and more.
This is really great if you’re building an offline app that needs to create, modify or retrieve this data and store it locally.
In the video below, I show you how I created a simple PHP script to retrieve the category tree using SOAP V2. Setting up the SOAP client is easy and if you know how to code in PHP, you can get an APP up and running in minutes.
Can’t view the video? Watch it on YouTube
I actually created this list of country codes using the Magento SOAP API and it took me about 15 minutes.
So to start, you will need to make sure that you have SOAP installed. If you are on a shared hosting account, you might already have SOAP installed. If you don’t, you can always contact the host and ask if they would be willing to install it for you.
If you are on a VPS or dedicated server, you can install SOAP yourself, but this depends on how your server is setup. In my case, I had WHM cPanel installed on my server so I was able to use EasyApache to install it.
You can test whether SOAP is installed by creating a PHP file with the following code in it:
Then simply open that file in your browser and look for the SOAP section and make sure that it’s enabled.
So once your server is ready for the API, you will need to create a PHP file with the SOAP client class. In the video, I used this example from the Magento site.
Simply replace ‘magentohost’ with your domain and replace ‘apiUser’ and ‘apiKey’ with the credentials that you will create in your admin panel.
To create an API user, you will first need to create a role; roles assign privileges to your user. To create a role, simply go to “System > Web Services > SOAP/XML-RPC – Roles”.
Then create the role by clicking the “Add New Role” button.
On the role creation page, you will be asked to enter a role name which can be anything that you’d like. It will also ask you to assign permissions to that name. The permissions that you assign depends on what the app needs to do. Once you’ve assigned the permissions, simply click on the “Save Role” button.
Now that we’ve setup our role, we can create a user and assign the role to that user.
To create a user, simply go to “System > Web Services > SOAP/XML-RPC – Users”.
Then click the “Add New User” button and fill out the form. Note that the user name that you enter on this form, will be the user name that you enter for ‘apiUser’ and the API key that you enter will be used for ‘apiKey’. Note that this key can be anything that you’d like it to be; think of it as a password.
After you’ve filled out this form, simply click the “Save User” button.
If you ever need to disable a user, simply change the user’s status from “Active” to “Inactive” using the dropdown menu.