Search code examples
google-fit

Trying to GET API for Read Sleep Data from google fit but returning 400 Bad request in response


Below is the request I am passing on Google Playground as well as trying through code to fetch Access token and further data. Scope used here : https://www.googleapis.com/auth/fitness.activity.read

GET /fitness/v1/users/me/sessions?startTime=2019-12-05T00:00.000Z&endTime=2019-12-17T23:59:59.999Z&activityType=72 HTTP/1.1
Host: www.googleapis.com
Content-length: 0
Authorization: Bearer Auth_code

Solution

  • Your start time is malformed:

    startTime=2019-12-05T00:00.000Z
    

    You need hours, minutes and seconds:

    startTime=2019-12-05T00:00:00.000Z
    

    Request in OAuth playground:

    GET /fitness/v1/users/me/sessions?startTime=2019-12-05T00:00:00.000Z&endTime=2019-12-17T23:59:59.999Z&activityType=72 HTTP/1.1
    Host: www.googleapis.com
    Content-length: 0
    Authorization: ...
    

    Response:

    HTTP/1.1 200 OK
    ...