4 October, 2022

How To Create Custom Function Using SOAP API

Custom SOAP API Creation

SOAP stands for Simple Object Access Protocol. It is based on XML mostly via HTTP (POST). Its basic structure is basically Envelope with Header and Body inside.

We need to create api user and role. This can be created from Admin -> System Configuration -> Web Services -> SOAP-XML/RPC User/Role. After doing this you should have “username” and “api_key” with you.

Read: How to Build REST API Using PHP

A Simple Example to List all the products in your magento store using SOAP API Function is as below:

SOAP V1 – Example

$client = new SoapClient('http://magentohost/api/soap/?wsdl');
$session = $client->login('apiUser', 'apiKey');
$result = $client->call($session, 'catalog_product.list');

SOAP V2 – Example

$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl');  // Url will also Varies for V1 and V2
$sessionId = $proxy->login('apiUser', 'apiKey');
$result = $proxy->catalogProductList($sessionId);

Custom Module Creation in SOAP API

Scenario: Create a custom function using SOAP API to update order amount in database (function should call from ERP tool).

Function Name : soapmoduleProjectPayorder
Parameters: Order Id , Amount , Comments
Output : Boolean

Also Read: How to Create a Chart using Google API?

Step 1:

Create a Module with the name Mage_Soapmodule

Step 2:

Create an api.xml file in etc/ folder of the module. api.xml is the main configuration file for your SOAP API.


Project API

Add Order Details

 // payorder is the function name where the bussiness logic defined to update the order details  in database

Requested Order Details does not exist.

Provided data is invalid.

Error while saving project. Details in error message.

Error while removing project. Details in error message.





Update Order Details

Step 3 :

Create the config.xml file in etc folder by specifying the version ,frontname etc..





Step 4 :

Need to create the Wsdl file. When we consider the Soap API we need to declare the parameters in xml format



Seller Payment


Step 5 :

In this Step we need to create the Wsi.xml file in etc/wsi.xml. Here we need to declare the necessary parameters. As mentioned above necessary params to call the function are orderId, amount and comment.



 //Declaring the necessary parameters


Seller Payment

Step 6 :

Create Model for handling the SOAP V1 requests

Create the api model file. In the api.xml file we have mentioned the model to be “soapmodule/project_api” so we need to create the file


public function payorder($orderId,$amount,$comment){
* Storing Transaction details
$transactionDetails = 
array(‘order_id’ => $orderId, ‘amount’=> $amount,’comment’=> $comment);
$saveTransactionDetails = Mage::getModel (testmodel/testmodel' )->setData($transactionDetails);
catch (Mage_Core_Exception $e) {
$this->_fault('save_error', $e->getMessage());
return true;

Step 7 :

create a a new file as v2.php in Api folder


class Mage_Soapmodule_Model_Project_Api_V2 extends Mage_Soapmodule_Model_Project_Api{

Final Step :

In your Magento root folder create soap_api.php file and call the custom Soap API function


$result = $proxy->soapmoduleProjectPayorder($sessionId,'160411747',50,'by cash');
echo '

Creating a custom function using SOAP API will give developers much needed flexibility. This article was created by developers to help fellow developers learn how to create a custom function using SOAP API.

Hope we have made things clear. If there is anything that you wish to know more, feel free to drop in a comment or inbox us.

Alex Sam is a digital marketer by choice & profession. He munches on topics relating to technology, eCommerce, enterprise mobility, Cloud Solutions and Internet of Things. His other interests lies in SEO, Online Reputation Management and Google Analytics. Follow Me Socially: Habr , Dev.to & Viblo .

Leave a Reply

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