Ben James :: adventures in gaming


Magento API Calls - Filter Parameters

One of the tasks ReadyToShip regularly needs to do is pull down all the orders from Magento that have been modified since the last time we got them. You would think this would be easy enough to do, since the sales_order.list API call provides a 'filter' parameter, used like so (this is perl but you should be able to easily figure it out for your own language):

my $server = Frontier::Client->new( url => "http://magentourl/api/xmlrpc/", debug => 1 );
my $sessionID = $server->call("login", ("username", "apikey"));
my $result = $server->call("call", ($sessionID, "sales_order.list", [
        updated_at => {
            from => "2008-10-05 12:49:51"

Unfortunately, the terms you can use are not very well documented. The wiki page gives an example of a 'like' match, but what else can we do with this filter parameter?

Well, I needed to find out so I started digging into the code and I found my way to the Varien_DB library where the SQL was constructed for these filters. And thus, I can deliver to you the following:

Parameters you can pass to a Magento API filter
from returns rows that are after this value (datetime only)
to returns rows that are before this value (datetime only)
eq returns rows equal to this value
neq returns rows not equal to this value
like returns rows that match this value (with % as a wildcard)
nlike returns rows that do not match this value (with % as a wildcard)
in returns rows where the value is in this array (pass an array in)
nin returns rows where the value is not in this array (pass an array in)
is unsure
null returns rows that are null
notnull returns rows that are not null
moreq unsure
gt returns rows greater than this value
lt returns rows less than this value
gteq returns rows greater than or equal to this value
lteq returns rows less than or equal to this value
finset unsure

I hope you find it useful!

3 Responses to “Magento API Calls - Filter Parameters”

  1. 1
    ianjs Says:

    How come you don’t have an autodiscovery ref for your RSS feed? I went to add your blog to Google Reader and almost forgot how to do it without one ;-)

    Oh, and how did you do the funky syntax highlighting?

  2. 2
    Adam B Says:

    What does the xml look like when you post a filter? Just asking because none of the apis seem to work from C# and I’m trying to just post the xml. Thanks!

  3. 3
    splitsplut Says:

    I’ve had your blog in my bookmarks for a couple of days now and just wanted to say that I really love your articles! ^^

Leave a Reply

Powered by Wordpress 2YI.NET Web Directory