Working with Sessions

The Fitness REST API lets you create and obtain sessions. Sessions represent a time interval during which users perform a fitness activity.

Sessions are represented by the Users.session resource.

Activities are stored in an 'ActivityType' integer.

Insert a session

This example demonstrates how to insert a session.

HTTP method
PUT
Request URL
https://www.googleapis.com/fitness/v1/users/me/sessions/someSessionId
Request body
{
  "id": "someSessionId",
  "name": "My example workout",
  "description": "A very intense workout",
  "startTimeMillis": 1396710000000,
  "endTimeMillis": 1396713600000,
  "version": 1,
  "lastModifiedToken": "exampleToken",
  "application": {
    "detailsUrl": "http://example.com",
    "name": "Foo Example App",
    "version": "1.0"
  },
  "activityType": 1
}

Response

The response is a 200 OK status code. The response body contains a JSON representation of the session.

Curl command
$ curl --header "Authorization: Bearer ya29.1.yourtokenvalue" -X PUT \
--header "Content-Type: application/json;encoding=utf-8" -d @createsession.json \
"https://www.googleapis.com/fitness/v1/users/me/sessions/someSessionId"

List existing sessions

This example demonstrates how to list existing sessions from April 2014.

HTTP method
GET
Request URL
https://www.googleapis.com/fitness/v1/users/me/sessions?startTime=2014-04-01T00:00:00.000Z&endTime=2014-04-30T23:59:59.999Z
Request body
None.
Response
The response is a 200 OK status code. The response body contains JSON representations of all existing sessions that match the start and end times provided in the query parameters.
Curl command
$ curl --header "Authorization: Bearer ya29.1.yourtokenvalue" -X GET \
--header "Content-Type: application/json;encoding=utf-8" \
"https://www.googleapis.com/fitness/v1/users/me/sessions?startTime=2014-04-01T00:00:00.000Z&endTime=2014-04-30T23:59:59.999Z"