Selecting fields
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.
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:
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 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:
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.
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 Celtic vs Rangers (fixture id: 18535517). 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 players in the lineup in the below examples
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:
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:
See how the size of the response is reduced? Next to selecting specific fields on the base entity or includes, it’s possible to filter your request. Check the next section for more info.
Last updated