4

I'm being driven mad by this wsi.xml file which doesn't seem to be doing what I'm asking of it. I'm creating my own API which does a bunch of things using a product's EAN (a custom attribute).

It works perfectly with a V1 API call, but isn't working for version 2 with or without WS-I compliance on.

My folder structure looks like this:

Namespace
    Eanapi
        etc
            api.xml
            config.xml
            wsdl.xml
            wsi.xml
        Model
            Api
                V2.php
            Api.php

Pretty straight forward.

The api.xml file looks like this:

<?xml version="1.0"?>
<config>
    <api>
        <resources>
            <eanapi translate="title" module="eanapi">
                <model>eanapi/api</model>
                <methods>
                    <specialprice translate="title" module="eanapi">
                        <title>Update Special Price by EAN</title>
                    </specialprice>
                </methods>
                <faults>
                    <data_invalid>
                        <code>100</code>
                        <message>Invaid Data</message>
                    </data_invalid>
                </faults>
            </eanapi>
        </resources>
        <v2>
            <resources_function_prefix>
                <eanapi>eanapi</eanapi>
            </resources_function_prefix>
        </v2>
        <resources_alias>
            <eanapi>eanapi</eanapi>
         </resources_alias>
    </api>
</config>

My wsdl.xml file looks like this:

<?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/" />
        </schema>
    </types>
    <message name="eanapiApiSpecialpriceRequest">
        <part name="sessionId" type="xsd:string"/>
        <part name="message" type="xsd:string" />
    </message>
    <message name="eanapiApiSpecialpriceResponse">
        <part name="result" type="xsd:string" />
    </message>
    <portType name="{{var wsdl.handler}}PortType">
        <operation name="eanapiApiSpecialprice">
            <documentation>Load product by EAN</documentation>
            <input message="typens:eanapiApiSpecialpriceRequest" />
            <output message="typens:eanapiApiSpecialpriceResponse" />
        </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="eanapiApiSpecialprice">
            <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>

And finally the wsi.xml looks like this:

<?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:complexType name="eanapiApiSpecialpriceEntity">
                <xsd:all>
                    <xsd:element name="ean" type="xsd:string" minOccurs="1" />
                </xsd:all>
            </xsd:complexType>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="eanapiApiSpecialpriceRequest">
        <wsdl:part name="parameters" element="typens:eanapiApiSpecialpriceRequestParam" />
    </wsdl:message>
    <wsdl:message name="eanapiApiSpecialpriceResponse">
        <wsdl:part name="parameters" element="typens:eanapiApiSpecialpriceResponseParam" />
    </wsdl:message>
    <wsdl:portType name="{{var wsdl.handler}}PortType">
        <wsdl:operation name="eanapiApiSpecialprice">
            <wsdl:documentation>Get product by Ean</wsdl:documentation>
            <wsdl:input message="typens:eanapiApiSpecialpriceRequest" />
            <wsdl:output message="typens:eanapiApiSpecialpriceResponse" />
        </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="eanapiApiSpecialprice">
            <soap:operation soapAction="" />
            <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>

Edit:

With WSI off I get an error saying: PHP Fatal error: Uncaught SoapFault exception: [3] Invalid api path.

I'm running the query with the following code:

$client = new SoapClient('http://magento.dev/api/v2_soap/?wsdl');
$session_id = $client->login($user, $key);
$result = $client->eanapiApiSpecialprice(
    $session_id, 'test');

var_dump ($result);

With WSI compliance on I get an error saying: PHP Fatal error: Uncaught SoapFault exception: [Receiver] Unknown error in test.php:25

$client = new SoapClient('http://magento.dev/api/v2_soap/?wsdl');
$session = $client->login(array('username' => $user, 'apiKey' => $key));
$sesion_id = $session->result;

$result = $client->eanapiApiSpecialprice(
    (object)array('sessionId' => $sesion_id,
    'ean' => 'test')
);

