Back to Top

Add Own API Function In Magento

Updated 29 February 2024

API function are those functions which call from another server…

We know Magento provide more API  functions here we learn how to make own API functions in magento module..

For this, you just need to add some code in your module’s YourModule/etc/api.xml file and add a new API functions YourModule/Model/Api.php

Here’s the code:-

api.xml

Searching for an experienced
Magento Company ?
Find out More
<config>
	<api>
		<resources>
			<yourmodule translate="title" module="yourmodule">
			<model>yourmodule/api</model>
			<title>Customer Resource</title>
			<acl>yourmodule</acl>
				<methods>
					<yourfunction1 translate="title" module="yourmodule"> <!-- this tag name by which you call your method-->
						<title>title which you want</title>
						<method>yourfunction1</method>
						<acl>yourmodule/yourfunction1</acl>
					</yourfunction1>
					<yourfunction2 translate="title" module="yourmodule">
						<title>title which you want</title>
						<method>yourfunction2</method>
						<acl>yourmodule/yourfunction2</acl>
					</yourfunction2>					
					<yourfunction3 translate="title" module="yourmodule">
						<title>title which you want</title>
						<method>yourfunction3</method>
						<acl>yourmodule/yourfunction3</acl>
					</yourfunction3>
					<yourfunction4 translate="title" module="yourmodule">
						<title>title which you want</title>
						<method>yourfunction4</method>
						<acl>yourmodule/yourfunction4</acl>
					</yourfunction4>
				</methods>
			</yourmodule>
		</resources>
	</api>
</config>

Api.php

<?php
  class Yourcompany_Yourmodule_Model_Api extends Mage_Api_Model_Resource_Abstract
    {

        public function yourfunction1($data){
			//in $data you get the values which you pass in API function
			//do code according to your requirement
			return true;
        }

       public function yourfunction2($data){
			//in $data you get the values which you pass in API function
			//do code according to your requirement
			return $data['erp_category_id'];
        }

        public function yourfunction3($data){
			//in $data you get the values which you pass in API function
			//do code according to your requirement
			return true;
        }

        public function yourfunction4($data){
			//in $data you get the values which you pass in API function
			//do code according to your requirement
			return true;
        }
    }
?>

Now you call these function using

1. yourmodule.yourfunction1($data);

2. yourmodule.yourfunction2($data);

3.yourmodule.yourfunction3($data);

4.yourmodule.yourfunction4($data);

Note:- for call these functions first you connect your server with magento using any protocol like XML-RPC

 XML-RPC is the simplest XML-based protocol for exchanging information between computers.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home