Complex Queries

Discussion

Simple usage of the Stack Exchange API focuses around getting large sets of data about sites quickly. It's fairly obvious how to grab all of a user's answers, even all of a large set of users' via vectorized requests, all recent comments, and so on. What's less obvious is how to cull our datasets to smaller chunks of data.

The Stack Exchange API provides the sort, min, max, fromdate, and todate parameters on many methods to allow for more complicated queries. min and max specify the range of a field must fall in (that field being specified by sort) to be returned, while fromdate and todate always define the range of creation_date. Think these parameters as defining two "windows" in which data must fit to be returned.

min, max, fromdate, and todate are inclusive.

Examples

Another handy trick is to only request the total field when all you care about is the quanity of items meeting some criteria, such as when calculating statistics. The ?filter=total built-in filter is provided for just this purpose.