Includes

What are includes?

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 be fixture get by date:

The date is in YYYY-MM-DD format:

https://soccer.sportmonks.com/api/v2.0/fixtures/date/2020-08-02?api_token={API_TOKEN}

This request will give you all the fixtures of a specific date. In our case, the 2nd of August 2020, which is what we want.

Note that you only have access to the leagues that are available in your plan.

Evaluating the response

All of our endpoints will give you a ‘basic’ response by default. As you can see, we will receive information mostly containing unique ids.

{
    "data": [
        {
            "id": 16475287,
            "league_id": 501,
            "season_id": 17141,
            "stage_id": 77447501,
            "round_id": 194968,
            "group_id": null,
            "aggregate_id": null,
            "venue_id": 8909,
            "referee_id": 14859,
            "localteam_id": 53,
            "visitorteam_id": 338,
            "winner_team_id": 53,
            "weather_report": {
                "code": "clouds",
                "type": "few clouds",
                "icon": "https://cdn.sportmonks.com/images/weather/02d.png",
                "temperature": {
                    "temp": 59.94,
                    "unit": "fahrenheit"
                },
                "temperature_celcius": {
                    "temp": 15.5,
                    "unit": "celcius"
                },
                "clouds": "20%",
                "humidity": "67%",
                "pressure": 1014,
                "wind": {
                    "speed": "10.29 m/s",
                    "degree": 300
                },
                "coordinates": {
                    "lat": 55.87,
                    "lon": -4.26
                },
                "updated_at": "2020-08-02T17:15:04.814798Z"
            },
            "commentaries": false,
            "attendance": null,
            "pitch": null,
            "details": null,
            "neutral_venue": false,
            "winning_odds_calculated": true,
            "formations": {
                "localteam_formation": "4-2-3-1",
                "visitorteam_formation": "4-4-2"
            },
            "scores": {
                "localteam_score": 5,
                "visitorteam_score": 1,
                "localteam_pen_score": null,
                "visitorteam_pen_score": null,
                "ht_score": "2-1",
                "ft_score": "5-1",
                "et_score": null,
                "ps_score": null
            },
            "time": {
                "status": "FT",
                "starting_at": {
                    "date_time": "2020-08-02 15:30:00",
                    "date": "2020-08-02",
                    "time": "15:30:00",
                    "timestamp": 1596382200,
                    "timezone": "UTC"
                },
                "minute": 90,
                "second": null,
                "added_time": null,
                "extra_minute": null,
                "injury_time": null
            },
            "coaches": {
                "localteam_coach_id": 1467946,
                "visitorteam_coach_id": 30082158
            },
            "standings": {
                "localteam_position": 1,
                "visitorteam_position": 12
            },
            "assistants": {
                "first_assistant_id": 12118,
                "second_assistant_id": 17249,
                "fourth_official_id": 15815
            },
            "leg": "1/1",
            "colors": {
                "localteam": {
                    "color": "#007848",
                    "kit_colors": "#F0F0F0,#139343,#5B0623,#0A0A0A,#5C8FAE,#FFDF1B,#F0F0F0"
                },
                "visitorteam": {
                    "color": "#0046A8",
                    "kit_colors": "#0046A8,#0046A8,#0046A8,#0046A8,#C40010,#0046A8,#0046A8"
                }
            },
            "deleted": false,
            "is_placeholder": false,
        }
    ],

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.

https://soccer.sportmonks.com/api/v2.0/fixtures/date/2020-08-02?api_token={API_TOKEN}&include=localTeam,visitorTeam

As you can see, there is an extra part included in comparison to the basic response:

             "localTeam": {
                "data": {
                    "id": 53,
                    "legacy_id": 152,
                    "name": "Celtic",
                    "short_code": "CEL",
                    "twitter": null,
                    "country_id": 1161,
                    "national_team": false,
                    "founded": 1888,
                    "logo_path": "https://cdn.sportmonks.com/images//soccer/teams/21/53.png",
                    "venue_id": 8909,
                    "current_season_id": 17141
                }
            },
            "visitorTeam": {
                "data": {
                    "id": 338,
                    "legacy_id": 693,
                    "name": "Hamilton Academical",
                    "short_code": "HMA",
                    "twitter": null,
                    "country_id": 1161,
                    "national_team": false,
                    "founded": 1874,
                    "logo_path": "https://cdn.sportmonks.com/images//soccer/teams/18/338.png",
                    "venue_id": 288196,
                    "current_season_id": 17141
                }
            }
            
        }

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:

https://soccer.sportmonks.com/api/v2.0/fixtures/date/2020-08-02?api_token={API_TOKEN}&include=localTeam,visitorTeam,events

And we'll get all the events per fixture. You can view a snippet of the response below.

             "events": {
                "data": [
                    {
                        "id": 16475287001,
                        "team_id": "338",
                        "type": "yellowcard",
                        "var_result": null,
                        "fixture_id": 16475287,
                        "player_id": 174161,
                        "player_name": "S. Martin",
                        "related_player_id": null,
                        "related_player_name": null,
                        "minute": 17,
                        "extra_minute": null,
                        "reason": null,
                        "injuried": null,
                        "result": null
                    },
                    {
                        "id": 16475287002,
                        "team_id": "53",
                        "type": "goal",
                        "var_result": null,
                        "fixture_id": 16475287,
                        "player_id": 96792,
                        "player_name": "O. Édouard",
                        "related_player_id": 173080,
                        "related_player_name": "G. Taylor",
                        "minute": 20,
                        "extra_minute": null,
                        "reason": null,
                        "injuried": null,
                        "result": "1-0"
                    },
                    {
                        "id": 16475287003,
                        "team_id": "53",
                        "type": "goal",
                        "var_result": null,
                        "fixture_id": 16475287,
                        "player_id": 8403182,
                        "player_name": "J. Frimpong",
                        "related_player_id": 173080,
                        "related_player_name": "G. Taylor",
                        "minute": 31,
                        "extra_minute": null,
                        "reason": null,
                        "injuried": null,
                        "result": "2-0"
                    },
                    {
                        "id": 16475287004,
                        "team_id": "338",
                        "type": "own-goal",
                        "var_result": null,
                        "fixture_id": 16475287,
                        "player_id": 32761,
                        "player_name": "C. Jullien",
                        "related_player_id": null,
                        "related_player_name": null,
                        "minute": 34,
                        "extra_minute": null,
                        "reason": null,
                        "injuried": null,
                        "result": "2-1"
                    },
                    {
                        "id": 16475287005,
                        "team_id": "338",
                        "type": "yellowcard",
                        "var_result": null,
                        "fixture_id": 16475287,
                        "player_id": 173774,
                        "player_name": "R. Callachan",
                        "related_player_id": null,
                        "related_player_name": null,
                        "minute": 36,
                        "extra_minute": null,
                        "reason": null,
                        "injuried": null,
                        "result": null
                    },               
                ],
            }

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 our nested includes tutorial for more information.

Not seeing all the data you expected to see? Check out our tutorial about pagination.

Last updated