Querying

Common request parameters

Parameter name Value Notes
format supported format xml, json, jsonp
callback callback name Only valid when output is jsonp

The format is controlled by either the format GET parameter or by supplying an Accept HTTP header. The following table maps content type headers to the equivalent GET format parameters:

GET parameter Accept header
json application/json
jsonp text/javascript
xml application/xml

Request parameters for resource listings

The following parameters are used for Pagination and Ordering:

Parameter name Value Notes
limit integer Number of results to return (pagination)
offset integer Result to begin with (pagination)
sort_by field to sort by Must be a valid field on the model. Prepend with “-” to reverse sort order.

It is also possible to filter resource listings as well. See Filtering below.

Ordering

Ordering result listings can be done with the sort_by GET parameter. Each resource has a list of fields that it is allowed to sort by. For example, the Business Resource can order on created and modified.

For example, to query for a list of business results sorted by their creation time with oldest businesses first:

http://mysite.com/marketplace/api/v1/business/business/?sort_by=created

To view the most recently modified businesses, with the most recent first:

http://mysite.com/marketplace/api/v1/business/business/?sort_by=-modified

Filtering

Each resource has a list of fields that can be filtered on using techniques similar to Django’s filter API. Filtering is performed using GET variables. “Double-underscore” syntax is used to adjust the type of filter.

Examples:

Scenario Filter query
Filter businesses by phone area code /businesses/businesses/?phone1__startswith=204
Filter businesses by city /businesses/businesses/?city=Denver
Show only validated businesses /businesses/businesses/?validated=True
Filter reviews by a specific business /reviews/reviews/?business__pk=1000

See the list of filtering capabilities for each resource in the documentation to learn which fields can be used with filtering.

Geo Queries

The following resources have endpoints that allow you to find objects near a given geographic point:

To query for objects near a location, use the endpoint ending with /near/ (eg. /business/business/near/) and supply lat (latitude), long (longitude), and optionally rad (radius, default 5 miles) GET variables.

For example, to find businesses near (38.96, -95.23), query this URI:

http://yoursite.com/marketplace/api/v1/business/business/near/?lat=38.96&long=-95.23

If you want to expand the search radius from 5 miles to 30 miles, query this URI:

http://yoursite.com/marketplace/api/v1/business/business/near/?lat=38.96&long=-95.23&rad=30

Home

Browse

Glossary

You are here:

This Page