Magento 1.9 API – How to Get Category Image Using Ksoap2 in Android

apimagento-1.9soap

Currently i am Working for Android Magento api integration. For that i am using Ksoap2 library to parse Soap Response in android…i m having trouble to get category image.

http://www.magentocommerce.com/api/soap/catalog/catalogCategory/catalog_category.info.html

i used "catalogCategoryInfo" method to get specific category information. And getting response like this:

catalogCategoryInfo{
 category_id=3; 
 is_active=1; 
 position=1; 
 level=2; 
 parent_id=2; 
 all_children=3; 
 children=; 
 created_at=2014-07-31T17:43:35+05:30; 
 updated_at=2014-11-24 06:38:01; 
 name=Wedding Collections; 
 url_key=t-shirt; path=1/2/3; 
 url_path=t-shirt.html; 
 children_count=0; 
 display_mode=PRODUCTS; 
 is_anchor=0; 
 available_sort_by=ArrayOfString{}; 
 default_sort_by=position; 
}

There is no field like "image"(in SOAP v1 response "image" field is available.see above url). i checked responseobject.getPropertyCount() for total number of attributes..but getting only 18 attributes. how can i get category image url?

Best Answer

This seams like a bug or something that was overlooked.
Let me take it step by step.
First take a look at the definition of the catalogCategoryInfo operation from the wsdl.xml file inside the Mage_Catalog module

<operation name="catalogCategoryInfo">
    <documentation>Retrieve hierarchical tree of categories.</documentation>
    <input message="typens:catalogCategoryInfoRequest"/>
    <output message="typens:catalogCategoryInfoResponse"/>
</operation>

You will see that the response has the type catalogCategoryInfoResponse.
This one looks like this:

<message name="catalogCategoryInfoResponse">
    <part name="info" type="typens:catalogCategoryInfo"/>
</message>

This means that it will return one object of type catalogCategoryInfo. This one is:

         <complexType name="catalogCategoryInfo">
            <all>
                <element name="category_id" type="xsd:string"/>
                <element name="is_active" type="xsd:int"/>
                <element name="position" type="xsd:string"/>
                <element name="level" type="xsd:string"/>
                <element name="parent_id" type="xsd:string"/>
                <element name="all_children" type="xsd:string"/>
                <element name="children" type="xsd:string"/>
                <element name="created_at" type="xsd:string" minOccurs="0"/>
                <element name="updated_at" type="xsd:string" minOccurs="0"/>
                <element name="name" type="xsd:string" minOccurs="0"/>
                <element name="url_key" type="xsd:string" minOccurs="0"/>
                <element name="description" type="xsd:string" minOccurs="0"/>
                <element name="meta_title" type="xsd:string" minOccurs="0"/>
                <element name="meta_keywords" type="xsd:string" minOccurs="0"/>
                <element name="meta_description" type="xsd:string" minOccurs="0"/>
                <element name="path" type="xsd:string" minOccurs="0"/>
                <element name="url_path" type="xsd:string" minOccurs="0"/>
                <element name="children_count" type="xsd:int" minOccurs="0"/>
                <element name="display_mode" type="xsd:string" minOccurs="0"/>
                <element name="is_anchor" type="xsd:int" minOccurs="0"/>
                <element name="available_sort_by" type="typens:ArrayOfString" minOccurs="0"/>
                <element name="custom_design" type="xsd:string" minOccurs="0"/>
                <element name="custom_design_apply" type="xsd:string" minOccurs="0"/>
                <element name="custom_design_from" type="xsd:string" minOccurs="0"/>
                <element name="custom_design_to" type="xsd:string" minOccurs="0"/>
                <element name="page_layout" type="xsd:string" minOccurs="0"/>
                <element name="custom_layout_update" type="xsd:string" minOccurs="0"/>
                <element name="default_sort_by" type="xsd:string" minOccurs="0"/>
                <element name="landing_page" type="xsd:int" minOccurs="0"/>
            </all>
        </complexType>

As you can see there is not image or thumbnail element among the ones returned.
I don't know if this is a bug or a feature or someone simple overlooked it.

But here is what you can do. You can create your own module that will add the image attribute in the list of returned values from the method call.
Follow this example. It is for extending the product response, but it works the same for categories.
The idea is to take advantage of the fact that all the wsdl.xml files from all modules are merged into one big one. You can create your own, and following the same xpath as in the wsdl file for the catalog, add a new attribute to the response.

Related Topic