var_dump ($result);
  • just an educated guess: try adding namespace prefix to children of xsd:schema. – mam08ixo Mar 6 '15 at 11:16
  • thanks for the suggestion @mam08ixo. Can you be a little more specific? – hammygoonan Mar 6 '15 at 11:26
  • How much more specific can it get? In your wsi example, the child elements of xsd:schema (complexType, all, element) are missing the xsd: namespace prefix. As you did not explain what the error actually is (apart from not doing what I'm asking) I can only give that hint and not post an answer, sorry. – mam08ixo Mar 6 '15 at 11:38
  • @mam08ixo, that clarified it perfectly, thanks. Unfortunately I'm still getting the same error: Invalid api path – hammygoonan Mar 6 '15 at 12:00
  • Please update your question to include this error message. It might also be helpful to add the webservice call (code snip) that results in the given error. – mam08ixo Mar 6 '15 at 12:09
0

In most cases "Invalid api path" error means wrong value in < model > section of api.xml file or wrong Api method name using. From your api.xml file:

<v2>
    <resources_function_prefix>
       <eanapi>eanapi</eanapi>
    </resources_function_prefix>
</v2>

so first part of method name is "eanapi"

<methods>
   <specialprice translate="title" module="eanapi">
         <title>Update Special Price by EAN</title>
   </specialprice>
</methods>

second part is "Specialprice". Try to call

$client->eanapiSpecialprice(...); 

instead of

$client->eanapiApiSpecialprice(...);

You also can call

$client->getFunctions();

and receive all available method names for call.

  • Thanks @ToxsBes, unfortunately this post is almost a year old now so I've got no way of testing this any more. Hopefully your comment helps someone else though. – hammygoonan May 13 '16 at 2:57
  • Yep, yesterday I have the same issue and solve it but dont find solution on SO. Thats why I put it here for others who will face in it in future. – ToxaBes May 13 '16 at 12:16
0

I have checked your code and found bug in file api.xml

Replace your code in fie api.xml

From:

<?xml version="1.0"?>
<config>
    <api>
        <resources>
            <eanapi translate="title" module="eanapi">
                <model>eanapi/api</model>
                <methods>
                    <specialprice translate="title" module="eanapi">
                        <title>Update Special Price by EAN</title>
                    </specialprice>
                </methods>
                <faults>
                    <data_invalid>
                        <code>100</code>
                        <message>Invaid Data</message>
                    </data_invalid>
                </faults>
            </eanapi>
        </resources>
        <v2>
            <resources_function_prefix>
                <eanapi>eanapi</eanapi>
            </resources_function_prefix>
        </v2>
        <resources_alias>
            <eanapi>eanapi</eanapi>
         </resources_alias>
    </api>
</config>

To:

<?xml version="1.0"?>
<config>
    <api>
        <resources>
            <eanapi translate="title" module="eanapi">
                <model>eanapi/api</model>
                <title>EAN API</title>
                <acl>eanapi</acl>
                <methods>
                    <specialprice translate="title" module="eanapi">
                        <title>Update Special Price by EAN</title>
                    </specialprice>
                </methods>
                <faults>
                    <data_invalid>
                        <code>100</code>
                        <message>Invaid Data</message>
                    </data_invalid>
                </faults>>
            </eanapi>
        </resources>
        <v2>
            <resources_function_prefix>
                <eanapi>eanapiApi</eanapi>
            </resources_function_prefix>
        </v2>
        <acl>
            <resources>
                <eanapi translate="title" module="eanapi">
                     <title>EAN Api</title>
                     <sort_order>3</sort_order>
                     <specialprice translate="title" module="eanapi">
                        <title>Update Special Price by EAN</title>
                     </specialprice>
                </eanapi>
            </resources>
        </acl>
    </api>
</config>

Note: Flush all cache in admin side & also assigned api roles to api user.

After check your v1 or v2 called.

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.