Magento API Steps to Create Web Service in Magento V2
Magento API Steps to create web service in Magento V2 - Tutsplanet
Creating the web services in Magento API V2, was a headache for me couple of days. It was a requirement for creating a custom API in magento 1.9
I have spent most of the time googling and going through the Magento’s source code very deeper. It was hard days for me really it was.
Finally, I could figure out the Magento API V2, how to create new method calling some foo function and it’s giving the results as per our requirement. Below I have elaborated the steps I have done to create a method. And you can download my test module by clicking here for installing in your Magento whatsoever. I have tested this in version 1.7.0.2
I am not going to explain the usual Magento things like creating a module, etc, this article is just based on the API related thing.
Step 1: First of all I am starting with config.xml, its a normal configuration that you all are familiar with already.


Here you can see I just got my helper and model declared as a part of Magento module.
Step 2: We are going to go deeper inside to API XML file, that is core of Magento API. In my attachment, I have added a skeleton file which is showing directory and naming conventions of api.xml . I believe you will get more ideas about from that xml file.
Below is my api.xml

Main points inside this api.xml

<resources_function_prefix> will work as prefix for API V2 function like productsGetList.
Acl thing to decide the user roles for the API functions in a way.
Defining your methods

Step 3: Adding your wsdl.xml file, still its mystery for me, I am not going to more deep into that ????

Step 4: Next is our model classes, We have created in a folder named Products , all api models will remain inside the above folder.
app/code/local/Writeyourcode/Learnnews/Model/Products/Api.php

app/code/local/Writeyourcode/Learnnews/Model/Products/Api/V2.php


We have created two functions to call the active products and inactive products. In fact, its getting neither active product nor inactive products, a function just wrote for demonstration. Yo know already how to deal with Magento models. Here is the websiteId is the website Id that I need to filter with, in your case you an avoid this.


I have added a testcall.php inside the zip for consuming API .Have a nice day.
Download

    Did this post help you?
    Tutsplanet brings in-depth and easy tutorials to understand even for beginners. This takes a considerable amount of work. If this post helps you, please consider supporting us as a token of appreciation:
    
    
    
    Just want to thank us? Buy us a Coffee
    May be another day? Shop on Amazon using our links.  Your prices won't change but we get a small commission. 
    
    
    
    
        
        Reader Interactions	
	