Pass filter to retrive specific set of customer list from magento using ksoap library in JAVA

StackOverflow https://stackoverflow.com/questions/12947589

  •  08-07-2021
  •  | 
  •  

Question

I am using SOAP API to fetch data from magento server.
I want to fetch customer list and I want to pass filter to retrieve specific list of customers. I am using hashMap but it raises a Serialization exception.

My code is like

{request = new SoapObject(NAMESPACE, "customerCustomerInfo");
            request.addProperty("sessionId", sessionId);
            HashMap<String, Object> filter=new HashMap<String, Object>();
            filter.put("customer_id", condition);
            request.addProperty("filters", filter);}

I have also used jsonobject , simple Arraylist , but its raised the same exception.

Was it helpful?

Solution

You can try to change "HashMap" to "HashTable", and register "MarshalHashtable" into your envelope.

Like:

SoapSerializationEnvelope env = new SoapSerializationEnvelope(SoapEnvelope.VER11);
androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug=true;
(new MarshalHashtable()).register(env);
// filter
Hashtable <String, String> filter=new Hashtable<String, String>();
filter.put("customer_id", "1");
request.addProperty("filter", filter);

got this sugestion from

"Use an array of parameters to create a request" at

https://code.google.com/p/ksoap2-android/wiki/CodingTipsAndTricks

OTHER TIPS

@Ricardo's answer is correct and it helped me but I am posting this complete code for those who are still confused. The below code will fetch me the orders of a particular customer.

SoapSerializationEnvelope env = new SoapSerializationEnvelope(SoapEnvelope.VER11);   
env.dotNet = false;                                                                  
env.xsd = SoapSerializationEnvelope.XSD;                                             
env.enc = SoapSerializationEnvelope.ENC;                                             
Hashtable hashtable = new Hashtable();                                               
hashtable.put("customer_id", 17);                                                    

SoapObject request = new SoapObject(NAMESPACE, "salesOrderList");                               
request.addProperty("filters", hashtable);                                           
request.addProperty("sessionId", sessionId);                 

env.setOutputSoapObject(request);                                                    

HTttpTransportSE transportSE = new HttpTransportSE(URL);                                              
transportSE.debug=true;                                                              
(new MarshalHashtable()).register(env);     
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top