Introducing Response Sorting

Blog:: Introducing Response Sorting

Yes, You can now sort almost all your relational data

Today the sportMonks team is ready to introduce a new feature to the soccer API called "response sorting". So much fun we had while working on this new feature. Mainly because it was something that was requested a lot by our customers in the first 2 weeks of API 2.0.

What is it and how does it work

The name speaks for it self. Response sorting gives you the possibility to sort relational data, loaded via the include option, based on custom criteria. With this in place our API is becoming even more flexible and will serve your needs perfectly.

So let's say we need information about the 2016/2017 English Premier League season, and in our response we want to have full season fixtures with all the events, commentaries, lineups, and substitutes. How should we request this.

The initial request would look similair to this:

GET https://soccer.sportmonks.com/api/v2.0/seasons/13?api_token=__TOKEN__&include=fixtures,fixtures.events,fixtures.comments,fixtures.lineup,fixtures.bench

This will result in a season with fixtures and all the requested includes available as relational data to each fixture. The order of the relational (and fixtures) data can be various, it comes as it hits our database. It would be much better if we could sort each individual include based on our own custom criteria. Let's begin by sorting the fixtures based on the start date in an ascending order.

GET https://soccer.sportmonks.com/api/v2.0/seasons/13?api_token=__TOKEN__&include=fixtures:order(starting_at|asc),fixtures.events,fixtures.comments,fixtures.lineup,fixtures.bench

How easy is that, All fixtures are now ordered based on the start date in an ascending order. Pretty amazing huh? The same logic goes for all other includes you have in your request.

GET https://soccer.sportmonks.com/api/v2.0/seasons/13?api_token=__TOKEN__&include=fixtures:order(starting_at|asc),fixtures.events:order(minute|desc),fixtures.comments:order(minute|desc),fixtures.lineup:order(field_position|asc),fixtures.bench:order(number|asc)

Unfortunately, at this moment in time, this feature is not available for odds and standings. standings are sorted based on position automatically.

The documentation about this feature can be found here https://www.sportmonks.com/soccer/documentation/v2.0/items/includes-sorting/48

We have many more new features we are currently working on so stay tight, more information will follow soon.

Thanks, The Support Team

Share: