Blog

Testing Magento’s XMLRPC API

This sounds a little esoteric, but along side Magento 1’s more commonly used SOAP API, there is an option to call this using remote procedure calls. There is less documentation out there on this, and even less on how to diagnose any issues. So here are some tips to get you started!

How calls are made

The good news in testing XMLRPC calls is that like most APIs they are based on http calls. In this case, XML is sent as the body of POST requests.

How to test

The simplest way to test is to put your requests into .xml files and pass these via curl. Here is an example of how to get a login token:

curl --data @login.xml http://www.somesite.co.uk/api/xmlrpc/

The –data option tells curl to 1. make a POST request and 2. Use the file login.xml for the body of that message. Here is the contents of that login.xml file:



login
	
		
			rob
		
		
			mykeyhererrt44t9e
		
	

Whitespace is ignored, so this coud be on one line if that’s your fancy.

When testing it’s useful to add -v to the curl command as then you’ll see any issues with connecting. Then you’ll see something like this:

* Trying 10.14.81.204...
* Connected to www.somesite.co.uk (10.14.81.204) port 80 (#0)
> POST /api/xmlrpc/ HTTP/1.1
> Host: www.somesite.co.uk
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Length: 179
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 179 out of 179 bytes
< HTTP/1.1 200 OK
< Date: Fri, 28 Jul 2017 13:29:10 GMT
< Content-Type: text/xml; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< X-Powered-By: PHP/5.5.38
<

* Connection #0 to host www.somesite.co.uk left intact
95f2e88414f07c9aa37435bbd7ef2c9d

Obviously now you can take that token and put it into your next request. Hopefully this comes in handy for anyone who has to test this part of the Magento system.

About the author

Robert Egginton

As our chief problem-solver and systems architect, Rob is involved in every aspect of our development processes. Rob is partial to a bit of improvisational theatre, and setting up a smart home on a budget.