I'm trying to develop Custom Module Magento V2 API with dynamic Elements. So for that I have written statically it's working fine. Now I need to change it dynamically

here is the question?

Normal Magento V2 API wsdl.xml file like below format

<?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}}">
        <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="helloHellomultiCreateAddEntity"> 
                    <element name="name" type="xsd:string" minOccurs="1" />
                    <element name="description" type="xsd:string" minOccurs="0" />
    <message name="helloHellomultiCreateRequest">
         <part name="sessionId" type="xsd:string"/>
         <part name="filters" type="xsd:filters" />
    <message name="helloHellomultiCreateResponse">
        <part name="sessionId" type="xsd:string" />
        <part name="data" type="typens:helloHellomultiCreateEntity" />
    <portType name="{{var wsdl.handler}}PortType">
        <operation name="helloHellomultiCreate">
            <documentation>Add Record</documentation>
            <input message="typens:helloHellomultiCreateRequest" />
            <output message="typens:helloHellomultiCreateResponse" />
    <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="helloHellomultiCreate">
            <soap:operation soapAction="urn:{{var wsdl.handler}}Action" />
                <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
                <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />

    <service name="{{var wsdl.name}}Service">
        <port name="{{var wsdl.handler}}Port" binding="typens:{{var wsdl.handler}}Binding">
            <soap:address location="{{var wsdl.url}}" />

Required Magento V2 API wsdl.xml file need to change complexType as below

<complexType name="helloHellomultiCreateAddEntity">
                            foreach($customer as $id => $key){ ?>
                            <element name="<?php echo $key ?>" type="xsd:string" minOccurs="1" />
                    <?php } ?>

Is it possible to write PHP code in .xml file? for dynamic magento attributes as elements.



you cannot write php code in the wsdl files.
But you can make your type helloHellomultiCreateAddEntity support an array of key-value pairs and you can send the attribute codes and values.
You can see an example in the wsdl.xml from the catalog module.
Search for the type catalogProductReturnEntity.
You will find this line

<element name="additional_attributes" type="typens:associativeArray" minOccurs="0"/>

You need to do something similar.

  • from type catalogProductReturnEntity i have found on 76th line as you said <element name="additional_attributes" type="typens:associativeArray" minOccurs="0"/>. How to know the list of key-value pairs? – Magento007 Aug 19 '15 at 12:46
  • you don't. you will also have to add an api method that retrieves all the customer attributes. – Marius Aug 19 '15 at 12:48
  • I could not figure out. So please explain with example? If possible – Magento007 Aug 19 '15 at 12:57
  • see how the catalogProductListOfAdditionalAttributes operation works from the same catalog wsdl.xml. this one retrieves the attributes of the product. Do something similar for customer attributes. – Marius Aug 19 '15 at 13:44
  • @Marius how to assign api method return array(which retrieves customer attributes) to parameter array – prasad maganti Aug 19 '15 at 14:42

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.