0

this is the first time I use Magento, and I'm trying to make an API, but Im getting some errors. When I try to call a custom SOAP api method, I'm getting this error:

Uncaught SoapFault exception: [Receiver] Unknown error.

Any ideas?

This is my folder structure:

 --->Company

   --->MobileApi

      --->Model
          --->Mobile
              ---->Api
                    ---->V2.php
                   Api.php

      --->etc
              ---->api.xml
              ---->config.xml
              ---->wsdl.xml
              ---->wsi.xml

api.xml

<?xml version="1.0"?>
<config>
  <api>
    <resources>
      <mobileapi_mobile translate="title" module="mobileapi">
        <model>mobileapi/mobile_api</model>
        <title>Mobile Api</title>
        <!--<acl>mobileapi/mobile</acl>-->
        <methods>
          <forgotaccess translate="title" module="mobileapi">
            <title>Forget the access to the Platform</title>
             <method>forgotaccess</method>
          </forgotaccess>
        </methods>
      </mobileapi_mobile>
    </resources>
    <resources_alias>
      <mobile>mobileapi_mobile_mobile</mobile>
    </resources_alias>
    <v2>
      <resources_function_prefix>
         <mobileapiMobile>mobileapiMobile</mobileapiMobile>
      </resources_function_prefix>
    </v2>
  </api>

config.xml

 <?xml version="1.0"?>
<config>
  <modules>
    <Company_MobileApi>
      <version>1.0</version>
    </Company_MobileApi>
  </modules>
  <global>
    <models>
      <company_mobileapi>
        <class>Company_MobileApi_Model</class>
      </company_mobileapi>
    </models>
    <helpers>
      <company_mobileapi>
        <class>Company_MobileApi_Helper</class>
      </company_mobileapi>
    </helpers>
  </global>
</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>
    <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
      <import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />

      <element name="mobileapiMobileForgotaccessRequestParam">
        <complexType>
          <sequence>
            <element minOccurs="1" maxOccurs="1" name="sessionId" type="xsd:string" />
            <element minOccurs="1" maxOccurs="1" name="username" type="xsd:string" />
          </sequence>
        </complexType>
      </element>
      <element name="mobileapiMobileForgotaccessResponseParam">
        <complexType>
          <sequence>
            <element minOccurs="1" maxOccurs="1" name="response" type="xsd:string" />

          </sequence>
        </complexType>
      </element>
    </schema>
  </types>

  <message name="mobileapiMobileForgotaccessRequest">
    <part name="parameters" element="typens:mobileapiMobileForgotaccessRequestParam" />
  </message>
  <message name="mobileapiMobileForgotaccessResponse">
    <wsdl:part name="parameters" element="typens:mobileapiMobileForgotaccessResponseParam" />
  </message>
  <portType name="{{var wsdl.handler}}PortType">
    <operation name="mobileapiMobileForgotaccess">
      <documentation>Forgot the access</documentation>
      <input message="typens:mobileapiMobileForgotaccessRequest" />
      <output message="typens:mobileapiMobileForgotaccessResponse" />
    </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="mobileapiMobileForgotaccess">
      <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>

wsi.xml

<?xml version="1.0" encoding="UTF-8"?>
<wsdl: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/"
             name="{{var wsdl.name}}"
             targetNamespace="urn:{{var wsdl.name}}">
    <wsdl:types>
        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:{{var wsdl.name}}">

            <xsd:element name="mobileapiMobileForgotaccessRequestParam">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element minOccurs="1" maxOccurs="1" name="sessionId" type="xsd:string" />
                        <xsd:element minOccurs="1" maxOccurs="1" name="username" type="xsd:string" />
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="mobileapiMobileForgotaccessResponseParam">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element minOccurs="1" maxOccurs="1" name="response" type="xsd:string" />

                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
          <!--<xsd:complexType name="mobileapiMobileForgotaccessRequestParam">-->

        </xsd:schema>
    </wsdl:types>

    <wsdl:message name="mobileapiMobileForgotaccessRequest">
        <wsdl:part name="parameters" element="typens:mobileapiMobileForgotaccessRequestParam" />
    </wsdl:message>
    <wsdl:message name="mobileapiMobileForgotaccessResponse">
        <wsdl:part name="parameters" element="typens:mobileapiMobileForgotaccessResponseParam" />
    </wsdl:message>

    <wsdl:portType name="{{var wsdl.handler}}PortType">

         <wsdl:operation name="mobileapiMobileForgotaccess">
            <wsdl:documentation>Forgot the access</wsdl:documentation>
            <wsdl:input message="typens:mobileapiMobileForgotaccessRequest" />
            <wsdl:output message="typens:mobileapiMobileForgotaccessResponse" />
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
      <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />

    <wsdl:operation name="mobileapiMobileForgotaccess">
      <soap:operation soapAction="urn:{{var wsdl.handler}}Action" />
      <wsdl:input>
        <soap:body  use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body  use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
   <wsdl:service name="{{var wsdl.name}}Service">
    <wsdl:port name="{{var wsdl.handler}}Port" binding="typens:{{var wsdl.handler}}Binding">
      <soap:address location="{{var wsdl.url}}" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

V2.php

class Company_MobileApi_Model_Mobile_Api_V2 extends Company_MobileApi_Model_Mobile_Api {

public function forgotaccess($sessionId,$username){

    echo 'hey this is the username'.$username.'and the sessionId:'.$sessionId;

}

}

Api.xml

class Company_MobileApi_Model_Mobile_Api extends Mage_Api_Model_Resource_Abstract {

public function forgotaccess($sessionId, $username)
{

    echo 'hey this is the username'.$username.'and the sessionId:'.$sessionId;

} }

This is how I'm calling the api method

error_reporting(E_ALL);
ini_set('display_errors', TRUE);
$api_url = "http://localhost/index.php/api/v2_soap/?wsdl=1"; 

$username = '******';
$password = '******';

$client = new SoapClient($api_url,array('cache_wsdl' => WSDL_CACHE_NONE));

//var_dump($client->__getFunctions());
//retreive session id from login
$session = $client->login(array("username"=>$username,"apiKey"=>$password));
$session= $session->result;


$result = $client->mobileapiMobileForgotaccess(array("sessionId"=>$session,"username"=>"test@test.com")); 

btw, I have the WS-I enable and I'm seeing the mobileapiMobileForgotaccess method in the function list.

0

Try to check the log error files right after you send a request; then update your question with the content of the log

<magento dir>/var/log/exception.log
<magento dir>/var/log/system.log
0

this unknown error is due V2.php file not found in your module

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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