Setting up Web Service or SOAP with magento

Before moving ahead and demonstrate “How to make use of Web Service/ SOAP of Magento”. If you wanted to have a quick introduction about “Web Service and their implementation with SOAP” then you can simply click here  Web Service and their implementation with SOAP

Create a web service Role in Magento:

Step 1: Login to admin section

Step 2: Navigate to System -> Web Services -> SOAP/XML-RPC Roles

Step 3: Click on “Add New Role”.

Step 4: Under “Role Info” Tab left side enter the Role Name like “API Role” . This role name is used to identify what role name the user has assigned.

Under “Role Resources” tab: You will see a list of all available resources. You need to select those checkbox (each checkbox represent a resource) that you want to allow for that Role.

Step 5: Click on “Save Role” button showing on top right side.

Create a Web Service User in Magento:

Step 1: Login to admin section

Step 2: Navigate to System -> Web Services -> SOAP/XML-RPC Users.

Step 3: Click on “Add New User”  button showing on top Right section.

Step 4: Under “User Info” tab please enter all required details for creating user.  The most important thing on this form is “Username” and “API Key”. Because these are the two details that are used to authenticate user while making call of SOAP functions through code. Make sure your account is active.

Step 5: Under “User Role” tab select the role that you have created just above like “API Role”.

Step 6: Click on “Save User” button showing on top right side.

Magento SOAP client WSDL Url:

Magento support 3 types of wsdl url

*. http://magentohost/api/?wsdl

*. http://magentohost/api/soap/?wsdl

*. http://magentohost/api/v2_soap?wsdl=1

The last url of Magento wsdl (http://magentohost/api/v2_soap?wsdl=1) has made significant improvements over upper 2 URL for .NET and JAVA based applications. As this URL expose function names their input and output parameters in much user as well as system friendly.



Write a SOAP Client to test Magento SOAP Call.

The purpose of this SOAP call is to Create Category on Magento Store using SOAP call. So below php code for Creating Category on Magento Store using SOAP call.




// int catalogCategoryCreate(string $sessionId, int $parentId, catalogCategoryEntityCreate $categoryData, string $storeView);


/*If you are using Proxy server then use below details. Otherwise No need to create this array and pass it.*/

$params =  array(

'trace' => 1,

'exceptions' => true,

'cache_wsdl' => WSDL_CACHE_NONE,

'proxy_host' => "—HOST--",

'proxy_port' => --PORT--,

'proxy_login' =>”—USERNAME--”,

'proxy_password' =>”—PROXY PASSWORD--”,


$client = new SoapClient($wsdl_url,$params);

// You can see the list of functions available on that wsdl url.  By uncommenting below lines.


$fcs = $client->__getFunctions();

echo “<pre>”print_r($fcs).echo “</pre>”;




$sessionId = $client->login('—WEB SERVICE USERNAME--','—WEB SERVICE API KEY--');


'name' => 'New Category2',

'is_active' => 1,


'available_sort_by' => array('name', 'price'),

'default_sort_by' => 'name'



$result = $client->catalogCategoryCreate($sessionId,3, $arguement,'default');

echo "Category Created";


catch(Exception $e)


echo "getting error=>".$e->getMessage();



Note: You need to use $param only if you are using proxy server to access internet otherwise no need to use $param with your code.

Related posts:

The following two tabs change content below.

Chandra Shekhar

GCP Architect
Chandra Shekhar Pandey is Google certified Cloud engineer, I am Magento2 Trained developer. Having huge experience in designing cloud solution. I have around 12 years of experience with world enterprise IT companies and fortune 500 clients. During my architecture design I am always caring about high availability, fast performance and resilient system. From the programmer background I have huge experience in LAMP stack as well. Throughout my carrier I have worked on Retail, E-Learning, Video... Read More about Chandra Shekhar

Latest posts by Chandra Shekhar (see all)