Search code examples
xmlmagentomagento-soap-api

Magento Soap Api (v2), how to show XML response


I'm getting in to the Magento SOAP api (v2) to start retrieving new orders and such like.

By running this code on the server (via a url) I can show the array result, but is there a way I can show the response as xml?;

<?php
 $proxy = new SoapClient('http://www.MAGENTO.co.uk/api/v2_soap/?wsdl'); 
$sessionId = $proxy->login('user', 'password'); 

$result = $proxy->salesOrderList($sessionId);
var_dump($result);
?>

Solution

  • Yes, you can, and I'll show you below, but remember that the point of a SOAP API is to abstract all that XML stuff away and let you deal with the native objects of your programming system (in this case, PHP).

    PHP's native SOAP client implementation has debugging methods which will allow you view the request and response for the last soap request made. You'll need to instantiate your client object with the trace option.

    $proxy = new SoapClient('http://www.MAGENTO.co.uk/api/v2_soap/?wsdl', array('trace' => 1)); 
    

    and then you should be able to do something like this

    //could echo as well, I always `var_dump` first in case of unexpected results
    var_dump($proxy->__getLastRequestHeaders());
    
    var_dump($proxy->__getLastRequest());
    
    var_dump($proxy->__getLastResponseHeaders());
    
    var_dump($proxy->__getLastResponse());
    

    The __getLastResponse method should return the raw SOAP XML.