Tuesday, May 9, 2017

Quick code to test XML-RPC and SOAP 2 in PHP using Magento 1.x

XML-RPC


require_once 'app/Mage.php';

umask(0);
Mage::app();

$host = 'http://test.com';
$user = 'user';
$pass = 'pass';  

$client = new Zend_XmlRpc_Client($host.'/api/xmlrpc/');
$session = $client->call('login', array($user,$pass));

//call resource sales_order.info
$client->call('call', array($session, 'sales_order.info', array('10000001')));

$response = $client->getLastResponse();
$data = $response->getReturnValue();
var_dump($data);

$client->call('endSession', array($session)); 

SOAP 2


ini_set("soap.wsdl_cache_enabled", "0");//no cache

$host = 'http://test.com';
$user = 'user';
$pass = 'pass';  

$client = new SoapClient($host.'/api/v2_soap/?wsdl'); 
$sessionId = $client->login($user,$pass); 
 
//check available types
//$types = $client->__getTypes();
//var_dump($types);

//check available functions
//$functions = $client->__getFunctions();
//var_dump($functions);

$result = $client->salesOrderInfo($sessionId,'900687569'); 
var_dump($result);

No comments:

Post a Comment