cancel
Showing results for 
Search instead for 
Did you mean: 

Call custom soap api. I created custom soap Api module

Call custom soap api. I created custom soap Api module

I have created a custom soap api and have folder structure like Hms-Sales-Model-Order.

Magento installation is 1.9 and These below mentioned are the only files I have in custom module under Hms-Sales.

 

 

Under  Hms-Sales-Model-Order I have Api.php that looks like this

 

class Hms_Sales_Model_Order_Api extends Mage_Sales_Model_Order_Api{
   
  /**
   * Get sales order details
   */
    public function getOrderDetails($sessionId,$clientSubstring,$filters = null)
    {
        //Get Resource model
        $rescource = Mage:Smiley Frustratedingleton('core/resource');
       
        //Retrieve read connection
        $readConnection = $resource->getConnection('core_read');
       
        //Retrieve write connection
        $writeConnection = $resource->getConnection('core_write');
       
        $clientSubstring = 'CHI';
      
        $query = "select * from hms_order_details where  increment_id LIKE '%{$clientSubstring}%'";
       
        //execute query and save results in results
        $results = $readConnection->fetchAll($query);
       
        var_dump($results);
        Mage::log($results);
       
        return $results;
    }

 

Under Hms-Sales-etc

I have api.xml,wsdl.xml,config.xml as follows

 

Api.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->

<config>
    <api>
        <resources>
            <hms_sales_order>
                <title>Custom API for Sales Order Details</title>
                <model>hms/sales_order_api</model>
                <methods>
                     <List translate="title" module="hms">
                        <title>Retrieve sales orders,shipping addresses,project,item details</title>
                        <method>getOrderDetails</method>                                              
                     </List>
                </methods>
            </hms_sales_order>           
                <faults module="Hms_sales">
                    <not_exists>
                        <code>100</code>
                        <message>Requested order not exists.</message>
                    </not_exists>
                    <filters_invalid>
                        <code>101</code>
                        <message>Invalid filters given. Details in error message.</message>
                    </filters_invalid>
                    <data_invalid>
                        <code>102</code>
                        <message>Invalid data given. Details in error message.</message>
                    </data_invalid>
                    <status_not_changed>
                        <code>103</code>
                        <message>Order status not changed. Details in error message.</message>
                    </status_not_changed>
                </faults>               
        </resources>
        <resources_alias>
            <order>Hms_Sales_Order</order>
        </resources_alias>
        <v2>
            <resources_function_prefix>
                <hms_sales_order>hms_salesOrder</hms_sales_order>    
            </resources_function_prefix>
        </v2>
    </api>
</config>

 

config.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->

<config>
 <modules>
    <Hms_Sales>
      <version>0.0.1</version>
      <depends>
        <Mage_Sales />
      </depends>     
    </Hms_Sales>
  </modules>
  <global>
        <models>
            <Sales>
                <rewrite>
                    <order_api>Hms_Sales_Model_Order_Api</order_api>
                    <order_api_v2>Hms_Sales_Model_Order_Api_v2</order_api_v2>
                </rewrite>
            </Sales>
        </models>
    </global>
</config>

 

 

wsdl.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->


<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="hms_salesOrderDetails">
                <all>
                    <element name="increment_id" type="xsd:string" minOccurs="0" />
                    <element name="entity_id" type="xsd:string" minOccurs="0" />
                    <element name="created_at" type="xsd:string" minOccurs="0" />
                    <element name="updated_at" type="xsd:string" minOccurs="0" />
                    <element name="state" type="xsd:string" minOccurs="0" />
                    <element name="status" type="xsd:string" minOccurs="0" />
                    <element name="shipping_description" type="xsd:string" minOccurs="0" />
                    <element name="store_id" type="xsd:string" minOccurs="0" />
                    <element name="customer_id" type="xsd:string" minOccurs="0" />
                    <element name="total_qty_ordered" type="xsd:string" minOccurs="0" />
                    <element name="customer_email" type="xsd:string" minOccurs="0" />
                    <element name="customer_firstname" type="xsd:string" minOccurs="0" />                   
                    <element name="customer_lastname" type="xsd:string" minOccurs="0" />
                    <element name="shipping_method" type="xsd:string" minOccurs="0" />
                    <element name="store_name" type="xsd:string" minOccurs="0" />
                    <element name="total_item_count" type="xsd:string" minOccurs="0" />
                    <element name="shipping_address_id" type="xsd:string" minOccurs="0" />
                    <element name="customer_note" type="typens:ArrayOfString" minOccurs="0" />
                    <element name="sku" type="typens:ArrayOfString" minOccurs="0" />
                    <element name="name" type="xsd:string" minOccurs="0" />
                    <element name="qty_ordered" type="xsd:string" minOccurs="0" />
                    <element name="UOM" type="xsd:string" minOccurs="0" />
                    <element name="first_name" type="xsd:string" minOccurs="0" />
                    <element name="middle_name" type="xsd:string" minOccurs="0" />
                    <element name="last_name" type="xsd:string" minOccurs="0" />
                    <element name="address_type" type="xsd:string" minOccurs="0" />
                    <element name="street" type="xsd:string" minOccurs="0" />
                    <element name="city" type="xsd:string" minOccurs="0" />
                    <element name="region" type="xsd:string" minOccurs="0" />
                    <element name="country_id" type="xsd:string" minOccurs="0" />
                    <element name="postcode" type="xsd:string" minOccurs="0" />
                    <element name="attribute_id" type="xsd:string" minOccurs="0" />
                    <element name="value" type="xsd:string" minOccurs="0" />                  
                </all>
            </complexType>

            <complexType name="hms_salesOrderDetailsArray">
                <complexContent>
                    <restriction base="soapenc:Array">
                        <attribute ref="soapenc:arrayType" wsdl:arrayType="typens:hms_salesOrderDetails[]" />
                    </restriction>
                </complexContent>
            </complexType>

        </schema>
    </types>
    <message name="hms_salesOrderListRequest">
        <part name="sessionId" type="xsd:string" />
        <part name="clientNameSubStr" type="xsd:string" />
        <part name="filters" type="typens:filters" />
    </message>

    <message name="hms_salesOrderListResponse">
        <part name="result" type="typens:hms_salesOrderDetailsArray" />
    </message>

    <portType name="{{var wsdl.handler}}PortType">
        <operation name="hms_salesOrderList">
            <documentation>Retrieve detailed list of assigned products</documentation>
            <input message="typens:hms_salesOrderListRequest" />
            <output message="typens:hms_salesOrderListResponse" />
        </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="hms_salesOrderList">
            <soapSmiley Surprisedperation 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>

 

I am trying to call this method from java program. I was able to get data from inbuild ,ethods from magento soap api but when i try to get data by calling my custom method, the error is

faultString: Invalid api path. This is how I call my magento custom method

 

String url =

"http://myserver/index.php/Hms_Sales_Order/api/soap/?wsdl";

String username = "someone";

String apiKey = "someapik"

 

PortType pt = serviceLocator.getPort();

Magento.PortType portType = serviceLocator.getPort(); 

String sessionId = portType.login(username, apiKey);

System.out.println("Session id is --" +sessionId);

Object objr = portType.call(sessionId, "hms_salesOrder.getOrderDetails", "CHI");

 

 

CAN SOMEONE PLEASE HELP ME???

GREATLY APPRECIATE ANY HELP.