Follow by Email

Friday, May 8, 2015

How to create your custom API in Magento

Creating Custom API is very easy in Magento.
Just create api.xml file in your etc folder

<?xml version="1.0"?>
<config>
    <api>
        <resources>          
            <!-- START GUSTOMER GROUP RESOURCES -->
          <mycustom_productupload translate="title" module="package_module">
                <model>package_module/productupload_api</model>
                <title> My API</title>
                <acl>custom_data</acl>
                <methods>
                    <list translate="title" module="package_module">
                        <title>custom product upload</title>
                        <method>bulkuploadproduct</method>
                    </list>
                </methods>
            </mycustom_productupload>
            <!-- END CUSTOMER GROUP RESOURCES -->
        </resources>
         
       
       
        <acl>
            <resources>
                <custom_data translate="title" module="package_module">
                    <title>Custom data</title>
                    <sort_order>3</sort_order>
                </custom_data>
            </resources>
        </acl>
    </api>
</config>

Now create a folder under model Productupload because you have define it under the model tag
and create a file api.php under Productupload. (Productupload /api.php)

api.php

class Package_Module_Model_Productupload_Api extends Mage_Customer_Model_Group_Api
{
   
    public function bulkuploadproduct($productListArr){
       your code....
    }

}


this bulkuploadproduct is the function which will automatically call when when you call the api.
Please find the following example to call this API.

$client = new SoapClient(SOAP_WSDL);
$session = $client->login(SOAP_USER, SOAP_PASS);
$client->call($session, 'mycustom_productupload.list',array($productList));

No comments:

Post a Comment