This script is no longer updated. The most updated script is now handled by the Coda Peloton Pack.
I have created a Coda template you can copy which contains the tables setup for syncing your own Peloton data. I try to make updates to the charts and dashboards in the template so check the template for new functionality.
- You can add which type of workouts you want to sync in Synced Workouts by changing the "workout type" in the sync table settings. This limits the number of workouts returned to the type you care about.
- The types should be separated by commas. Options are cycling, strength, yoga, stretching, running, walking, cardio, meditation, bike_bootcamp, outdoor, and bootcamp (tread).
- Added average output/minute to the Browse Instructors page showing your output/min for all the cycling classes you've taken with a given instructor
- The Friends' Cycling Leaderboard automatically defaults to all your friends selected when you copy the template
- Fixed the Monthly: Average Output, Cadence, Resistance, Speed chart on the Cycling page to show avg. Cadence, Resistance, and Speed correctly
🎉 Kudos to Makon for reporting these issues!
- Fixed a bug with walking and running workouts which would break the Pack
- For walking and running workouts, the pace for your walk/run shows up in the
Avg Cadence
column - Elevation will show up in the
Total Output
column
🎉 Kudos to Dena for reporting this bug!
- Added a Non-Cycling page to show stats around your non-cycling workouts
- View 10 most recent non-cycling workouts, total minutes by month, and avg. start time
🎉 Kudos to Mat for the suggestion!
tl;dr: I'll no longer be updating the Google Apps Script. I'll be updating the Peloton Pack in Coda with new features going forward. The template uses the Peloton Pack and the Google Apps Script won't work with this template anymore.
- Your Peloton data is now synced using the Peloton Pack (native integration with Coda)
- The Google Apps script, Python script, and old tables are stored in the Archive / Deprecated page
- Instructions for how to use the Peloton Pack are on the Packs page or see Your Peloton Data
- To authenticate the Peloton Pack, enter your Peloton credentials here and copy/paste your
User ID
andCookie
into the Peloton Pack - The new sync tables in Synced Workouts, Synced Friends, Synced Friend Workouts, and Synced Instructors can be refreshed manually, daily, or hourly (go to Insert→Packs→Peloton→Settings)
Here's a video tutorial on how the Peloton Pack works in Coda
- Fixed issue with Google Apps Script only where only 100 workouts were being returned from API
- Added friends' latest cycling workouts to Google Apps Script
- New table
Friend Workouts
contains latest 10 cycling workouts from people you follow Friends' Cycling Leaderboard
shows how your stats compare with those of your friends
- Added a monthly view of your cycling workouts to the Cycling dashboard (see Monthly Cycling Stats)
- Added monthly charts to the Cycling dashboard as well
- Added pie chart of all workouts by instructors to Cycling (see Workouts by instructor)
- Some tidying up: collapsed some charts and views in Cycling
- Fixed Google Apps Script to account for a variety of other workouts
There are two scripts in this repo you can run to sync your Peloton workout data to a Coda doc. One script is meant to be run in Google Apps Scripts and the other is a Python script you can run as a traditional cron job:
- peloton_coda_gas.js - For Google Apps Script (gist)
- peloton_coda_python.py - Python script to run locally or in the cloud as a cron job (gist)
Starting in line 10 to line 13 of the peloton_coda_gas.js script, you'll need to enter in some of your own data to make the script work.
CodaAPI.authenticate('YOUR_CODA_API_KEY')
CODA_DOC_ID = 'YOUR_CODA_DOC_ID'
PELOTON_USERNAME = 'YOUR_PELOTON_USERNAME'
PELOTON_PASSWORD = 'YOUR_PELOTON_PASSWORD'
Step-by-step:
- Go to script.google.com and create a new project and give your project a name.
- Click on Libraries and enter the following string into the "Script ID" field:
15IQuWOk8MqT50FDWomh57UqWGH23gjsWVWYFms3ton6L-UHmefYHS9Vl
. Note: If you are using the legacy Google Apps Scripted editor, go to Libraries then Resources in the toolbar. - Click Lookup and then select version 9 of library to use (as of January 2021, version 9 - Coda API v1.0.0 is the latest). Don't touch the other settings. Click Add.
- Copy and paste the entire script into your Google Apps Script editor (by default, the script name is "Code.gs")
- Go to your Coda account settings, scroll down until you see "API SETTINGS" and click Generate API Token. Copy and paste that API token into the value for
YOUR_CODA_API_KEY
in the script. Note: do not delete the single apostrophes aroundYOUR_CODA_API_KEY
. - Make a copy of this template if you haven't already.
- In the Coda doc you created, go to the "All Workouts" page and delete all the dummy data by clicking the Clear example data button.
- Get the the doc ID from your Coda doc by copying and pasting all the characters after the
_d
in the URL of your Coda doc (should be about 10 characters). You can also use the Doc ID Extractor tool in the Coda API docs. Copy and paste your doc ID intoYOUR_CODA_DOC_ID
in the script. - Fill in your Peloton username and password in
YOUR_PELOTON_USERNAME
andYOUR_PELOTON_PASSWORD
(remember to keep the single quotes around both values). - Click the dropdown menu next to the Debug button in the toolbar and select the
runPelotonSync
option. - Click the Run
▶️ button and this sync all your Peloton workout data to the Workouts table in your Coda doc. Google may ask you to approve some permissions. You will get a message saying "Google hasn't verified this app." Click on Advanced and click on Go to (script name) to proceed). - Get the script to run daily by clicking on the clock 🕒 icon on the left sidebar and set up a time-driven trigger.
- Click create a new trigger, make sure
runPelotonSync
is set as the function to run, "Select event source" should beTime-driven
, and the type to "Hour timer."
You have more flexibility with where and how you run the Python script. The steps below is one method for setting up a serverless function to run on Google Cloud Platform.
Step-by-step:
- Set up a Google Cloud Platform project and enable the Cloud Functions API and Cloud Scheduler API.
- Create a Google Cloud Function and check "Allow unauthenticated invocations":
- In the source code, select "Python 3.7" as the "Runtime" and edit the "Entry point" to a name like
runPelotonSync
. - Copy and paste the whole Python script into
main.py.
- Above line 19, "wrap" the whole script within a function like
pelotonData
(you may have to indent all the code below the function declaration):
def pelotonData(request):
# Current workout IDs
table_name = 'Workouts'
headers = {'Authorization': 'Bearer ' + api_key}
current_workout_ids = []
...
- Click Deploy at the bottom of the screen and wait until you see the green checkmark in the Google Cloud Functions list.
- Click into your new function and click Trigger to get the URL for triggering the script to run.
- Set up a Google Cloud Scheduler job to run the script every day, week, etc. You would set the "Target" in the Cloud Scheduler job with the URL you got from your Google Cloud Function.
- The Peloton API used in these scripts are unofficial, so there is no documentation from Peloton regarding the use of their API. They may change the API at any point in time.
- Don't be too aggressive with how often you run either script. Peloton may start rate-limiting you.
- Don't share your Coda API key and Peloton login details
- Props to @geudrik and his Peloton Client Library. Use his library if you want to develop a custom application with your Peloton data.