Consuming the Magento’s XMLRPC web service through Android

Featured Image

Recently I became proud owner of HTC Desire mobile device powered by Android platform. This is something I got my boss Tomislav Bilic to thank to. Even before (several weeks before) getting my real Android powered phone, I started poking around Android platform. Behind this interest was my desire is was/is to do mobile eCommerce apps. As I have been involved in everyday Magento development for the last two years now, it was only logical for my first steps to do something Magento-Android related.

So, what was on the plate? In order to do anything mobile with Magento you need to connect to its API, whether it is SOAP or XMLRPC API interface.

Personally I am a bigger fan of XMLRPC (can’t say why actually). In regards to that, my first task was to connect my Android to Magento XMLRPC API. Surprisingly, Android framework (SDK) does not have feature rich and ready classes for doin XMLRPC calls like lets say Zend Framework has.

Luckily for me, there was already someone who had to deal with this issue before me. If you open the Android-XMLRPC page you will find a nice little library for handling the XMLRPC in Android. This was all I needed to get me started. Here is an example of how to connect to Magento trough this library.

// ...
String sessionId = "";
//HashMap<string , String> params = new HashMap</string><string , String>();
//params.put("apiUser", "developer");
//params.put("apiKey", "magento123");
XMLRPCClient client = new XMLRPCClient("");
try {
		sessionId = (String)client.callEx("login", new Object[]{params});
		will cause
		DEBUG/MY_XMLRPCException_MSG(196): XMLRPC Fault: Calling parameters do not match signature <pre class="ish"><code class="language-623"> </code></pre> 
	sessionId = (String)"login", "developer", "magento123");
catch (XMLRPCException e) {
	Log.d("MY_XMLRPCException_MSG", e.getMessage());
// ...

By executing above you will most likely trigger the exception and get the following error.

06-09 09:33:53.313: DEBUG/MY_XMLRPCException_MSG(226): Permission denied (maybe missing INTERNET permission).

As you can see, error is pretty self-descriptive. You need to open your AndroidManifest.xml file and add the following inside the “manifest” attribute.

<uses -permission android:name="android.permission.INTERNET"></uses>

After successfully executed XMLRPC request, you should see the log message like shown below.

06-09 09:49:27.163: DEBUG/MY_XMLRPC_SUCCESS_SESSION_ID(223): 9273ad9a5a52a959fec32439944bc84b

Meaning you now have session id and can do the rest of the Magento XMLRPC method calls by passing this session id.

Also, you can see in the code, that I commented some stuff. For those ambitions this is a little tip on how to do more complex API calls to the rest of the Magento XMLRPC API methods exposed. This one you need to figure on your own.

Hope it comes in handy to the Magento-Android newcomers.

From Croatia with love, cheers.


  1. Hi, I am trying this same code for my URL but every time getting the exception…
    Like expected start Tag{..}. my wsdl is getting start with

    Please help…

  2. Hii.. I am creating a magento application. How can i develop login page ?
    Am i using web service..?

  3. How to pass argument in callEx method for getting only one customer data from customer.list?

  4. Hi there,

    Great tuto.
    I’m testing it and I get the session correctly but It’s impossible for me to get any other call working.

    Can you post an example to see how is suposed to put the sessionid in that call?

    I’m really blocked right now


  5. I can’t get the XMLRPC to intergrate with eclipse. any good tuts for this ?. Eclipse keeps underlining all the code in red.

  6. Hello,

    Thanks a lot for your tutorial.

    I have a question about the calls to the rest of the Magento XMLRPC API methods because I don’t know where I should put the session id parameter.

    Could you show an example of calling any method or for example the customer.create??

    Thanks in advance

  7. nevermind, for those of you who have this same issue in the future, you must create a new project from source in eclipse rather than using the import project feature

  8. I am having trouble setting up android-xmlrpc, I get an error right away when I import the project into eclipse:

    Description Resource Path Location Type
    Project has no file! Edit the project properties to set one. XMLRPC Unknown Android Target Problem

    Description Resource Path Location Type
    The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project XMLRPC Unknown Java Problem

    Description Resource Path Location Type
    The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files /XMLRPC/src/org/xmlrpc/android line 1 Java Problem

    Those 3 different error messages. How do I setup android-xmlrpc correctly?

  9. Hi,

    i am new to magento and looking to publish api for catalog search is there any code readily available?

    Thanks in advance

  10. I was wondering, i’ve managed so far to retrieve information from magento and show this in a table using my android. it also shows a nice image.

    Now there is this filter. Has anyone already tried to use the filter with xmlrpc in java?

    if so can someone please post an example?

    greetings and thanks in advance Marc

  11. Thanks a lot for this little tutorial!

    I have just one correction about the internet permission, the right code is:

    (no space between “uses” and “-permission ” and autoclose tag.

  12. Thanks for the tutorial.

    Could you also maybe do another basic call. Something like sales_order.list too?

    I am very interested to see how a call like that would be put together?

  13. Hey Vijay. THanks for pointing it out. The typo is now fixed. Feel free to let us know if you notice anything else. English is not our native language 🙂

  14. Great work.I Like it.

    But I have one question in this sentence
    Consuming the Magento’s XMLRPC web service “trough” Android

    Here “trough” is intentionally or mistake.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.