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 220.127.116.11
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.
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.