### Android

Your app can get a list of food items eaten within a specified time frame by
creating a data read request and querying for `DataType.TYPE_NUTRITION`, as
shown in the following example:

    val readRequest = DataReadRequest.Builder()
        .read(DataType.TYPE_NUTRITION)
        .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
        .build()

For more information about reading data, see [Work with the Fitness History](https://developers.google.com/fit/android/history).

### REST

Retrieving a list of food items eaten, via the REST API is a three stage
process:

1. Retrieve a list of data sources available for the `com.google.nutrition` data type. *Alternatively, if the data source details are already known,
   these can be used directly in the next step.*
2. Obtain a list of food eaten from each data source in turn.
3. (*If there is more than one data source*) combine the lists of food items within the client application.

### Retrieving a list of food data sources

As only the `datasource.dataStreamId` is required from each [data source](https://developers.google.com/fit/rest/v1/reference/users/dataSources#resource),
a field mask can be used, as shown here, to limit the response to just this
property.

**HTTP method**

    GET

**Request URL**

```html
https://www.googleapis.com/fitness/v1/users/me/dataSources?dataTypeName=com.google.nutrition&fields=dataSource(dataStreamId)
```

**Response**

If successful, the response is a `200 OK` status code. The response body
contains a JSON list, each item in the list corresponding to a data source.

For example:

    {
     "dataSource": [
      {
       "dataStreamId": "raw:com.google.nutrition:com.example.nutritionSource1:"
      },
      {
       "dataStreamId": "raw:com.google.nutrition:com.example.nutritionSource2:"
      }
     ]
    }

**CURL command**

```html
$ curl \
  'https://www.googleapis.com/fitness/v1/users/me/dataSources?dataTypeName=com.google.nutrition&fields=dataSource(dataStreamId)' \
      --header 'Authorization: Bearer ya29.yourtokenvalue' \
      --header 'Accept: application/json' \
      --compressed
```

### Obtaining a list of food eaten from a data source

Use the `dataSource.dataStreamId` from each of the sources in step 1, in
turn, to retrieve the list(s) of food eaten.

The `datasetId` is start and end of the required time period, in nanoseconds
as defined in the [data set resource](https://developers.google.com/fit/rest/v1/reference/users/dataSources/datasets/get#parameters).

For example, `1546300800000000000-1546387200000000000` represents the
`datasetId` for *01 Jan 2019 00:00:00 UTC* to *02 Jan 2019 00:00:00*.

> [!NOTE]
> **Note:** You can use a field mask to only get relevant values in the response. This example uses the `point/value/stringVal` field mask to only get the names of the food items eaten (shown in `stringVal`). It excludes the other default fields in the data set resource for the `com.google.nutrition` data points like `nutrients`, `meal_type` and `food_item`. You can edit the field mask to add or remove properties. For example, `point(startTimeNanos,value/stringVal)` would include a timestamp against each food item.

**HTTP method**

    GET

**Request URL**

```html
https://www.googleapis.com/fitness/v1/users/me/dataSources/dataSource.dataStreamId/datasets/1546300800000000000-1546387200000000000?fields=point%2Fvalue%2FstringVal
```

**Response**

    {
     "point": [
      {
       "value": [
        {},
        {},
        {
         "stringVal": "apple"
        }
       ]
      },
      {
       "value": [
        {},
        {},
        {
         "stringVal": "banana"
        }
       ]
      },
      {
       "value": [
        {},
        {},
        {
         "stringVal": "carrot"
        }
       ]
      }
     ]
    }

**CURL command**

```html
$ curl \
  'https://www.googleapis.com/fitness/v1/users/me/dataSources/dataSource.dataStreamId/datasets/157059699023000000-1575159699023999000?fields=point%2Fvalue%2FstringVal' \
      --header 'Authorization: Bearer ya29.yourtokenvalue' \
      --header 'Accept: application/json' \
      --compressed
```