Filtering
Filter the unneeded data for more efficient responses!
In this chapter, we’ll 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 API reference guide for more detailed information. For this tutorial, we’ll use the get fixtures by date endpoint.
This endpoint has the following parameters:
Leagues: filter on league IDs
Bookmakers*: filter on bookmaker IDs
Markets:* filter on market IDs
Status: filter on status
You can only filter on the bookmakers & markets parameters when you've enriched your response with the odds include.
In this tutorial, we’ll show you step by step how filtering works, but most importantly, why you would want to use it.
Create the request
First, we’ll show you why exactly filtering is useful. For example, we want to have all the fixtures on a specific date of the Italian Serie A (league id: 384).
As mentioned above, we’re going to use the same endpoint as in our includes tutorial. Requesting all the fixtures played on the 2nd of August 2020:
https://soccer.sportmonks.com/api/v2.0/fixtures/date/2020-08-02?api_token={API_TOKEN}
"data": [
{
"id": 11999555,
"league_id": 791,
"season_id": 16732,
"stage_id": 77446206,
"round_id": 187825,
"group_id": null,
"aggregate_id": null,
"venue_id": 1466,
"referee_id": 26134,
"localteam_id": 2451,
"visitorteam_id": 233261,
"winner_team_id": 233261,
"weather_report": {
"code": "clouds",
"type": "few clouds",
"icon": "https://cdn.sportmonks.com/images/weather/02n.png",
"temperature": {
"temp": 80.01,
"unit": "fahrenheit"
},
"temperature_celcius": {
"temp": 26.7,
"unit": "celcius"
},
"clouds": "20%",
"humidity": "42%",
"pressure": 1015,
"wind": {
"speed": "8.05 m/s",
"degree": 330
},
"coordinates": {
"lat": 35.47,
"lon": -97.52
},
"updated_at": "2020-08-02T02:00:08.649722Z"
},
"commentaries": false,
"attendance": null,
"pitch": "Good",
"details": null,
"neutral_venue": false,
"winning_odds_calculated": true,
"formations": {
"localteam_formation": null,
"visitorteam_formation": null
},
"scores": {
"localteam_score": 0,
"visitorteam_score": 3,
"localteam_pen_score": null,
"visitorteam_pen_score": null,
"ht_score": "0-2",
"ft_score": "0-3",
"et_score": null,
"ps_score": null
},
"time": {
"status": "FT",
"starting_at": {
"date_time": "2020-08-02 00:00:00",
"date": "2020-08-02",
"time": "00:00:00",
"timestamp": 1596326400,
"timezone": "UTC"
},
"minute": 90,
"second": null,
"added_time": null,
"extra_minute": null,
"injury_time": null
},
"coaches": {
"localteam_coach_id": 37427975,
"visitorteam_coach_id": 32013107
},
"standings": {
"localteam_position": 10,
"visitorteam_position": 3
},
"assistants": {
"first_assistant_id": 26754,
"second_assistant_id": 53662,
"fourth_official_id": 26135
},
"leg": "1/1",
"colors": {
"localteam": {
"color": "#0B750B",
"kit_colors": "#008040,#008040,#008040,#00C1BA,#C40010,#0046A8,#F0F0F0"
},
"visitorteam": {
"color": "#D6003D",
"kit_colors": "#0046A8,#0046A8,#D6003D,#D6003D,#FF0000,#0000FF,#D6003D"
}
},
"deleted": false,
"is_placeholder": false,
},
Field
Description
data
Opens an array of data you've requested
id
A unique fixture id
league_id
The unique id of the league the fixture belongs to
season_id
The unique id of the season the fixture belongs to
stage_id
The unique id of the stage the fixture belongs to
round_id
The unique id of the round the fixture belongs to
group_id
The unique id of the group the fixture belongs to
aggregate_id
Indicates if the fixture has an aggregated score
venue_id
The unique id of the venue the fixture is played at
referee_id
The unique id of the referee that is in charge of the fixture
localteam_id
The unique id of the local team
visitorteam_id
The unique id of the visitor team
winnerteam_id
Contains the id of the team that won the fixture
weather_report
commentaries
Indicates if this fixture has commentaries available
attendance
Give information about the visitor attendance of the fixture
pitch
details
Optional additional information.
neutral_venue
Indicates if the fixture was played at a neutral fixture. This often happens in cup finals
formations
scores
Opens an array containing the scores of the fixture
localteam_score
The number of goals the local team has scored in this fixture
visitorteam_score
The number of goals the visitor team has scored in this fixture
localteam_pen_score
The number of penalty goals the local team has scored in this fixture (only available when the fixture goes into penalty shootout)
visitorteam_pen_score
The number of penalty goals the visitor team has scored in this fixture (only available when the fixture goes into penalty shootout)
ht_score
The score at halftime
ft_score
The score at full time (90 minutes)
et_score
The score in extra time (only available when the fixture goes into extra time)
ps_score
The score of the penalty shootout (only available when the fixture goes into penalty shootout)
time
Opens an array containing the time details of the fixture
status
starting_at
Opens an array containing the time details of the fixture
date_time
Gives the date and time the fixture starts
date
Gives the date on which the fixture is played
time
Gives the starting time of the fixture
timestamp
The timestamp notation of the match
timezone
Indicates in which timezone you've requested the data
minute
Indicates in which minute the fixture is in
second
Indicates in which second the fixture is in
added_time
Indicates how much added time is added
extra_minute
Extra minute is when a fixture goes to extra time. Extra_minute will count from 0 to 15 and from 15 to 30.
injury_time
In case of added time it will end up in injury_minute
coaches
Opens an array containing the unique id's of the coaches
localteam_coach_id
The unique id of the coach from the local team
visitorteam_coach_id
The unique id of the coach from the visitor team
standings
Opens an array containing the standings of the local- and visitorteam
localteam_position
Indicates in which positions the local team is before the fixture
visitorteam_position
Indicates in which positions the visitor team is before the fixture
assistants
Opens an array containing the unique id's of the assistant referees
first_assistant_id
The unique id of the first assistant
second_assistant_id
The unique id of the second assistant
fourth_official_id
The unique id of the fourth official
leg
Indicates in how many legs this fixture is played
colors
Opens an array containing information about the team colors
localteam
Opens an array containing information about the local team colors
color
The main color code of the local team
kit_colors
The kit color codes of the local team
visitorteam
Opens an array containing information about the visitor team colors
color
The main color code of the visitor team
kit_colors
The kit color codes of the local team
deleted
is_placeholder
This property indicates if the resource is used to display dummy data. The false of this property will always be a boolean
value.
Evaluate the response
The request works, but it is far from efficient. While you do receive the data you requested, it is incredibly hard to find the data for only the Italian Serie A (league id: 384) because you’ve just requested every single fixture on that date. For this example, we made the request with an Enterprise Plan subscribed API token, which means that the API would return all fixtures of 1200+ leagues.
Note, that there is only one league id in the previous response snippet. And it's not a fixture from the Italian Serie A (league id: 384).
You can find a short overview of the response at the bottom of the request. This is called the meta description:
],
"pagination": {
"total": 570,
"count": 100,
"per_page": 100,
"current_page": 1,
"total_pages": 6,
"links": {
"next": "https://soccer.sportmonks.com/api/v2.0/fixtures/date/2020-08-02?page=2"
}
}
}
Field
Description
pagination
Opens an array of information about the pages in the API response
total
The total amount of results the API returns
count
The amount of results on the current page
per_page
The amount of results per page
current_page
The number of page currently browsed
total_pages
The total number of pages
links
The link if you want to go to the next API page
As you can see, the API returns a total of 570 results with 100 results per page. Obviously, this is way too much if you only want to request fixtures for a specific league. Therefore, this request is inefficient and needs some slight adjustments.
Please check our pagination tutorial for more information about pages.
Improve the request
This is where filtering comes into play. Because we only want the fixtures of the Italian Serie A (league id: 384) in our response. We can easily exclude the rest of the data that we won’t be needing. Simply add the leagues
parameter to your request:
https://soccer.sportmonks.com/api/v2.0/fixtures/date/2020-08-02?api_token={API_TOKEN}&leagues={IDs}
Now, you can simply add the league id of the Italian Serie A to your request: &leagues=384
The result? Only five fixtures instead of 570! Again, you can see this in the meta description of the response.
https://soccer.sportmonks.com/api/v2.0/fixtures/date/2020-08-02?api_token={API_TOKEN}&leagues=384
{
"data": [
{
"id": 11937816,
"league_id": 384,
"season_id": 16415,
"stage_id": 77445257,
"round_id": 180800,
"group_id": null,
"aggregate_id": null,
"venue_id": 7316,
"referee_id": 15303,
"localteam_id": 394,
"visitorteam_id": 109,
"winner_team_id": 109,
"weather_report": {
"code": "rain",
"type": "light rain",
"icon": "https://cdn.sportmonks.com/images/weather/10d.png",
"temperature": {
"temp": 84.38,
"unit": "fahrenheit"
},
"temperature_celcius": {
"temp": 29.1,
"unit": "celcius"
},
"clouds": "4%",
"humidity": "55%",
"pressure": 1009,
"wind": {
"speed": "7.7 m/s",
"degree": 103
},
"coordinates": {
"lat": 44.8,
"lon": 11.83
},
"updated_at": "2020-08-02T17:45:03.076667Z"
},
"commentaries": true,
"attendance": 0,
"pitch": null,
"details": null,
"neutral_venue": false,
"winning_odds_calculated": true,
"formations": {
"localteam_formation": "4-4-1-1",
"visitorteam_formation": "3-5-2"
},
"scores": {
"localteam_score": 1,
"visitorteam_score": 3,
"localteam_pen_score": null,
"visitorteam_pen_score": null,
"ht_score": "1-1",
"ft_score": "1-3",
"et_score": null,
"ps_score": null
},
"time": {
"status": "FT",
"starting_at": {
"date_time": "2020-08-02 16:00:00",
"date": "2020-08-02",
"time": "16:00:00",
"timestamp": 1596384000,
"timezone": "UTC"
},
"minute": 90,
"second": null,
"added_time": null,
"extra_minute": null,
"injury_time": null
},
"coaches": {
"localteam_coach_id": 932371,
"visitorteam_coach_id": 896626
},
"standings": {
"localteam_position": 20,
"visitorteam_position": 9
},
"assistants": {
"first_assistant_id": 12803,
"second_assistant_id": 14003,
"fourth_official_id": 16419
},
"leg": "1/1",
"colors": {
"localteam": {
"color": "#F4F48A",
"kit_colors": "#F4F48A,#F4F48A,#F4F48A,#F4F48A,#F0F0F0,#0046A8,#0A0A0A"
},
"visitorteam": {
"color": "#482F8A",
"kit_colors": "#482F8A,#482F8A,#5B3BAE,#5B3BAE,#482F8A,#482F8A,#482F8A"
}
},
"deleted": false
},
{
"id": 11937817,
"league_id": 384,
"season_id": 16415,
"stage_id": 77445257,
"round_id": 180800,
"group_id": null,
"aggregate_id": null,
"venue_id": 86,
"referee_id": 17862,
"localteam_id": 102,
"visitorteam_id": 1123,
"winner_team_id": 102,
"weather_report": {
"code": "clouds",
"type": "scattered clouds",
"icon": "https://cdn.sportmonks.com/images/weather/03n.png",
"temperature": {
"temp": 70.77,
"unit": "fahrenheit"
},
"temperature_celcius": {
"temp": 21.5,
"unit": "celcius"
},
"clouds": "40%",
"humidity": "78%",
"pressure": 1008,
"wind": {
"speed": "3.36 m/s",
"degree": 300
},
"coordinates": {
"lat": 44.5,
"lon": 9.07
},
"updated_at": "2020-08-02T20:30:02.943964Z"
},
"commentaries": true,
"attendance": 0,
"pitch": null,
"details": null,
"neutral_venue": false,
"winning_odds_calculated": true,
"formations": {
"localteam_formation": "3-5-2",
"visitorteam_formation": "3-4-2-1"
},
"scores": {
"localteam_score": 3,
"visitorteam_score": 0,
"localteam_pen_score": null,
"visitorteam_pen_score": null,
"ht_score": "3-0",
"ft_score": "3-0",
"et_score": null,
"ps_score": null
},
"time": {
"status": "FT",
"starting_at": {
"date_time": "2020-08-02 18:45:00",
"date": "2020-08-02",
"time": "18:45:00",
"timestamp": 1596393900,
"timezone": "UTC"
},
"minute": 90,
"second": null,
"added_time": null,
"extra_minute": null,
"injury_time": null
},
"coaches": {
"localteam_coach_id": 364995,
"visitorteam_coach_id": 127980
},
"standings": {
"localteam_position": 17,
"visitorteam_position": 11
},
"assistants": {
"first_assistant_id": 15790,
"second_assistant_id": 15305,
"fourth_official_id": 14084
},
"leg": "1/1",
"colors": {
"localteam": {
"color": "#D82520",
"kit_colors": "#1C1A48,#D82520,#1C1A48,#D82520,#5C8FAE,#FFDF1B,#1C1A48"
},
"visitorteam": {
"color": "#FFDF1B",
"kit_colors": "#FFDF1B,#FFDF1B,#F0F0F0,#00C1BA,#C40010,#0046A8,#FFDF1B"
}
},
"deleted": false
},
],
"pagination": {
"total": 5,
"count": 5,
"per_page": 100,
"current_page": 1,
"total_pages": 1,
"links": {}
}
}
}
Did you get a blank response?
Note that there may be no fixtures on the date you’ve requested in the leagues you’ve access to.
Since we’re on a roll, we might as well filter on more than just one league. Simply add more league ids! You can separate them with a comma:
https://soccer.sportmonks.com/api/v2.0/fixtures/date/2020-08-02?api_token={API_TOKEN}&leagues=8,384,501,271....etc.
Filtering and using includes
In the previous chapter, you’ve learned about includes. Thanks to our API’s flexibility, you can filter and use includes in the same request! Let’s mix up the previous request with some includes:
https://soccer.sportmonks.com/api/v2.0/fixtures/date/2020-08-02?api_token={API_TOKEN}&include=localTeam,visitorTeam,events&leagues=384
{
"data": [
{
"id": 11937816,
"league_id": 384,
"season_id": 16415,
"stage_id": 77445257,
"round_id": 180800,
"group_id": null,
"aggregate_id": null,
"venue_id": 7316,
"referee_id": 15303,
"localteam_id": 394,
"visitorteam_id": 109,
"winner_team_id": 109,
"weather_report": {
"code": "rain",
"type": "light rain",
"icon": "https://cdn.sportmonks.com/images/weather/10d.png",
"temperature": {
"temp": 84.38,
"unit": "fahrenheit"
},
"temperature_celcius": {
"temp": 29.1,
"unit": "celcius"
},
"clouds": "4%",
"humidity": "55%",
"pressure": 1009,
"wind": {
"speed": "7.7 m/s",
"degree": 103
},
"coordinates": {
"lat": 44.8,
"lon": 11.83
},
"updated_at": "2020-08-02T17:45:03.076667Z"
},
"commentaries": true,
"attendance": 0,
"pitch": null,
"details": null,
"neutral_venue": false,
"winning_odds_calculated": true,
"formations": {
"localteam_formation": "4-4-1-1",
"visitorteam_formation": "3-5-2"
},
"scores": {
"localteam_score": 1,
"visitorteam_score": 3,
"localteam_pen_score": null,
"visitorteam_pen_score": null,
"ht_score": "1-1",
"ft_score": "1-3",
"et_score": null,
"ps_score": null
},
"time": {
"status": "FT",
"starting_at": {
"date_time": "2020-08-02 16:00:00",
"date": "2020-08-02",
"time": "16:00:00",
"timestamp": 1596384000,
"timezone": "UTC"
},
"minute": 90,
"second": null,
"added_time": null,
"extra_minute": null,
"injury_time": null
},
"coaches": {
"localteam_coach_id": 932371,
"visitorteam_coach_id": 896626
},
"standings": {
"localteam_position": 20,
"visitorteam_position": 9
},
"assistants": {
"first_assistant_id": 12803,
"second_assistant_id": 14003,
"fourth_official_id": 16419
},
"leg": "1/1",
"colors": {
"localteam": {
"color": "#F4F48A",
"kit_colors": "#F4F48A,#F4F48A,#F4F48A,#F4F48A,#F0F0F0,#0046A8,#0A0A0A"
},
"visitorteam": {
"color": "#482F8A",
"kit_colors": "#482F8A,#482F8A,#5B3BAE,#5B3BAE,#482F8A,#482F8A,#482F8A"
}
},
"deleted": false,
"is_placeholder" false,
"localTeam": {
"data": {
"id": 394,
"legacy_id": 2543,
"name": "SPAL",
"short_code": "SPA",
"twitter": "@spalferrara",
"country_id": 251,
"national_team": false,
"founded": 1907,
"logo_path": "https://cdn.sportmonks.com/images//soccer/teams/10/394.png",
"venue_id": 7316,
"current_season_id": 17533
}
},
"visitorTeam": {
"data": {
"id": 109,
"legacy_id": 176,
"name": "Fiorentina",
"short_code": "FIO",
"twitter": "@acffiorentina",
"country_id": 251,
"national_team": false,
"founded": 1926,
"logo_path": "https://cdn.sportmonks.com/images//soccer/teams/13/109.png",
"venue_id": 7223,
"current_season_id": 17488
}
},
"events": {
"data": [
{
"id": 11937816001,
"team_id": "109",
"type": "goal",
"var_result": null,
"fixture_id": 11937816,
"player_id": 129152,
"player_name": "A. Duncan",
"related_player_id": 129836,
"related_player_name": "F. Chiesa",
"minute": 30,
"extra_minute": null,
"reason": null,
"injuried": null,
"result": "0-1"
},
{
"id": 11937816002,
"team_id": "394",
"type": "goal",
"var_result": null,
"fixture_id": 11937816,
"player_id": 129446,
"player_name": "M. D'Alessandro",
"related_player_id": 129010,
"related_player_name": "M. Valoti",
"minute": 39,
"extra_minute": null,
"reason": null,
"injuried": null,
"result": "1-1"
},
{
"id": 11937816003,
"team_id": "394",
"type": "yellowcard",
"var_result": null,
"fixture_id": 11937816,
"player_id": 130165,
"player_name": "M. Fares",
"related_player_id": null,
"related_player_name": null,
"minute": 45,
"extra_minute": 2,
"reason": "Holding",
"injuried": null,
"result": null
},
{
"id": 11937816004,
"team_id": "109",
"type": "substitution",
"var_result": null,
"fixture_id": 11937816,
"player_id": 131955,
"player_name": "C. Kouame",
"related_player_id": 786811,
"related_player_name": "K. Agudelo",
"minute": 55,
"extra_minute": null,
"reason": null,
"injuried": null,
"result": null
},
{
"id": 11937816005,
"team_id": "394",
"type": "substitution",
"var_result": null,
"fixture_id": 11937816,
"player_id": 12790660,
"player_name": "K. Horvath",
"related_player_id": 37397147,
"related_player_name": "J. A. Cuellar Mendoza",
"minute": 61,
"extra_minute": null,
"reason": null,
"injuried": null,
"result": null
},
{
"id": 11937816006,
"team_id": "394",
"type": "substitution",
"var_result": null,
"fixture_id": 11937816,
"player_id": 133364,
"player_name": "G. Strefezza",
"related_player_id": 129949,
"related_player_name": "A. Murgia",
"minute": 61,
"extra_minute": null,
"reason": null,
"injuried": null,
"result": null
},
{
"id": 11937816007,
"team_id": "109",
"type": "substitution",
"var_result": null,
"fixture_id": 11937816,
"player_id": 133805,
"player_name": "P. Cutrone",
"related_player_id": 177988,
"related_player_name": "D. Vlahovic",
"minute": 65,
"extra_minute": null,
"reason": null,
"injuried": null,
"result": null
},
{
"id": 11937816008,
"team_id": "109",
"type": "substitution",
"var_result": null,
"fixture_id": 11937816,
"player_id": 3181370,
"player_name": "R. Sottil",
"related_player_id": 131982,
"related_player_name": "L. Venuti",
"minute": 65,
"extra_minute": null,
"reason": null,
"injuried": null,
"result": null
},
{
"id": 11937816009,
"team_id": "394",
"type": "substitution",
"var_result": null,
"fixture_id": 11937816,
"player_id": 129975,
"player_name": "F. Di Francesco",
"related_player_id": 129010,
"related_player_name": "M. Valoti",
"minute": 80,
"extra_minute": null,
"reason": null,
"injuried": true,
"result": null
},
{
"id": 11937816010,
"team_id": "394",
"type": "substitution",
"var_result": null,
"fixture_id": 11937816,
"player_id": 129551,
"player_name": "B. Salamon",
"related_player_id": 130165,
"related_player_name": "M. Fares",
"minute": 80,
"extra_minute": null,
"reason": null,
"injuried": null,
"result": null
},
{
"id": 11937816011,
"team_id": "394",
"type": "substitution",
"var_result": null,
"fixture_id": 11937816,
"player_id": 89660,
"player_name": "G. Tunjov",
"related_player_id": 129446,
"related_player_name": "M. D'Alessandro",
"minute": 86,
"extra_minute": null,
"reason": null,
"injuried": true,
"result": null
},
{
"id": 11937816012,
"team_id": "109",
"type": "goal",
"var_result": null,
"fixture_id": 11937816,
"player_id": 131955,
"player_name": "C. Kouame",
"related_player_id": 129694,
"related_player_name": "E. Pulgar",
"minute": 89,
"extra_minute": null,
"reason": null,
"injuried": null,
"result": "1-2"
},
{
"id": 11937816013,
"team_id": "109",
"type": "yellowcard",
"var_result": null,
"fixture_id": 11937816,
"player_id": 129836,
"player_name": "F. Chiesa",
"related_player_id": null,
"related_player_name": null,
"minute": 90,
"extra_minute": 2,
"reason": "Tripping",
"injuried": null,
"result": null
},
{
"id": 11937816015,
"team_id": "109",
"type": "substitution",
"var_result": null,
"fixture_id": 11937816,
"player_id": 2170272,
"player_name": "A. Terzic",
"related_player_id": 129152,
"related_player_name": "A. Duncan",
"minute": 90,
"extra_minute": 5,
"reason": null,
"injuried": null,
"result": null
},
{
"id": 11937816016,
"team_id": "109",
"type": "substitution",
"var_result": null,
"fixture_id": 11937816,
"player_id": 24837939,
"player_name": "C. Dalle Mura",
"related_player_id": 129836,
"related_player_name": "F. Chiesa",
"minute": 90,
"extra_minute": 5,
"reason": null,
"injuried": null,
"result": null
},
{
"id": 11937816014,
"team_id": "109",
"type": "penalty",
"var_result": null,
"fixture_id": 11937816,
"player_id": 129694,
"player_name": "E. Pulgar",
"related_player_id": null,
"related_player_name": null,
"minute": 90,
"extra_minute": 4,
"reason": null,
"injuried": null,
"result": "1-3"
}
]
}
},
Just like that, you have built an efficient request and experienced the flexibility of our API. By filtering the request on the data you need, you can save yourself from a lot of irrelevant data. Moreover, you can combine filtering with includes as well. The possibilities are near limitless! Next, we'll be covering limiting API responses.
Last updated