Includes are the cornerstone of our API and allow you to enrich and customize your requests. This flexibility is what distinguishes Sportmonks from all competitors.
This manner of flexibility lets you receive the specific data that interests you. Each endpoint comes with a list of includes. For more information, please refer to our API reference guide.
You can see includes as something like an add-on to an endpoint. In this tutorial, we will show and explain what includes are and how you can make use of them. Don’t worry, though; using includes is relatively straightforward!
Creating the request
In this tutorial, our goal is to analyze a match played on the 2nd of August 2020. We want to know who the teams are and what events (goals, cards, substitutions) happened during the match.
Our starting endpoint will befixture get by date:
You can see the fixture id, the local and visitor teams’ id, and the full-time score. However, what if we want to know more about the participating teams, their team names, or what their logos look like?
Enrich your response with includes!
This is where includes come into play. By merely adding&include=localTeam,visitorTeamto the request, we have successfully used includes. This request will show you the extra data about the home and visitor teams because we've ‘included’ information about the local and visitor teams.
The API will give you all the information about the local and visitor teams. You can see the team names, the logos when the team was founded, the venue id, and the id of the current season they’re participating in.
Like shooting fish in a barrel, right?
But we’re not done yet! We still want to know about the events (goals, cards, and substitutions) that happened during the match.
Our API has close to no limit on the number of includes per endpoint. This allows you to request all the extra data you want in the same request. So, we can simply add the include events to our request:
Now we have extra information about the participating teams and all the events of a fixture! Just like that, we have achieved our goal.
Includes are basically add-ons that you can use with your request for additional information. The endpoint provides basic data, while the include gives you extra information.
Conclusion
Not all includes work with every endpoint. So please make sure that you check which includes are available per endpoint in our API reference guide.
There are also more advanced, includes called nested includes. These are relationships of relationships. You can already check out ournested includes tutorialfor more information.
Not seeing all the data you expected to see? Check out our tutorial aboutpagination.