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.
</code> <?php $wsdl_url="http://magentohost/api/v2_soap?wsdl=1"; // 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--'); $arguement=array( 'name' => 'New Category2', 'is_active' => 1, 'include_in_menu'=>2, 'available_sort_by' => array('name', 'price'), 'default_sort_by' => 'name' ); try{ $result = $client->catalogCategoryCreate($sessionId,3, $arguement,'default'); echo "Category Created"; } catch(Exception $e) { echo "getting error=>".$e->getMessage(); } <code>
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.
Chandra Shekhar
Latest posts by Chandra Shekhar (see all)
- Best practices for micro service design - January 23, 2022
- Spring Boot - January 23, 2022
- Java - January 23, 2022
Recent Comments