We've made some navigation improvements. Information on Sessions and Data types is under the Guides > Key concepts section.

Write Blood Glucose Data

Your app can record blood glucose data by writing to the com.google.blood_glucose data type. In this data type, each data point represents a single instantaneous blood glucose reading. The data point contains fields for the blood glucose concentration, temporal relationships to meals and sleep, and the source of the specimen which was measured. All fields except for blood glucose concentration are optional.

Create a data source

Android

To write a blood glucose data point, create a new DataSource of TYPE_BLOOD_GLUCOSE, as shown in the following example:

DataSource bloodGlucoseSource = new DataSource.Builder()
    .setDataType(TYPE_BLOOD_GLUCOSE)
    ...
    .build();

REST

To write a blood glucose data point, create a new data source.

HTTP method

POST

Request URL

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

Request body

{
  "dataStreamName": "BloodGlucose",
  "type": "raw",
  "application": {
    "detailsUrl": "http://example.com",
    "name": "My Example App",
    "version": "1"
  },
  "dataType": {
    "name": "com.google.blood_glucose"
   }
}

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

Adding data

Android

To add data to the source created above, create a data point for this data source, which can be inserted using the History API:

DataPoint bloodGlucose = DataPoint.create(bloodGlucoseSource);
bloodGlucose.setTimestamp(now.getMillis(), MILLISECONDS);
bloodGlucose.getValue(FIELD_BLOOD_GLUCOSE_LEVEL).setFloat(5.0f); // 90 mg/dL
bloodGlucose.getValue(FIELD_TEMPORAL_RELATION_TO_MEAL)
    .setInt(FIELD_TEMPORAL_RELATION_TO_MEAL_BEFORE_MEAL);
bloodGlucose.getValue(FIELD_MEAL_TYPE).setInt(MEAL_TYPE_BREAKFAST);
bloodGlucose.getValue(FIELD_TEMPORAL_RELATION_TO_SLEEP)
    .setInt(TEMPORAL_RELATION_TO_SLEEP_ON_WAKING);
bloodGlucose.getValue(FIELD_BLOOD_GLUCOSE_SPECIMEN_SOURCE)
    .setInt(BLOOD_GLUCOSE_SPECIMEN_SOURCE_CAPILLARY_BLOOD);

REST

This example demonstrates adding blood glucose data using the data source created above.

HTTP method

PATCH

Request URL

https://www.googleapis.com/fitness/v1/users/me/dataSources/datasource.dataStreamId/datasets/1574159699023000000-1574159699023000000

Request body

For clarity the JSON body shown below is annotated with comments, to show the use of health field constants. Although the Fit API will currently drop comments, it is highly recommended you remove these from your code, as JSON does not officially support comments.

{
  "minStartTimeNs": 1574159699023000000,
  "maxEndTimeNs": 1574159699023000000,
  "dataSourceId": "datasource.dataStreamId",
  "point": [
    {
      "startTimeNanos": 1574159699023000000,
      "endTimeNanos": 1574159699023000000,
      "dataTypeName": "com.google.blood_glucose",
      "value": [
        {
          // Blood glucose level, 90 mg/dL
          "fpVal": 5.0
        },
        {
          // FIELD_TEMPORAL_RELATION_TO_MEAL_BEFORE_MEAL
          "intVal": 3
        },
        {
          // MEAL_TYPE_BREAKFAST
          "intVal": 1
        },
        {
          // TEMPORAL_RELATION_TO_SLEEP_ON_WAKING
          "intVal": 3
        },
        {
          // BLOOD_GLUCOSE_SPECIMEN_SOURCE_CAPILLARY_BLOOD
          "intVal": 2
        }
      ]
    }
  ]
}

Response

If the blood glucose data is added successfully, the response is a 200 OK status code. The response body contains a JSON representation of the blood glucosedata that has been added.

CURL command

$ curl --header "Authorization: Bearer ya29.yourtokenvalue --request PATCH \
    --header "Content-Type: application/json;encoding=utf-8" --data @blood-glucose-data.json \
    https://www.googleapis.com/fitness/v1/users/me/dataSources/datasource.dataStreamId/datasets/1574159699023000000-1574159699023000000