Create your own API |
... api for customer module, that operates with basic customer info (firstname, lastname, email ...).
1. Describe API Resource in api.xml |
Create api.xml in customer module /etc folder with this contents:
We have to implement create, list, info, update and remove methods for customer resource. Lets add it to resources.
Our resource will return some faults, let’s list them in the config:
2. Describe ACL For API Resource |
In order to prevent unathorized access to our custom API we have to define the ACL resources that can be restricted.
We also have to map ACL resources to API resource methods:
3. Creating API Resource Model |
Let’s create Mage_Customer_Model_Api that extends Mage_Api_Model_Resource_Abstract
We cannot create method “list” because it’s a PHP keyword, so we will add the following to api.xml:
And now will add some simple functionality to our resource model.
Create Customer:
Customer Info:
Customers List with filtering.
Customer Update:
Customer Delete:
Creating custom adapter for api |
In order to create custom webservice adapter we should implement Mage_Api_Model_Server_Adapter_Interface
XmlRpc Adapter example:
“setHandler”, “getHandler”, “setController” and “getController” methods have simple implementation that uses Varien_Object getData/setData methods.
“run” an “fault” have native implementation for XmlRpc webservice.
Method “run” defines webservice logic in this adapter for creating XmlRpc server to handle XmlRpc requests.
Method “fault” allows us to send fault exceptions for XmlRpc service while handling request.