Testing Magento’s XMLRPC API

28 JulyJul, 2017
Robert Egginton

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:

<?xml version="1.0"?>
<methodCall>
<methodName>login</methodName>
	<params>
		<param>
			<value>rob</value>
		</param>
		<param>
			<value>mykeyhererrt44t9e</value>
		</param>
	</params>
</methodCall>

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
<
<?xml version="1.0" encoding="UTF-8"?>
* Connection #0 to host www.somesite.co.uk left intact
<methodResponse><params><param><value><string>95f2e88414f07c9aa37435bbd7ef2c9d</string></value></param></params></methodResponse>

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.