Skip to content

Instantly share code, notes, and snippets.

@DarkCat09
Last active September 17, 2022 14:58
Show Gist options
  • Save DarkCat09/bade28d9abaeac2b40a2f1f8115e7039 to your computer and use it in GitHub Desktop.
Save DarkCat09/bade28d9abaeac2b40a2f1f8115e7039 to your computer and use it in GitHub Desktop.
Google's Fields API from YouTube documentation

How to use the fields parameter

The fields parameter filters the API response, which only contains the resource parts identified in the part parameter value, so that the response only includes a specific set of fields. The fields parameter lets you remove nested properties from an API response and thereby further reduce your bandwidth usage. (The part parameter cannot be used to filter nested properties from a response.)

The following rules explain the supported syntax for the fields parameter value, which is loosely based on XPath syntax:

  • Use a comma-separated list (fields=a,b) to select multiple fields.
  • Use an asterisk (fields=*) as a wildcard to identify all fields.
  • Use parentheses (fields=a(b,c)) to specify a group of nested properties that will be included in the API response.
  • Use a forward slash (fields=a/b) to identify a nested property.
  • In practice, these rules often allow several different fields parameter values to retrieve the same API response. For example, if you want to retrieve the playlist item ID, title, and position for every item in a playlist, you could use any of the following values:
fields=items/id,playlistItems/snippet/title,playlistItems/snippet/position
fields=items(id,snippet/title,snippet/position)
fields=items(id,snippet(title,position))

Note

As with all query parameter values, the fields parameter value must be URL encoded. For better readability, the examples in this document omit the encoding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment