Magento Themes and Magento Extensions

Magento XML RPC API – Invalid return payload: not-xmlrpc xml element NIL – for


I am working for the Magento API as a server and XML RPC PHP from Joomla as a client to bring up the information of product from Magento. Today I found where the problem persists and I have some workarounds for the fixes. But the fixes are in the Core files of Magento and Joomla itself.

Here is my detailed explanation and fixes for the problem.


When I was working with the XML RPC Magento API, everything working just fine like creating customers, listing product attribute sets and attributes, listing products, etc. But when I came to get the product information of a particular product in a page and used following code:

  1. $client = new xmlrpc_client($path, $host, ”);
  2. //$client–>setDebug(true);
  3. $login = new xmlrpcmsg(‘login’, array(encode($apiUser), encode($apiKey)));
  4. $doc = $client->send($login);
  5. if(!is_object($doc)) {
  6. die(‘XML-RPC non-object document: ’ . $doc);
  7. }
  8. $value = $doc->value();
  9. if(!is_object($value)) {
  10. die(‘XML-RPC non-object value: ’ . $value);
  11. }
  12. $session = $doc->value()->getval();
  13. if(!$session -> 0) {
  14. die(‘Empty session ID: ’ . $doc->faultString());
  15. }
  16. $options = new xmlrpcval(array(new xmlrpcval(’837022070001′, ’string’)), ’array’);
  17. $msg = new xmlrpcmsg( ’call’, array( encode($session), encode(‘’), $options));
  18. $doc = $client->send($msg);
  19. if( $doc->faultCode() == 0 ) {
  20. $items = decode($doc->value());
  21. print_r($items);
  22. }
  23. else {
  24. die($doc->faultString());
  25. }

I keep receiving the following error message:

Invalid return payload: enable debugging to examine incoming payload found not-xmlrpc xml element NIL

When I tried the following to list the products, it just works fine:

  1. $options = new xmlrpcval(array(
  2. new xmlrpcval(
  3. array(
  4. ‘status’ =-> new xmlrpcval(array(‘eq’ =-> new xmlrpcval(’1′, ’string’) ), ’struct’)
  5. ), ’struct’)
  6. ), ’array’);
  7. $msg = new xmlrpcmsg( ’call’, array( encode($session), encode(‘product.list’), $options));
  8. $doc = $client->send($msg);
  9. if( $doc->faultCode() == 0 ) {
  10. $items = decode($doc->value());
  11. print_r($items);
  12. }
  13. else {
  14. die($doc->faultString());
  15. }

Actually this is kind of known bug in Magento specially in case of XML RPC API Server when it returns XML as a response. Magento returns an element empty <NIL> element if there is no value in the field. And the element <NIL> is not the valid element for XML RPC client parsers. It seems the problem is with all type of XML RPC client parsers for different languages like Java, C#, etc. becuase I can see lots of threads in magento discussion board about this but they are almost unsolved yet.


When I went through the manual/documentation of PHP XML RPC, there was some information under FAQ:

My client returns “XML-RPC Fault #2: Invalid return payload: enable debugging to examine incoming payload”: what should I do?

The response you are seeing is a default error response that the client object returns to the php application when the server did not respond to the call with a valid xmlrpc response.

The most likely cause is that you are not using the correct URL when creating the client object, or you do not have appropriate access rights to the web page you are requesting, or some other common http misconfiguration.

To find out what the server is really returning to your client, you have to enable the debug mode of the client, using

  1. $client->setdebug(1);

Since I am working in Joomla 1.5 to get the product information from Magento, I am obviously using XML RPC client recommended by PHP itself ‘phpxmlrpc’ client library which is open source free library. So the problem was due to invalid XML element <NIL> sent by Magento as a response, when the parser tries to parse response XML, it terminates when it finds an invalid element <NIL> even though the XML is well formatted. So for now, I have modified the core phpxmlrpc client library file which is already packed with Joomla as a third party Library inside the library folder. I just went through all the classes and put following script to replace all the occurrences of <NIL> element before it validates the elements.

  1. //File Modified :- libraries/phpxmlrpc/xmlrpc.php
  2. //Line Number: 2539 (approx.)
  3. //Joomla Version: 1.5.18
  4. //XML RPC Version:,v 1.158 2007/03/01 21:21:02 ggiunta Exp
  5. // Date : July 29th, 2010
  6. // Forcefully remove nil element - By Raju Gautam
  7. // to overcome from the  element returned by Magento in response
  8. // because the  element is not valid element for xml rpc
  9. $data = str_replace(array(”, ”, ”, ”, ”, ”), ”, $data);

Though it cannot be assured that the script will work ahead without any problems because if there are other such invalid XML elements injected in any case by Magento API again then we have to replace those elements accordingly. I know the problem must be solved from Magento side but I fixed it from XML RPC client for now because I don’t have much knowledge with Magento yet.

Hope this will help anyone who is really running into the same problem and getting frustrated.

Leave a Reply

You must be logged in to post a comment.