2

I created a custom method to the Magento SOAP API and it worked well so far. Now I want to create the same method to the Magento SOAP API V2.

I created the WSDL.xml and the V2.php Class files (below), and when I try call my method in V2 API, I got this error:

Uncaught SoapFault exception: [Client] Function ("pacoteCreatelink") is not a valid method for this service in [...]

Although the error be clear, it seems to me that my new method in soap v2 is not being recognized. I must pass something. Any Ideas?

Files:

Company
    Bundleapi
        etc
            config.xml
            api.xml
            wsdl.xml
        Model
            Pacote
                Api
                    V2.php
                Api.php

V2.php:

<?php
class Company_Bundleapi_Model_Pacote_Api_V2 extends Company_Bundleapi_Model_Pacote_Api
{
    public function createlink($message)
    {
        return $message;
    }
}

api.xml:

<?xml version="1.0"?>
<config>
    <api>
        <resources>
            <bundle_link translate="title" module="company_bundleapi">
                <title>Create Bundle link</title>
                <model>bundleapi/pacote_api</model>
                <methods>
                    <createlink translate="title" module="company_bundleapi">
                        <title>Create link Options Bundle</title>
                    </createlink>
                    <cleanlink translate="title" module="company_bundleapi">
                        <title>Clean link beetwen Bundle and Simple Products</title>
                    </cleanlink>
                </methods>
            </bundle_link>
        </resources>
        <resources_alias>
            <pacote>bundle_link_pacote</pacote>
        </resources_alias>
        <v2>
            <resources_function_prefix>
                <bundle_link>pacote</bundle_link>
            </resources_function_prefix>
        </v2>
    </api>
</config>

wsdl.xml:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:typens="urn:{{var wsdl.name}}" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
         xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
         xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
         xmlns="http://schemas.xmlsoap.org/wsdl/"
         name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}">
<types>
</types>
<message name="pacoteCreatelinkRequest">
    <part name="sessionId" type="xsd:string"/>
    <part name="message" type="xsd:string" />
</message>
<message name="pacoteCreatelinkResponse">
    <part name="result" type="xsd:string" />
</message>
<portType name="{{var wsdl.handler}}PortType">
    <operation name="pacoteCreatelink">
        <documentation>Create Link to Bundle Products</documentation>
        <input message="typens:pacoteCreatelinkRequest" />
        <output message="typens:pacoteCreatelinkResponse" />
    </operation>
</portType>
<binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
    <operation name="pacoteCreatelink">
        <soap:operation soapAction="urn:{{var wsdl.handler}}Action" />
        <input>
            <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
        </input>
        <output>
            <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
        </output>
    </operation>
</binding>
<service name="{{var wsdl.name}}Service">
    <port name="{{var wsdl.handler}}Port" binding="typens:{{var wsdl.handler}}Binding">
        <soap:address location="{{var wsdl.url}}" />
    </port>
</service>
</definitions>

config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Company_Bundleapi>
            <version>0.1.0</version>
        </Company_Bundleapi>
    </modules>
    <global>
        <models>
            <bundleapi>
                <class>Company_Bundleapi_Model</class>
            </bundleapi>
        </models>
    </global>
</config>

I have checked this and this before.

8
  • 1
    you need a tag v2 in api.xml. It is explained in the first link you said you tried.
    – Marius
    Commented Sep 8, 2014 at 8:01
  • I edited my api.xml with tag v2, but it's still not working. I edited question too. Thanks Commented Sep 8, 2014 at 8:17
  • 1
    I see nothing wrong at a first glance. I think a good place to start debugging is Mage_Api_Model_Server_V2_Handler::__call. See how the $apiKey variable looks like before calling the actual method. If it looks ok to you you can continue the debuggin g process in Mage_Api_Model_Server_Handler_Abstract::call
    – Marius
    Commented Sep 8, 2014 at 8:34
  • At a second look I see that you are also missing the resources_alias tag in api.xml.
    – Marius
    Commented Sep 8, 2014 at 8:35
  • I created resources_alias tag. I used the name of resource and de Model's name, looks like your code in your question. But still did not work. I'm starting to debug hot to you said. Thanks for your help. Commented Sep 8, 2014 at 14:53

2 Answers 2

5

How did you connect through api? If the value looks like http://example.com/api/soap?wsdl then you are still making a call to V1. Update it to look like this http://example.com/api/v2_soap/?wsdl

Also, please, do not forget to refresh system cache.

If you wish to prevent future caching, use:

ini_set("soap.wsdl_cache_enabled", 0);

or dynamically:

$client = new SoapClient('http://somewhere.com/?wsdl', array('cache_wsdl' => WSDL_CACHE_NONE) );
1
  • I'm already using ini_set("soap.wsdl_cache_enabled", 0). In API V1 the call is: $result = $client->call($session, 'bundle_link.createlink');. These resources_alias tag in api.xml are leaving me confused. It seems that the error happens before, but my WSDL seems to be correct. Thanks for your help Commented Sep 9, 2014 at 3:11
1

The problem resources_function_prefix tag, in api.xml. This is responsible for specifying the prefix of the call in the format v2 for resource API v1. I was using it incorrectly.

My currently api.xml:

<?xml version="1.0"?>
<config>
<api>
    <resources>
        <blink translate="title" module="company_bundleapi">
        <title>Create Bundle link</title>
        <model>bundleapi/pacote_api</model>
        <methods>
            <createlink translate="title" module="company_bundleapi">
                <title>Create link Options Bundle</title>
            </createlink>
            <cleanlink translate="title" module="company_bundleapi">
                <title>Clean link beetwen Bundle and Simple Products</title>
            </cleanlink>
        </methods>
        </blink>
    </resources>
    <v2>
        <resources_function_prefix>
            <blink>blinkBlink</blink>
        </resources_function_prefix>
    </v2>
</api>
</config>

Call in API V2: $result = $client->blinkBlinkCreatelink($session,'string');

For more infos: http://alanstorm.com/magento_soap_v2_adapter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.