Web services API filter operators

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'))));
Alternatively, we could get only those customers whose email addresses start with 'jim':
$server->call($sessionID, 'customer.list', array(array('email' => array('like' => 'jim%'))));

There are quite a few filter operators available which directly correspond to SQL operators, since that's what they are translated to internally.

OperatorExplanation
fromAfter the given timestamp
toBefore the given timestamp
likeLike the given text (SQL syntax, using % for wildcards)
nlikeNot like the given text (SQL syntax)
eqEqual to the given value
neqNot equal to the given value
inIn the given array
ninNot in the given array
nullIs null
notnullIs not null
gtGreater than
ltLess than
gteqGreater than or equal to
lteqLess than or equal to
api

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

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <apache>, <bash>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <perl>, <php>, <python>, <ruby>, <xml>. The supported tag styles are: <foo>, [foo].

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.