Enriching your response

The flexibility of our API is in the part where you build your own responses by adding include parameters to your request. On every endpoint you can find information on what data can be included and how deep you can add includes. To best describe how to use includes and what the include limit means, we will give an explanation based on some example calls.

Adding team information

Useful information for every game is home and away team information. How else would you know between which two teams the game is being played? Here we start with the interesting part, including team information.

https://cricket.sportmonks.com/api/v1/livescores?api_token=__TOKEN__&include=localteam,visitorteam

Note that we have extended our request with &include=localteam,visitorteam. This results in information about the home and away team. You will retrieve a full team object related to the response which includes the name, logo url and much more information.

Adding Runs and Scoreboards

What is a game without the progression? Important information for your application to show could be bowling and batting information, lineup or runs. You can use these includes: localteam,visitorteam,lineup,runs,bowlings,battings

https://cricket.sportmonks.com/api/v1/livescores?api_token=__TOKEN__&include=localteam,visitorteam,lineup,runs,bowlings,battings

With the current URL we have no clue to which scoreboard the player relates to. It only shows the player_id, not the actual name.

Adding nested includes

Luckily the flexibility of the API goes a step further with nested includes. Nested includes are basically relations on relations for the base endpoint. We can enrich the runs, battings etc. with actual player information showing all details of the player who was responsible for the score.

https://cricket.sportmonks.com/api/v1/livescores/now?api_token=__TOKEN__&include=localteam,visitorteam,lineup.player,runs.team,bowlings.team,battings.team

Note we have added the .player to the lineup include? Or .teams to runs, battings and bowlings?

You can add as many nested includes as described in the documentation section of the endpoint it self.

Last updated