0

How to create custom api with multiple parameters passed in the api call file in magento1. I have added the code in request call. But it is not working.

Thanks in advance

wsdl.xml file

    <?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/" />
      <complexType name="testPushNotificationCreateArray">
          <complexContent>
              <restriction base="soapenc:Array">
                  <attribute ref="soapenc:arrayType" wsdl:arrayType="typens:testPushNotificationCreate[]"/>
              </restriction>
          </complexContent>
      </complexType>
       <complexType name="testPushNotificationCreate">
        <all>
          <element name="token" type="xsd:string" minOccurs="0"/>
          <element name="customer_group_id" type="xsd:string" minOccurs="0"/>
          <element name="channel" type="xsd:string" minOccurs="0"/>
        </all>
      </complexType>
    </schema>
  </types>
  <message name="dzPushnotifTokenCreateRequest">
    <part name="sessionId" type="xsd:string"/>
    <part name="data" type="typens:testPushNotificationCreate"/>
  </message>
  <message name="dzPushnotifTokenCreateResponse">
 <!--    <part name="result" type="typens:testPushNotificationCreateArray"/> -->
    <part name="result" type="xsd:int"/>
  </message>
  <portType name="{{var wsdl.handler}}PortType">
     <operation name="dzPushnotifTokenCreate">
            <documentation>TEST</documentation>
            <input message="typens:dzPushnotifTokenCreateRequest"/>
            <output message="typens:dzPushnotifTokenCreateResponse"/>
        </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="dzPushnotifTokenCreate">
            <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>
0

The following link is a step by step link to create custom API in Magento1 with sample source code, a bit old though.

https://tutsplanet.com/magento-api-steps-create-web-service-magento-v2/

EDIT

You may check the below code for the input parameters.

<message name="productsapiActiveListRequest">
<part name="sessionId" type="xsd:string"/>
<part name="websiteId" type="xsd:string" />

And you can check the testcall.php included in the zip file given a link at the bottom of the tutorial. The test file shows how to call the params in the API

5
  • Thanks. I have created a custom module and it is working. But not able to pass parameters in the api call. – user78358 Apr 29 '19 at 7:45
  • @user78358 Updated the answer. – Rinto George Apr 29 '19 at 7:50
  • Thanks. Working fine only for single parameter. Not working for multiple parameters. Added the value inside the array. But it takes one value only. Any suggestions please? – user78358 Apr 29 '19 at 10:51
  • Did you happen to change the type while you passing the array as parameter? <part name="websiteId" type="xsd:string" /> – Rinto George Apr 29 '19 at 10:57
  • Yes I have changed to array parameter to type="typens:testPushNotificationCreate" – user78358 Apr 29 '19 at 11:30

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.