Many of the Magento web services API methods facilitate listing certain types of data - customers, products, orders, etc. However, when using these methods we rarely want to retrieve every record. Luckily there are a number of filter operators that can be used to narrow the result set that will be returned.
The following is a basic example of how to get a list of all customers in PHP:
$server = new SoapClient('http://magentohost/api/soap/?wsdl'); $sessionID = $server->login('api_user', 'api_key'); $server->call($sessionID, 'customer.list');
Now, suppose we want to retrieve only those customers updated since 10/06/2009. We can do this by adding a filter operator to the last line:
$server->call($sessionID, 'customer.list', array(array('updated_at' => array('from' => '2009-06-10'))));
There are quite a few filter operators available which directly correspond to SQL operators, since that's what they are translated to internally.
| Operator | Explanation |
| from | After the given timestamp |
| to | Before the given timestamp |
| like | Like the given text (SQL syntax, using % for wildcards) |
| nlike | Not like the given text (SQL syntax) |
| eq | Equal to the given value |
| neq | Not equal to the given value |
| in | In the given array |
| nin | Not in the given array |
| null | Is null |
| notnull | Is not null |
| gt | Greater than |
| lt | Less than |
| gteq | Greater than or equal to |
| lteq | Less than or equal to |

Comments
This line:
$server->call($sessionID, 'customer.list', array('updated_at' => array('from' => '2009-06-10')));
should be like this:
$server->call($sessionID, 'customer.list', array(array('updated_at' => array('from' => '2009-06-10'))));
Note the extra array(..)
Thanks for pointing that out - the post has been updated.
Post new comment