AI-generated Key Takeaways
- 
          The Fitness REST API is used to create and retrieve sessions, which represent fitness activities over a time interval. 
- 
          Sessions are represented by the Users.session resource, and activities are categorized using an ActivityType integer. 
- 
          The provided examples demonstrate how to insert a new session using a PUT request and list existing sessions within a specified time range using a GET request. 
- 
          It is important to refer to the "Responsible use of Google Fit" guidelines for best practices when handling user data. 
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 OKstatus 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 OKstatus 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" 
