Chat with us, powered by LiveChat

This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

A Guide to Implement Custom API In Magento Backend

March 21, 2016

3 Min Read
Reading Time: 3 minutes

In the previous part of this Custom API development series, we created our custom module to implement custom API and we created files for plugin as well, which are required by the custom APIs provided by our module.

Custom API Magento Backend

In this second and last part will look at the backend section of Magento to show how to expand the custom APIs.

Setting up API User and API Role From the Magento BackEnd  

Now we are setting up API User and API Role in Magento’s Backend.  For the setup of API Role go to System > Web Services > (SOAP/XML­RPC) Roles and Click on “Add New Role” button for creating a new role.


Under the “Role Info” tab it will ask for “Role Name” and “Current Admin Password”. I used “Cloudways SOAP Role” in the Role Name field and clicked on the “Save Role” button. After saving your role go to “Role Resources” tab. Under Role Resources, you’ll see different resources with check boxes. Click on the Core > Store > List of stores check box. It means that “Cloudways SOAP Role” can only access “List of stores” resources APIs.

Note: I selected Stores > List of Stores Under “Resources” for demonstration purpose. You can choose a module of your own choice.


Click on the Save Role button for save the role information.

Now set up API User for assigning your API role. Setup of API User “Cloudways SOAP Role” to the new user which we are going to create. For Setup of API User go to System > Web Services > (SOAP/XML­RPC) Users. Click on the “Add New User” button for creating a new user. Under the “User Info” tab fill the information those required for creating a new user.


Click on the “Save User” button. Under “User Role” tab select the “Cloudways SOAP Role” radio button.


Click on the Save User and that’s it. We set up the Role and User for accessing the Magento API.

Consume the API in Magento

In this part, I show you how to call Magento APIs. Under your Document root directory, create a consume.php file and use the code below:

// v2 call
$client = new SoapClient('');
$session = $client-­>login('soapuser', 'soapuser');
$result = $client-­>cwcustomapimodule($session);
echo '<pre>';

Change to your Magento store URL. Magento supports two versions of the APIs. v1 and v2. In this article, I show Magento v2 API method.

In this API mode first,  I create new instance “SoapClient” class. Next, I call “Login” method for login to Magento store (We will need to provide “Username” and “Password” of the API User) which we created in the earlier section. Here we are all done.

Final Thoughts

This sums up the custom API development series. I hope after following this series you feel comfortable with the Magento APIs and you learned how to create your own Magento custom APIs as per your requirements. I would love to hear your comments about the tutorials and how you implemented your custom API.

If you’d like to practice what we’ve learned in this custom API series, you can sign up for your free trial of the Cloudways Managed Cloud Platform. Thanks to the Cloudways hosting stack, you get optimized and ultra fast Managed Magento Hosting for your web store, increasing your sales and improving your search engine rankings.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Boost Your Magento Store Performance by 5x Times & Maximize Your Sales

Our fastest Magento hosting can help you in growing your business revenue by 500%


Cloudways is a European MSP that provides custom cloud design, deployment and management solutions on leading cloud providers.

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

BFCM 2019