Enable Magento SOAP api from backend to enable client application to connect with Magento Store.
If you wanted to connect to Magento store from any external application, then you need to enable SOAP api interface from backend and create a user and role based on your requirement. Basically enable Enable Magento SOAP api from backend to enable client application to connect with Magento Store.
Below are steps which need to be followed.
Login to Magento back end with admin credentials
Go to System->Webservices->SOAP/XML RPC Roles
Click on Add new Role
Provide role name
Click on Role Resources
If you wanted a role to be created who has access to all the resources then Select All and Save role
For customized role and its permission select Custom from dropdown and select the API modules/methods to which you wanted this particular role to have access to. This might help you in creating different role for different client applications.
Click on Save and confirm roles is added on role list page.
Now let us go and create a new User.
Go to System->Webservies->SOAP/XML RPC users
Click on Add new user
Provide below information
User name | This would be the user name which will be used by client application to connect and retrieve session id. |
First Name | First Name of User |
Last Name | Last name of user |
Email address of user | |
API Key/API Key Confirmation | This is important and secret key which client application will use/pass while retrieving session id. This has to be secret and cannot be shared with unknown sources. |
Account Status | Active |
Click on user Role on left side
Select the role which we created above
Click Save and you are done
Now you can go ahead and connect to Magento SOAP api from client application
Below is sample php code to connect to Magento SOAP api and retrieve session id and get list of products for any particular category. Code is for demonstration purpose only.
Magento_Soap_User1 Click on user Role on left side Select the role which we created above Magento_Soap_User2 Click Save and you are done Now you can go ahead and connect to Magento SOAP api from client application Below is sample php code to connect to Magento SOAP api and retrieve session id and get list of products for any particular category. Code is for demonstration purpose only. <?php try { define("SOAP_WSDL",'https://www.yourdomain.com/api/?wsdl'); define("SOAP_WSDL2",'https://www.youdomain.com/api/v2_soap/?wsdl'); define("SOAP_USER","demo_soap_user"); define("SOAP_PASS","demo_soap_user_key"); if($_GET['ver'] == '2') { $client = new SoapClient(SOAP_WSDL2, array('trace' => 1,'cache_wsdl' => 0)); echo "<br>version 2 <br>"; } else { $client = new SoapClient(SOAP_WSDL,array('trace' => 1,'cache_wsdl' => 0)); echo "<br>version 1 <br>"; } $session = $client->login(SOAP_USER, SOAP_PASS); $result = array(); try { if($_GET['ver'] == '2') { $result = $client->catalogCategoryAssignedProducts($session,'233'); // 233 here is category id and this method will returns us all the product under this category id var_dump ($result); } else { $result= $client->call($session, 'catalog_category.assignedProducts', '233'); // 233 here is category id and this method will returns us all the product under this category id var_dump ($result); } } catch (SoapFault $exception) { echo 'EXCEPTION='.$exception; } echo "<br>end test<br>"; } catch (Exception $e) { echo var_dump($e); throw $e; } ?>
Hope this help….Happy Coding!!!!