💡Request options

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}

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 entity}.

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

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

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 second base entity is countries. Just like on the player entity, we can select on all the fields of the countries entity. In our example, you need to select 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

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

SyntaxUsageExample

&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

Last updated