I am trying to call the Magento SOAP API and get a list of orders within a certain time period. I can connect to API and get a list of all the orders just fine but I can't (for the life of me) figure out how to filter the results... Any ideas? My Code that return all the orders is below...
$proxy = new SoapClient('http://lalala.freelunchlabs.com/api/v2_soap/?wsdl');
// create authorized session id using api user name and api key
$sessionId = $proxy->login('myusername', 'mypassword');
$filters = array(
'created_at' => array( '>' => '2011-04-21 02:13:00'),
'created_at' => array( '<' => '2011-04-21 02:22:00')
);
// Get order list
$orderinfo = $proxy->salesOrderList($sessionId,array($filters));
print_r($orderinfo);
Thanks in advance!
Chuck
I got no experience with the Magento SOAP 2 Api, but if the filters in V2 work the same way as with V1, you could try this:
$filters = array(
'created_at' => array(
'from' => '2011-04-21 02:13:00',
'to' => '2011-04-21 02:22:00'
)
);
In v2 of the Magento API you need to adjust your 'filters' array like so:
$params = array('complex_filter'=>
array(
array('key'=>'created_at','value'=>array('key' =>'from','value' => '2012-07-05 01:01:01'))
)
);
While their API shows an example of the API v2 here:
http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/introduction#api_version_v2
this documentation doesn't indicate (as far as I can tell) that you need to replace 'filter' with 'complex_filter' when using conditional statements.
For example, you could replace
'key'=>'from"
with
'key'=>'to'
or
'key'=>'eq'
A more complete list of conditionals that you can use is here:
http://100101.kurodust.net/2008/10/24/magento-api-calls-filter-parameters/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With