πŸ’°
API 3.0
Odds API 3.0
Odds API 3.0
  • Getting Started
    • πŸ™‹β€β™‚οΈWelcome
    • πŸ”Authentication
    • πŸ’‘Request options
    • 🧭Query complexity
    • πŸ“”Response Codes
    • Endpoints
      • πŸ‘“Pre-match Odds
        • GET All Odds
        • GET Odds by Fixture ID
        • GET Odds by Fixture ID and Bookmaker ID
        • GET Odds by Fixture ID and Market ID
        • GET Last Updated Odds
      • 🧠Inplay Odds
        • GET All Odds
        • GET Odds by Fixture ID
        • GET Odds by Fixture ID and Bookmaker ID
        • GET Odds by Fixture ID and Market ID
        • GET Last Updated Odds
      • πŸ“šBookmakers
        • GET All Bookmakers
        • GET Bookmaker by ID
        • GET Bookmakers Search by Name
        • GET Bookmakers by Fixture ID
        • GET Bookmaker Event ID's by Fixture Id
      • πŸ“‘Markets
        • GET All Markets
        • GET Market by ID
        • GET Markets by Search by Name
    • Entities
      • πŸ“šBookmaker
      • πŸ“‘Market
      • πŸ‘“Odd
      • 🧠InplayOdd
Powered by GitBook
On this page
  • Field selection
  • 1. Only select a specific field
  • 2. Select a specific field on an include
  • Syntax
  1. Getting Started

Request options

PreviousAuthenticationNextQuery complexity

Last updated 2 years ago

This chapter will teach you how to filter out data from our API, which is useful when you want to request specific data and can omit the rest for faster response time. You can filter out data for various parameters per endpoint. See our endpoint overviews for more detailed information.

Field selection

API 3.0 introduces the possibility to request specific fields on entities. This possibility comes in handy when you only use particular fields in an API response. The advantage of selecting specific fields is that it reduces the response speed in mainly large responses. In addition to reducing response time, the response size can also be drastically reduced. Let's take a look together at an example.

1. Only select a specific field

One of our new additions to API 3.0 is a name field on the fixtures. The name field contains a textual representation of the participants playing the fixture. Without selecting a specific field, the API request and response would look like this:

