Dataset Filtering, Sorting & Limiting

Dataset Filtering, Sorting & Limiting

Before you dive in to Filtering and limiting you must have a basic understanding of how the API works and what "including data" means. If these terms are unfamiliar for you, we suggest you to start reading Dataset Enrichment first.

Imagine that we want to get the full season schedule of the 2019 Big Bash LEague (BBL). We can request this data via the following URL.

https://cricket.sportmonks.com/api/v1/fixtures?api_token=__TOKEN__&filter[season_id]=10

Filtering The Relationships

In some cases it might be useful to filter the includes to remove data you do not need. Let's say we have included odds and only want the odds of bookmaker bet365.

https://cricket.sportmonks.com/api/v2.0/livescores?api_token=__TOKEN__&include=odds&filter[odds.bookmaker_id]=2

This will remove all the odds that are not from bet365 from the response so you don't have any overhead.

Sorting The Includes

During the season games are being rescheduled due to, for example, International games being played. This will result in an updated/rescheduled games, but since the game ids haven't changed, it can result in weird responses since we want it to be sorted based on starting_at attribute. Here include sorting comes in handy:

https://cricket.sportmonks.com/api/v2.0/seasons/10?api_token=__TOKEN__&include=fixtures&sort=fixtures.starting_at

The above request will result in games sorted by starting_at attribute in ascending order. If you are interested in sorting the other way around then you simply prefix the sorting field with a -(minus sing)

https://cricket.sportmonks.com/api/v2.0/fixtures?api_token=__TOKEN__&sort=-starting_at

Questions?

We're always happy to help with code or other questions you might have! Search our documentation, contact support, or get in touch with our sales team.

This article was last updated on 2019-01-17 15:25:41

{{ loginForm.errors.get('email') }}

{{ loginForm.errors.get('password') }}

Remember me?