Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
How to fetch Sleep data from Google's REST api?

I'm trying to fetch my sleep data from Google-Fit.

When I make the following request -

const { data: sleepData } = await axios({
        method: 'POST',
        url: 'https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate',
        headers: {
          Authorization: `Bearer ${accessToken}`,
        },
        data: {
          aggregateBy: [{ dataTypeName: 'com.google.sleep.segment' }],
          bucketByTime: { durationMillis: 86400000 },
          startTimeMillis: startTimeQuery, // day start time in UNIX
          endTimeMillis: endTimeQuery, // day end time in UNIX
        },
      });

I'm getting the following data with empty points -

      {
        "bucket": [
          {
            "startTimeMillis": "1651115600000",
            "endTimeMillis": "1651202000000",
            "dataset": [
              {
                "dataSourceId": "derived:com.google.sleep.segment:com.google.android.gms:merged",
                "point": []
              }
            ]
          },
          {
            "startTimeMillis": "1651202000000",
            "endTimeMillis": "1651288400000",
            "dataset": [
              {
                "dataSourceId": "derived:com.google.sleep.segment:com.google.android.gms:merged",
                "point": []
              }
            ]
          },
       ]}

Has anyone run into similar problems?

I'm using Google-Fit on an Android Device.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Hey here is a working example from Google Fitness REST API with my account which is connected to my sleep tracking device.

var axios = require('axios');
var data = JSON.stringify({
  "aggregateBy": [
    {
      "dataTypeName": "com.google.sleep.segment"
    }
  ],
  "endTimeMillis": {endTimeMillis},
  "startTimeMillis": {startTimeMillis}
});

var config = {
  method: 'post',
  url: 'https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate',
  headers: { 
    'Authorization': 'Bearer {AccessToken}', 
    'Content-Type': 'application/json'
  },
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});

The Only difference is to remove the bucketByTime so that Fitness API will send the segment points as small as possible.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!