Includes

On this page you will learn about includes and how they will enrich your response, so you will get exactly the API response you need/expect.

What are includes?

Includes are the cornerstone of our API and allow you to enrich and customise your requests. This flexibility is what distinguishes Sportmonks from all competitors. Each endpoint comes with a list of includes. For more information, please refer to our API reference guide.

Creating the request

In this tutorial, our goal is to analyze a match played on the 3rd of September, 2022. We want to know who the teams are and what events (goals, cards, substitutions) happened during the match.

Our starting endpoint will be the GET Fixture by Date endpoint:

https://api.sportmonks.com/v3/football/fixtures/date/2022-09-03?api_token=YOUR_TOKEN

The date is in YYYY-MM-DD format.

This request will give you all the fixtures of a specific date. In our case, the 3rd of September 2022, 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.

Response
{
  "data": [
      {
        "id": 18537988,
        "sport_id": 1,
        "league_id": 501,
        "season_id": 19735,
        "stage_id": 77457866,
        "group_id": null,
        "aggregate_id": null,
        "round_id": 275093,
        "state_id": 1,
        "venue_id": 336296,
        "name": "Hearts vs St. Johnstone",
        "starting_at": "2023-03-04 15:00:00",
        "result_info": null,
        "leg": "1/1",
        "details": null,
        "length": 90,
        "placeholder": false,
        "last_processed_at": "2023-03-02 00:15:27",
        "has_odds": true,
        "starting_at_timestamp": 1677942000
      },
      {
        "id": 18537977,
        "sport_id": 1,
        "league_id": 501,
        "season_id": 19735,
        "stage_id": 77457866,
        "group_id": null,
        "aggregate_id": null,
        "round_id": 275091,
        "state_id": 5,
        "venue_id": 8946,
        "name": "Hibernian vs Kilmarnock",
        "starting_at": "2023-02-18 15:00:00",
        "result_info": "Hibernian won after full-time.",
        "leg": "1/1",
        "details": null,
        "length": 90,
        "placeholder": false,
        "last_processed_at": "2023-02-25 14:55:39",
        "has_odds": true,
        "starting_at_timestamp": 1676732400
      },
      {
        "id": 18537990,
        "sport_id": 1,
        "league_id": 501,
        "season_id": 19735,
        "stage_id": 77457866,
        "group_id": null,
        "aggregate_id": null,
        "round_id": 275093,
        "state_id": 1,
        "venue_id": 8914,
        "name": "Rangers vs Kilmarnock",
        "starting_at": "2023-03-04 15:00:00",
        "result_info": null,
        "leg": "1/1",
        "details": null,
        "length": 90,
        "placeholder": false,
        "last_processed_at": "2023-03-02 00:15:27",
        "has_odds": true,
        "starting_at_timestamp": 1677942000
      },
//And more

Are you interested in an explanation of all the fields? Check the fixture entities page.

You can see the fixture id, the names of the teams involved and the home and away scores. 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=participants to the request, we have successfully used includes. This request will show you the extra data about the participants because we've ‘included’ information about the participants.

Your request:

https://api.sportmonks.com/v3/football/fixtures/date/2022-09-03?api_token=YOUR_TOKEN&include=participants
Response
{
  "data": {
    "id": 18535605,
    "sport_id": 1,
    "league_id": 501,
    "season_id": 19735,
    "stage_id": 77457866,
    "group_id": null,
    "aggregate_id": null,
    "round_id": 274733,
    "state_id": 5,
    "venue_id": 8914,
    "name": "Rangers vs Celtic",
    "starting_at": "2023-01-02 12:30:00",
    "result_info": "Game ended in draw.",
    "leg": "1/1",
    "details": null,
    "length": 90,
    "placeholder": false,
    "last_processed_at": "2023-02-17 10:19:54",
    "has_odds": true,
    "starting_at_timestamp": 1672662600,
    "participants": [
      {
        "id": 53,
        "sport_id": 1,
        "country_id": 1161,
        "venue_id": 8909,
        "gender": "male",
        "name": "Celtic",
        "short_code": "CEL",
        "image_path": "https://cdn.sportmonks.com/images/soccer/teams/21/53.png",
        "founded": 1888,
        "type": "domestic",
        "placeholder": false,
        "last_played_at": "2023-02-26 15:00:00",
        "meta": {
          "location": "away",
          "winner": false,
          "position": 1
        }
      },
      {
        "id": 62,
        "sport_id": 1,
        "country_id": 1161,
        "venue_id": 8914,
        "gender": "male",
        "name": "Rangers",
        "short_code": "RAN",
        "image_path": "https://cdn.sportmonks.com/images/soccer/teams/30/62.png",
        "founded": 1873,
        "type": "domestic",
        "placeholder": false,
        "last_played_at": "2023-02-26 15:00:00",
        "meta": {
          "location": "home",
          "winner": false,
          "position": 2
        }
      }
    ]
  },

The API will give you all the information about the participants. You can see the team names, the logos when the team was founded, the venue id, and more.

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.

We can simply add the include events to our request:

https://api.sportmonks.com/v3/football/fixtures/date/2022-09-03?api_token=YOUR_TOKEN&include=participants;events

And we'll get all the events per fixture.

You can view a snippet of the response below.

Response
{
  "data": {
    "id": 18535605,
    "sport_id": 1,
    "league_id": 501,
    "season_id": 19735,
    "stage_id": 77457866,
    "group_id": null,
    "aggregate_id": null,
    "round_id": 274733,
    "state_id": 5,
    "venue_id": 8914,
    "name": "Rangers vs Celtic",
    "starting_at": "2023-01-02 12:30:00",
    "result_info": "Game ended in draw.",
    "leg": "1/1",
    "details": null,
    "length": 90,
    "placeholder": false,
    "last_processed_at": "2023-02-17 10:19:54",
    "has_odds": true,
    "starting_at_timestamp": 1672662600,
    "participants": [
      {
        "id": 53,
        "sport_id": 1,
        "country_id": 1161,
        "venue_id": 8909,
        "gender": "male",
        "name": "Celtic",
        "short_code": "CEL",
        "image_path": "https://cdn.sportmonks.com/images/soccer/teams/21/53.png",
        "founded": 1888,
        "type": "domestic",
        "placeholder": false,
        "last_played_at": "2023-02-26 15:00:00",
        "meta": {
          "location": "away",
          "winner": false,
          "position": 1
        }
      },
      {
        "id": 62,
        "sport_id": 1,
        "country_id": 1161,
        "venue_id": 8914,
        "gender": "male",
        "name": "Rangers",
        "short_code": "RAN",
        "image_path": "https://cdn.sportmonks.com/images/soccer/teams/30/62.png",
        "founded": 1873,
        "type": "domestic",
        "placeholder": false,
        "last_played_at": "2023-02-26 15:00:00",
        "meta": {
          "location": "home",
          "winner": false,
          "position": 2
        }
      }
    ],
    "events": [
      {
        "id": 71257512,
        "fixture_id": 18535605,
        "period_id": 4546648,
        "participant_id": 53,
        "type_id": 14,
        "section": "event",
        "player_id": 319282,
        "related_player_id": null,
        "player_name": "Daizen Maeda",
        "related_player_name": null,
        "result": "0-1",
        "info": null,
        "addition": "1st Goal",
        "minute": 5,
        "extra_minute": null,
        "injured": null,
        "on_bench": false,
        "coach_id": null,
        "sub_type_id": 1522
      },
      {
        "id": 71257554,
        "fixture_id": 18535605,
        "period_id": 4546648,
        "participant_id": 53,
        "type_id": 18,
        "section": "event",
        "player_id": 74000,
        "related_player_id": 173080,
        "player_name": "Josip Juranovic",
        "related_player_name": "Greg Taylor",
        "result": null,
        "info": null,
        "addition": null,
        "minute": 21,
        "extra_minute": null,
        "injured": true,
        "on_bench": false,
        "coach_id": null,
        "sub_type_id": 1524
      },
 // and more! 

Now we have extra information about the participating teams and all the fixtures' events! Just like that, we 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.

Our API uses the query complexity mechanism to determine the number of includes you can use. More info: query complexity.

Conclusion

The API is very flexible. You will find out more about the flexibility and request options here. 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