title: Magento API: Publish a new method in soap V2
body: <p>I'm new in Magento and I'd like to create a my own API v2 method.
  I've built a simple project...<br></p>
  
  <pre><code>Mycompany
      Mymodule
          etc
              api.xml
              config.xml
              wsdl.xml
          Model
              Api
                  V2.php
              Api.php
  </code></pre>
  
  <p><br>
  These are the main files...
  <strong><br>(1) api.xml<br></strong></p>
  
  
  
  <pre><code>&lt;config&gt;
      &lt;api&gt;
          &lt;resources&gt;
              &lt;mymodule translate="title" module="mymodule"&gt;
                  &lt;title&gt;mymodule&lt;/title&gt;
                  &lt;model&gt;mymodule/api&lt;/model&gt;
                  &lt;methods&gt;                    
                      &lt;myapimethod translate="title" module="mymodule"&gt;
                          &lt;title&gt;myapimethod&lt;/title&gt;
                          &lt;acl&gt;mymodule/myapimethod&lt;/acl&gt;
                      &lt;/myapimethod&gt;
                  &lt;/methods&gt;
              &lt;/mymodule&gt;
          &lt;/resources&gt;
          &lt;v2&gt;
              &lt;resources_function_prefix&gt;
                  &lt;mymodule&gt;mymodule&lt;/mymodule&gt;
              &lt;/resources_function_prefix&gt;
          &lt;/v2&gt;
          &lt;acl&gt;
              &lt;resources&gt;
                  &lt;mymodule translate="title" module="mymodule"&gt;
                      &lt;title&gt;Mymodule&lt;/title&gt;
                      &lt;sort_order&gt;2000&lt;/sort_order&gt;                    
                      &lt;myapimethod translate="title" module="mymodule"&gt;
                          &lt;title&gt;myapimethod&lt;/title&gt;
                      &lt;/myapimethod&gt;  
                  &lt;/mymodule&gt;
              &lt;/resources&gt;
          &lt;/acl&gt;
      &lt;/api&gt;
  &lt;/config&gt;
  </code></pre>
  
  <p><strong>(2) wsdl.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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}}"&gt;
      &lt;types&gt;
          &lt;schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento"&gt;
              &lt;import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" /&gt;
          &lt;/schema&gt;
      &lt;/types&gt;
      &lt;message name="myapimethodRequest"&gt;
          &lt;part name="sessionId" type="xsd:string"/&gt;
          &lt;part name="message" type="xsd:string" /&gt;
      &lt;/message&gt;
      &lt;message name="myapimethodResponse"&gt;
          &lt;part name="result" type="xsd:string" /&gt;
      &lt;/message&gt;
      &lt;portType name="{{var wsdl.handler}}PortType"&gt;
          &lt;operation name="myapimethod"&gt;
              &lt;documentation&gt;this is an example of api method...&lt;/documentation&gt;
              &lt;input message="typens:myapimethodRequest" /&gt;
              &lt;output message="typens:myapimethodResponse" /&gt;
          &lt;/operation&gt;
      &lt;/portType&gt;
      &lt;binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType"&gt;
          &lt;soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" /&gt;
          &lt;operation name="myapimethod"&gt;
              &lt;soap:operation soapAction="urn:{{var wsdl.handler}}Action" /&gt;
              &lt;input&gt;
                  &lt;soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /&gt;
              &lt;/input&gt;
              &lt;output&gt;
                  &lt;soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /&gt;
              &lt;/output&gt;
          &lt;/operation&gt;
      &lt;/binding&gt;
      &lt;service name="{{var wsdl.name}}Service"&gt;
          &lt;port name="{{var wsdl.handler}}Port" binding="typens:{{var wsdl.handler}}Binding"&gt;
              &lt;soap:address location="{{var wsdl.url}}" /&gt;
          &lt;/port&gt;
      &lt;/service&gt;
  &lt;/definitions&gt;
  </code></pre>
  
  <p><strong>(3) Api.php</strong></p>
  
  <pre><code>&lt;?php
  class Mycompany_Mymodule_Model_Api extends Mage_Api_Model_Resource_Abstract
  {        
          public function myapimethod($sessionId, $message)
          {
              return "This is the message : ".$message;
          }
  }
  </code></pre>
  
  <p><strong>(4) V2.php</strong></p>
  
  <pre><code>&lt;?php
  class Mycompany_Mymodule_Model_Api_V2 extends Mycompany_Mymodule_Model_Api
  {        
  
  }
  </code></pre>
  
  <p><em><strong></em>(5) test.php</strong></p>
  
  <pre><code>&lt;?php
  try {
      define("SOAP_WSDL",'http://localhost:8080/magento/index.php/api/?wsdl');
      define("SOAP_WSDL2",'http://localhost:8080/magento/index.php/api/v2_soap?wsdl=1');
      define("SOAP_USER","dtsSoapUser");
      define("SOAP_PASS","casares");
  
      if($_GET['ver'] == '2') {
          $client = new SoapClient(SOAP_WSDL2, array('trace' =&gt; 1,'cache_wsdl' =&gt; 0));
          echo "&lt;br&gt;version 2 &lt;br&gt;";
      }
      else {
          $client = new SoapClient(SOAP_WSDL,array('trace' =&gt; 1,'cache_wsdl' =&gt; 0));
  
          echo "&lt;br&gt;version 1 &lt;br&gt;";
      }
      $session = $client-&gt;login(SOAP_USER, SOAP_PASS);
      $result = array();
  
      try {
          if($_GET['ver'] == '2') {
               $result = $client-&gt;Myapimethod($session, "My message....");
               var_dump ( $result);        
          } else {            
              $result= $client-&gt;call($session, 'mymodule.myapimethod', array($session, "My message ...."));
              var_dump($result);
          }
      } catch (SoapFault $exception) {
          echo 'EXCEPTION='.$exception;
      }
  
      echo "&lt;br&gt;end test&lt;br&gt;";
  } catch (Exception $e){
      echo var_dump($e);
      throw $e;
  }   
  ?&gt;
  </code></pre>
  
  <p><strong>Using the following Url, the result is:</strong></p>
  
  <blockquote>
    <p>.../test.php/?ver=1</p>
  </blockquote>
  
  <pre><code>version 1
  string 'This is the message : My message ....' (length=37)
  end test
  </code></pre>
  
  <p>It's to say: using Soap v1, the method works!.</p>
  
  <p>But if I use the soap v2 call...</p>
  
  <blockquote>
    <p>.../test.php/?ver=2
    the result is:</p>
  </blockquote>
  
  <pre><code>version 2
  EXCEPTION=SoapFault exception: [3] Invalid api path. in C:\wamp\www\PruebasPHP\test.php:22 Stack trace: #0 C:\wamp\www\PruebasPHP\test.php(22): SoapClient-&gt;__call('Myapimethod', Array) #1 C:\wamp\www\PruebasPHP\test.php(22): SoapClient-&gt;Myapimethod('b9e1e8d15a61398...', 'My message....') #2 {main}
  end test
  </code></pre>
  
  <p><br>The role has access to all the api resources...<br></p>
  
  <p>I don't know what is wrong? can anyone help me with this problem? 
  Can be anything related to acl's?
  Thanks in advance!!!</p>