How to setup custom api for Magento with SOAP V2?

How to setup custom api for Magento with SOAP V2?

August 2, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to setup custom api for Magento with SOAP V2?

Setting Up Custom API for Magento with SOAP V2

In this post, we’ll guide you through setting up a custom function in your Magento API using SOAP v2, which is necessary if you’re working with C# code that needs to utilize the API.

Overview of Your Current Setup

First, let’s briefly review the files and setup you’ve provided:

  1. ABT_Test.xml: This file enables your custom module.
<config>
    <modules>
        <ABT_Test>
            <active>true</active>
            <codePool>local</codePool>
        </ABT_Test>
    </modules>
</config>
  1. Config.xml: This file defines the active state and code pool of your module, as well as the models it uses.
<config>
    <modules>
        <ABT_Test>
            <active>true</active>
            <codePool>local</codePool>
            <version>1.0</version>
        </ABT_Test>
    </modules>
    <global>
        <models>
            <test>
                <class>ABT_Test_Model</class>
            </test>
        </models>
    </global>
</config>
  1. Api.xml: This file defines the API resources and methods for your module.
<config>
    <api>
        <!-- ... rest of the file -->
    </api>
</config>
  1. Wsdl.xml: This file defines the WSDL interface for your custom method ‘foo’.

  2. API.php and API/V2.php: These files contain the actual API logic.

  3. Test_API.php: This is your test script that uses both SOAP v1 and v2 to call your custom function.

Understanding the Issue

The primary issue lies in how Magento handles the mapping of SOAP v2 methods. When you define a method in api.xml, Magento expects it to be defined in both API.php (for v1) and API/V2.php (for v2).

However, in your case, while you’ve correctly defined the foo method in API.php, it’s not present in API/V2.php. This mismatch causes the “Procedure ‘testFoo’ not present” error when calling SOAP v2.

The Solution: Defining the Method for Both V1 and V2

To resolve this issue, you need to define your custom function in both API.php and API/V2.php:

API.php:

class ABT_Test_Model_Api extends Mage_Api_Model_Resource_Abstract
{
    public function foo()
    {
        return true;
    }
}

API/V2.php:

class ABT_Test_Model_Api_V2 extends ABT_Test_Model_Api
{
}

In API/V2.php, you don’t need to redefine the method; simply extending from API.php is enough. This ensures that the method exists in both v1 and v2 API contexts.

Conclusion

Setting up a custom function in Magento’s SOAP v2 requires careful attention to the mapping between your XML definitions and your PHP code. By defining your methods correctly across both v1 and v2 files, you can ensure compatibility with different versions of the API.

Remember, when working with Magento APIs, it’s important to keep your configurations and code consistent and well-documented. If you’re looking for more advanced solutions or need help setting up complex integrations, consider reaching out to professional developers at Laravel Company.

Happy coding!

API Extensions Configuration

Our network