Add Hydration Data

You can add hydration data to Google Fit by creating a data source and using the com.google.hydration data type. Each data point represents the volume, in liters, consumed by a user as part of a single drink. Use a float to specify volume. Note: The timestamp indicates when the drink was consumed. Because com.google.hydration is an instantaneous data type, the start and end time should be the same.

Creating a data source

Android

Use DataSource.Builder to create a new data source. For example, hydrationSource.

val hydrationSource = DataSource.Builder()
    .setDataType(DataType.TYPE_HYDRATION)
    .setStreamName("hydrationSource")
    // ... 
    .build()

REST

Call the REST API to create a new data source. For example, HydrationSource.

HTTP method

POST

Request URL

https://www.googleapis.com/fitness/v1/users/me/dataSources

Request body

{
  "dataStreamName": "HydrationSource",
  "type": "raw",
  "application": {
    "detailsUrl": "http://example.com",
    "name": "My Example App",
    "version": "1"
  },
  "dataType": {
    "name": "com.google.hydration",
    "field": [
     {
      "name": "volume",
      "format": "floatPoint",
      "optional": false
     }
    ]
   }
}

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 @hydration-ds.json \
  https://www.googleapis.com/fitness/v1/users/me/dataSources

Adding Hydration Data

Android

This example shows you how to create a new data point, and add hydration data for a 0.3 liter drink of water, using your data source.

val hydration = DataPoint.builder(hydrationSource)
    .setTimestamp(timestamp, TimeUnit.MILLISECONDS)
    .setField(FIELD_VOLUME, 0.3f)
    .build()

REST

This example shows you how to add hydration data using your data source.

HTTP method

PATCH

Request URL

https://www.googleapis.com/fitness/v1/users/me/dataSources/raw:com.google.hydration:407408718192:HydrationSource/datasets/1275753581000000000-1275753581000000000

Request body

{
 "minStartTimeNs": 1275753581000000000,
 "maxEndTimeNs": 1275753581000000000,
 "dataSourceId": "raw:com.google.hydration:407408718192:HydrationSource",
 "point": [
  {
   "startTimeNanos": 1275753581000000000,
   "endTimeNanos": 1275753581000000000,
   "dataTypeName": "com.google.hydration",
   "value": [
    {
     "fpVal": 0.3
    }
   ]
  }
 ]
}

Response

If your data point was created successfully, you'll get a 200 OK HTTP response status code. The response body contains a JSON representation of the data set.

CURL command

$ curl --header "Authorization: Bearer ya29.yourtokenvalue" --request PATCH \
  --header "Content-Type: application/json;encoding=utf-8" --data @hydration-data.json \
  https://www.googleapis.com/fitness/v1/users/me/dataSources/raw:com.google.hydration:407408718192:HydrationSource/datasets/1275753581000000000-1275753581000000000