Read Aggregate Daily Nutrition Data
Stay organized with collections
Save and categorize content based on your preferences.
This section demonstrates reading the aggregate daily nutrition from a specific
data source. The response contains a list of buckets (one per 24-hour period),
each with a single dataset and datapoint that contains a field for all recorded
nutrition data types. If no nutrition values exist for a particular time
period, there is no dataset. If more than one meal_type
is recorded, the
value will be set to UNKNOWN
.
Android
Your app can read the aggregate daily nutrition data for a user by creating
a data read request, and specifying the aggregate for the
'DataType.TYPE_NUTRITION' and
'DataType.AGGREGATE_NUTRITION_SUMMARY' data types, as shown in the
following example:
val readRequest = DataReadRequest.Builder()
.aggregate(DataType.AGGREGATE_NUTRITION_SUMMARY)
.bucketByTime(1, TimeUnit.DAYS)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.build()
REST
Your app can read the aggregate daily nutrition data for a user by
making a POST
request and querying the specified data source. You must
make a separate query for each data source.
HTTP method
POST
Request URL
https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate
Request body
{
"aggregateBy": [{
"dataSourceId":
"raw:com.google.nutrition:407408718192:MyDataSource"
}],
"bucketByTime": { "durationMillis": 86400000 },
"startTimeMillis": 1471244400000,
"endTimeMillis": 1471259040000
}
Response
If the data source is created successfully, the response is a 200 OK
status code. The response body contains a JSON representation of the data
source, including a datasource.dataStreamId
property that you can use as
the data source ID for subsequent requests.
CURL command
$ curl --header "Authorization: Bearer ya29.yourtokenvalue --request POST \
--header "Content-Type: application/json;encoding=utf-8" --data @aggregate.json \
https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-28 UTC.
[null,null,["Last updated 2025-08-28 UTC."],[[["\u003cp\u003eThis documentation explains how to access daily aggregate nutrition data from a specific data source.\u003c/p\u003e\n"],["\u003cp\u003eThe data is organized in 24-hour buckets, with each bucket containing a single dataset and datapoint for all recorded nutrition data types.\u003c/p\u003e\n"],["\u003cp\u003eAndroid and REST API examples are provided for retrieving this data.\u003c/p\u003e\n"],["\u003cp\u003eIf multiple meal types are logged, the \u003ccode\u003emeal_type\u003c/code\u003e field will be set to \u003ccode\u003eUNKNOWN\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eMissing nutrition values for a given time period result in an empty dataset for that period.\u003c/p\u003e\n"]]],[],null,["# Read Aggregate Daily Nutrition Data\n\nThis section demonstrates reading the aggregate daily nutrition from a specific\ndata source. The response contains a list of buckets (one per 24-hour period),\neach with a single dataset and datapoint that contains a field for all recorded\nnutrition data types. If no nutrition values exist for a particular time\nperiod, there is no dataset. If more than one `meal_type` is recorded, the\nvalue will be set to `UNKNOWN`. \n\n### Android\n\nYour app can read the aggregate daily nutrition data for a user by creating\na data read request, and specifying the aggregate for the\n['DataType.TYPE_NUTRITION'](/android/reference/com/google/android/gms/fitness/data/DataType#TYPE_NUTRITION) and\n['DataType.AGGREGATE_NUTRITION_SUMMARY'](/android/reference/com/google/android/gms/fitness/data/DataType#AGGREGATE_NUTRITION_SUMMARY) data types, as shown in the\nfollowing example: \n\n val readRequest = DataReadRequest.Builder()\n .aggregate(DataType.AGGREGATE_NUTRITION_SUMMARY)\n .bucketByTime(1, TimeUnit.DAYS)\n .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)\n .build()\n\n### REST\n\nYour app can read the aggregate daily nutrition data for a user by\nmaking a `POST` request and querying the specified data source. You must\nmake a separate query for each data source.\n\n**HTTP method** \n\n POST\n\n**Request URL** \n\n https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate\n\n**Request body** \n\n {\n \"aggregateBy\": [{\n \"dataSourceId\":\n \"raw:com.google.nutrition:407408718192:MyDataSource\"\n }],\n \"bucketByTime\": { \"durationMillis\": 86400000 },\n \"startTimeMillis\": 1471244400000,\n \"endTimeMillis\": 1471259040000\n }\n\n**Response**\n\nIf the data source is created successfully, the response is a `200 OK`\nstatus code. The response body contains a JSON representation of the data\nsource, including a `datasource.dataStreamId` property that you can use as\nthe data source ID for subsequent requests.\n\n**CURL command** \n\n $ curl --header \"Authorization: Bearer ya29.yourtokenvalue --request POST \\\n --header \"Content-Type: application/json;encoding=utf-8\" --data @aggregate.json \\\n https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate"]]