https://api.sportmonks.com/v3/football/fixtures/18509783?api_token={your_token}
{
  "data": {
    "id": 18509783,
    "inplay": 0,
    "sport_id": 1,
    "league_id": 2,
    "season_id": 18346,
    "stage_id": 77453618,
    "group_id": null,
    "aggregate_id": 29195,
    "round_id": null,
    "state_id": 7,
    "venue_id": null,
    "name": "Real Madrid vs Manchester City",
    "home_score": 2,
    "away_score": 1,
    "starting_at": "2022-05-04 19:00:00",
    "result_info": "Real Madrid won after extra-time.",
    "ended_at": "2022-05-04 20:54:26",
    "leg": "2/2",
    "details": null,
    "length": 90,
    "placeholder": false,
    "is_final_result": 0
  },

As you can see, the API response is rather large if you're only interested in the fixture's name. Let's select that API field to reduce the response length and size.

We're using the fixtures endpoint. This means that we can select on all the fields of the fixtures entity. You can do this by adding &select={specific fields on the base }.

In our example, this would result in the below API request and response:

https://api.sportmonks.com/v3/football/fixtures/18509783?api_token={your_token}&select=name
{
  "data": {
    "name": "Real Madrid vs Manchester City",
    "id": 18509783,
    "sport_id": 1,
    "round_id": null,
    "stage_id": 77453618,
    "group_id": null,
    "aggregate_id": 29195,
    "league_id": 2,
    "season_id": 18346,
    "venue_id": null,
    "state_id": 7
  },

As you can see in the example response above, the 'name' field is only returned for the fixture.

Please note that the fields that have relations are also automatically included for technical reasons.

2. Select a specific field on an include

You can also use field selection based on includes. Imagine you want to access fixture lineup information from Manchester City vs Liverpool. Additional to the lineups, you also wish to receive the display names, player images and country details.

Please note that we only copied the first player in the lineup in the below examples. Download our full code examples to see the complete differences.

Without selecting specific fields, you will receive a lot of information you don't need. The API request and partial API response would look like this:

https://api.sportmonks.com/v3/football/fixtures/18138897?api_token={your_token}&include=lineups.player;lineups.player.country
{
  "data": {
    "id": 18138897,
    "inplay": 0,
    "sport_id": 1,
    "league_id": 8,
    "season_id": 18378,
    "stage_id": 77453700,
    "group_id": null,
    "aggregate_id": null,
    "round_id": 247615,
    "state_id": 5,
    "venue_id": 151,
    "name": "Manchester City vs Liverpool",
    "home_score": 2,
    "away_score": 2,
    "starting_at": "2022-04-10 15:30:00",
    "result_info": "Game ended in draw.",
    "ended_at": "2022-04-10 17:22:47",
    "leg": "1/1",
    "details": null,
    "length": 90,
    "placeholder": false,
    "is_final_result": 0,
    "lineups": [
      {
        "id": 1574621,
        "sport_id": 1,
        "fixture_id": 18138897,
        "player_id": 129820,
        "team_id": 8,
        "position_id": 24,
        "detailed_position_id": null,
        "formation_field": null,
        "type_id": 11,
        "provider_id": 2,
        "yersey_number": 1,
        "formation_position": 1,
        "player_name": "Alisson",
        "player": {
          "id": 129820,
          "sport_id": 1,
          "country_id": 5,
          "nationality_id": null,
          "city_id": null,
          "position_id": 24,
          "detailed_position_id": 24,
          "type_id": 24,
          "common_name": "A. Becker",
          "firstname": "Alisson RamsΓ©s",
          "lastname": "Becker",
          "name": "Alisson RamsΓ©s Becker",
          "display_name": "Alisson",
          "image_path": "https://cdn.sportmonks.com/images/soccer/players/28/129820.png",
          "height": 193,
          "weight": 91,
          "date_of_birth": "1992-10-02",
          "gender": "male",
          "country": {
            "id": 5,
            "continent_id": 7,
            "name": "Brazil",
            "official_name": "Federative Republic of Brazil",
            "fifa_name": "BRA",
            "iso2": "BR",
            "iso3": "BRA",
            "latitude": "-10.81045150756836",
            "longitude": "-52.97311782836914",
            "geonameid": 3469034,
            "borders": [
              "ARG",
              "BOL",
              "COL",
              "GUF",
              "GUY",
              "PRY",
              "PER",
              "SUR",
              "URY",
              "VEN"
            ],
            "image_path": "https://cdn.sportmonks.com/images//countries/png/short/br.png"
          }
        }
      },

Download full-example

Now, let's select specific fields on the base entities used.

Since we're using the lineups.player include, the first base entity is players. We can select on all the fields of that entity. In our example, you need to select display_name and image_path.

The new API request and partial API response would look like this:

https://api.sportmonks.com/v3/football/fixtures/18138897?api_token={your_token}&include=lineups.player:display_name,image_path;lineups.player.country:name,image_path
{
  "data": {
    "id": 18138897,
    "inplay": 0,
    "sport_id": 1,
    "league_id": 8,
    "season_id": 18378,
    "stage_id": 77453700,
    "group_id": null,
    "aggregate_id": null,
    "round_id": 247615,
    "state_id": 5,
    "venue_id": 151,
    "name": "Manchester City vs Liverpool",
    "home_score": 2,
    "away_score": 2,
    "starting_at": "2022-04-10 15:30:00",
    "result_info": "Game ended in draw.",
    "ended_at": "2022-04-10 17:22:47",
    "leg": "1/1",
    "details": null,
    "length": 90,
    "placeholder": false,
    "is_final_result": 0,
    "lineups": [
      {
        "id": 1574621,
        "sport_id": 1,
        "fixture_id": 18138897,
        "player_id": 129820,
        "team_id": 8,
        "position_id": 24,
        "detailed_position_id": null,
        "formation_field": null,
        "type_id": 11,
        "provider_id": 2,
        "yersey_number": 1,
        "formation_position": 1,
        "player_name": "Alisson",
        "player": {
          "id": 129820,
          "country_id": 5,
          "sport_id": 1,
          "city_id": null,
          "position_id": 24,
          "detailed_position_id": 24,
          "display_name": "Alisson",
          "image_path": "https://cdn.sportmonks.com/images/soccer/players/28/129820.png",
          "country": {
            "id": 5,
            "continent_id": 7,
            "name": "Brazil",
            "image_path": "https://cdn.sportmonks.com/images//countries/png/short/br.png"
          }
        }
      },

Download full-example

As you can see in the example response, the size and length are reduced significantly.

Syntax

This syntax can be used across all endpoints, the documentation for each endpoint describes the exceptions regarding exclusions of some fields/relations.

The table below describes the syntax for the usage of the field selection

Syntax
Usage
Example

&select=

Select specific fields on the base entity

&select=name

&include=

Include relations

?include=lineups

;

Mark end of (nested) relation, you can start including of other relations here

?include=lineups;events

:

Mark field selection

?include=lineups:player_name;events

The second base entity is countries. Just like on the player entity, we can select on all the fields of the entity. In our example, you need to select name and image_path.

πŸ’‘
entity
countries
66KB
old_request_selecting_fields_on_includes.json
The API response without selecting on fields
37KB
new_request_selecting_field_on_includes.json
The API response with selecting on fields