### GET Request Example for v1 Metrics Endpoint Source: https://github.com/trainingpeaks/partnersapi/wiki/Metrics-Get-Athlete-Metrics Demonstrates how to make a GET request to the obsolete v1/metrics endpoint to retrieve athlete metrics within a specified date range. This endpoint requires an Athlete ID, start date, and end date. Note that this endpoint is deprecated. ```HTTP GET https://api.sandbox.trainingpeaks.com/v1/metrics/123456/2017-01-01/2017-01-04 GET https://api.trainingpeaks.com/v1/metrics/123456/2017-01-01/2017-01-04 ``` -------------------------------- ### Fetch Updated Workouts (API Request Example) Source: https://github.com/trainingpeaks/partnersapi/wiki/Workouts-Get-Changed This example demonstrates how to make a GET request to the TrainingPeaks API to retrieve workouts that have been modified or deleted since a given date. It shows the structure of the request URL including query parameters for date, page size, and page number. ```HTTP GET /v2/workouts/changes?date=2017-10-01&pageSize=50&page=0 HTTP/1.1 Host: api.sandbox.trainingpeaks.com Authorization: Bearer YOUR_ACCESS_TOKEN ``` -------------------------------- ### Retrieve Workouts of the Day - API Examples Source: https://github.com/trainingpeaks/partnersapi/wiki/Workout-Of-The-Day-Get Examples demonstrating how to call the Workouts of the Day endpoint for both sandbox and production environments. These examples show basic date retrieval and retrieval with the numberOfDays parameter. ```HTTP https://api.sandbox.trainingpeaks.com/v2/workouts/wod/2017-01-04 https://api.sandbox.trainingpeaks.com/v2/workouts/wod/2017-01-04?numberOfDays=3 https://api.trainingpeaks.com/v2/workouts/wod/2017-01-04 https://api.trainingpeaks.com/v2/workouts/wod/2017-01-04?numberOfDays=3 ``` -------------------------------- ### Example API Request URLs Source: https://github.com/trainingpeaks/partnersapi/wiki/Coach-Get-Athlete-Zones-by-Type Examples of how to construct the API request URL for both sandbox and production environments, including placeholders for athlete ID and zone type. ```URL https://api.sandbox.trainingpeaks.com/v1/coach/athletes/{athlete_id}/zones/{zone_type} ``` ```URL https://api.trainingpeaks.com/v1/coach/athletes/{athlete_id}/zones/{zone_type} ``` -------------------------------- ### Workout Data Structure - JSON Example Source: https://github.com/trainingpeaks/partnersapi/wiki/Workout-Of-The-Day-Get An example of the JSON structure returned by the Workouts of the Day API endpoint. This illustrates the properties available for each workout, such as planned distance, ID, start time, and workout type. ```JSON [ { "DistancePlanned": 100000, "Id": 139283664, "IFPlanned": null, "StartTimePlanned": "2014-04-15T12:57:59", "TotalTimePlanned": 1, "TssPlanned": 80, "WorkoutFileFormats":["erg","fit","mrc","zwo", "json"], "WorkoutType": "Bike" } ] ``` -------------------------------- ### Retrieve Workout Mean Max Data - API Request Example Source: https://github.com/trainingpeaks/partnersapi/wiki/Workouts-Get-Athlete-Mean-Max-Data This example demonstrates how to construct a GET request to the TrainingPeaks Partners API to retrieve mean max data for a specific athlete's workout. It includes placeholders for the athlete ID and workout ID. ```HTTP GET https://api.trainingpeaks.com/v2/workouts/{athleteid}/id/{id}/meanmaxes ``` -------------------------------- ### TrainingPeaks API File Upload Endpoint Examples Source: https://github.com/trainingpeaks/partnersapi/wiki/Uploaded-Workout-File-Data Examples of the TrainingPeaks API endpoint for file uploads in both sandbox and production environments. ```HTTP https://api.sandbox.trainingpeaks.com/v3/file https://api.trainingpeaks.com/v3/file ``` -------------------------------- ### Example Workout File Request URLs Source: https://github.com/trainingpeaks/partnersapi/wiki/Workout-Of-The-Day-Structured-Workout-File Examples of constructing URLs for requesting workout files in the 'mrc' format for both testing (sandbox) and production environments. Replace '{workout id}' with the actual workout identifier. ```URL https://api.sandbox.trainingpeaks.com/v2/workouts/wod/file/123456789/?format=mrc ``` ```URL https://api.trainingpeaks.com/v2/workouts/wod/file/123456789/?format=mrc ``` -------------------------------- ### Example Subscription Response (JSON) Source: https://github.com/trainingpeaks/partnersapi/wiki/Webhook-Get-Subscriptions An example of the JSON response structure when successfully retrieving webhook subscriptions. Each object in the array represents a single subscription with details like Id, AthleteId, EventType, WebhookUrl, and status. ```json [ { "Id": "0d76e887-8e8a-46f4-bb2b-2f66e4fc40ee", "AthleteId": 54321, "EventType": "workout-created", "WebhookUrl": "https://api.mycompany.com/callback", "Active": true, "CreatedBy": 54321, "CreatedOn": "2025-07-24T21:03:05.1324848Z" } ] ``` -------------------------------- ### GET /v2/workouts/{athleteId}/{start date}/{end date} Source: https://github.com/trainingpeaks/partnersapi/wiki/Workouts-Get-Athlete-Workouts Retrieves a list of workouts for a given athlete within a specified date range. The end date cannot be more than 365 days in the future, and the difference between the start and end dates cannot exceed 45 days. ```APIDOC ## GET /v2/workouts/{athleteId}/{start date}/{end date} ### Description Retrieves a list of workouts for a given athlete within a specified date range. The end date cannot be more than 365 days in the future, and the difference between the start and end dates cannot exceed 45 days. ### Method GET ### Endpoint /v2/workouts/{athleteId}/{start date}/{end date} ### Parameters #### Path Parameters - **athleteId** (string) - Required - The ID of the athlete. - **startDate** (string) - Required - The start date in local time (YYYY-MM-DD). - **endDate** (string) - Required - The end date in local time (YYYY-MM-DD). #### Query Parameters - **includeDescription** (boolean) - Optional - Whether to include the workout description in the response. ### Request Example ``` https://api.sandbox.trainingpeaks.com/v2/workouts/123456/2017-01-01/2017-01-04?includeDescription=true ``` ### Response #### Success Response (200) - **workouts** (array) - An array of workout objects. #### Response Example ```json [ { "Distance": 100000, "Id": 139283664, "StartTime": "2014-04-15T12:57:59", "TotalTime": 1.25, "WorkoutType": "Bike" } ] ``` ``` -------------------------------- ### GET /v2/workouts/{start date}/{end date} Source: https://github.com/trainingpeaks/partnersapi/wiki/Workouts-Get Retrieves a list of workouts for a given athlete within a specified date range. This is useful for verifying existing workouts before uploading new ones. ```APIDOC ## GET /v2/workouts/{start date}/{end date} ### Description Returns a list of workouts for the date range from an athlete’s calendar. This method will be made available to services and apps that upload workout files and are required to verify that a duplicate workout does not already exist in the athlete’s account. ### Method GET ### Endpoint /v2/workouts/{start date}/{end date} ### Parameters #### Path Parameters - **start date** (string) - Required - Start date in local time (YYYY-MM-DD). - **end date** (string) - Required - End date in local time (YYYY-MM-DD). #### Query Parameters - **includeDescription** (boolean) - Optional - Include the workout Description in the response. ### Notes - The end date cannot be more than 365 days in the future. - The delta between the start date and end date cannot be more than 45 days. ### Request Example ``` https://api.sandbox.trainingpeaks.com/v2/workouts/2017-01-01/2017-01-04 ``` ### Response #### Success Response (200) - An array of workouts. See the [Workouts Object](Workouts-Object) for a complete list of properties. #### Response Example ```json [ { "Distance": 100000, "Id": 139283664, "StartTime": "2014-04-15T12:57:59", "TotalTime": 1.25, "WorkoutType": "Bike" } ] ``` ``` -------------------------------- ### Example Token Response from TrainingPeaks Source: https://github.com/trainingpeaks/partnersapi/wiki/OAuth This is an example of the JSON response received from the TrainingPeaks OAuth server after successfully exchanging an authorization code for tokens. It contains the access token, token type, expiration time, refresh token, and granted scopes. ```JSON { "access_token" : "gAAAAMYien...", "token_type" : "bearer", "expires_in" : 600, "refresh_token" : "i7ne!IAAA...", "scope": "scopes granted" } ``` -------------------------------- ### GET /v1/info/version Source: https://github.com/trainingpeaks/partnersapi/wiki/Info-Version Retrieves the current version and build configuration of the API. ```APIDOC ## GET /v1/info/version ### Description Returns the version string and build configuration details for the API. ### Method GET ### Endpoint /v1/info/version ### Parameters None ### Request Example N/A ### Response #### Success Response (200) - **Version** (string) - The current version string of the API. - **Build** (string) - The version SHA build hash and build configuration. #### Response Example { "Version": "2.0.1234.0", "Build": "2.0.1234 1abcd2345 Release" } ``` -------------------------------- ### Fetch Workouts by Date Range - API Request Source: https://github.com/trainingpeaks/partnersapi/wiki/Workouts-Get This snippet demonstrates how to make a GET request to the TrainingPeaks Partners API to retrieve a list of workouts within a specified date range. It requires start and end dates and optionally accepts includeDescription. Note the constraints on date ranges. ```HTTP GET /v2/workouts/2017-01-01/2017-01-04?includeDescription=true HTTP/1.1 Host: api.sandbox.trainingpeaks.com Authorization: Bearer YOUR_ACCESS_TOKEN ``` -------------------------------- ### Example Athlete Profile Response (JSON) Source: https://github.com/trainingpeaks/partnersapi/wiki/Coach-Get-Assistant-Athletes This is an example of the JSON response structure returned by the API when requesting a list of athletes for an assistant coach. Each object in the array represents an athlete's profile, including their ID, name, email, and the ID of the coach they are assigned to. ```JSON [ { "Id": 123456, "FirstName": "John1", "LastName": "Doe1", "Email": "john.doe@gmail.com", "CoachedBy": 987654 }, { "Id": 123457, "FirstName": "John2", "LastName": "Doe2", "Email": "john.doe2@yahoo.com", "CoachedBy": 987653 }, { "Id": 1234568, "FirstName": "John3", "LastName": "Doe3", "Email": "doe3@yahoo.com", "CoachedBy": 987654 } ] ``` -------------------------------- ### Retrieve Workout Details via GET Request Source: https://github.com/trainingpeaks/partnersapi/wiki/Workouts-Get-Details This snippet demonstrates the HTTP GET request structure to fetch detailed workout data. Replace {id} with the specific workout identifier. ```http GET /v2/workouts/id/{id}/details HTTP/1.1 Host: api.trainingpeaks.com Authorization: Bearer ``` -------------------------------- ### GET /v2/metrics/{start date}/{end date} Source: https://github.com/trainingpeaks/partnersapi/wiki/v2-Metrics-Get-By-Date-Range Retrieves a list of athlete metrics recorded between the specified start and end dates. ```APIDOC ## GET /v2/metrics/{start date}/{end date} ### Description Retrieves athlete metric data for a specific date range. The response includes various metrics like weight, HRV, and sleep data if available. ### Method GET ### Endpoint /v2/metrics/{start date}/{end date} ### Parameters #### Path Parameters - **start date** (string) - Required - The start date in local time (YYYY-MM-DD). - **end date** (string) - Required - The end date in local time (YYYY-MM-DD). ### Request Example https://api.trainingpeaks.com/v2/metrics/2022-06-01/2022-06-10 ### Response #### Success Response (200) - **MetricId** (string) - Unique identifier for the metric entry. - **AthleteId** (int) - TrainingPeaks athlete identifier. - **DateTime** (string) - Local DateTime as recorded. - **UploadClient** (string) - The client application that uploaded the data. #### Response Example [ { "MetricId":"B3AADF1C-1380-4FFE-93D5-E67C3A3491A4", "AthleteId":123456, "DateTime": "2022-06-01T06:12:34", "UploadClient":"testapplication", "WeightInKilograms":68.1, "HRV":84.1, "Steps":12345, "Stress":"Low", "SleepQuality":"Good" } ] ``` -------------------------------- ### GET Request for Next Event - cURL Source: https://github.com/trainingpeaks/partnersapi/wiki/Event-Get-Next Example of how to make a GET request to the /v2/events/next endpoint using cURL. This retrieves the next event object for the authenticated athlete. Ensure you have the 'events:read' OAuth scope. ```bash curl -X GET \ 'https://api.sandbox.trainingpeaks.com/v2/events/next' \ -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' ``` -------------------------------- ### POST /v3/file Source: https://github.com/trainingpeaks/partnersapi/wiki/File-Upload-Asynchronous Uploads a new device file to a user account. Returns an Accepted status with a tracking URL. ```APIDOC ## POST /v3/file ### Description Uploads a new device file to a user account for processing. ### Method POST ### Endpoint /v3/file ### Parameters #### Request Body - **fileData** (binary) - Required - The workout file content to be uploaded. ### Request Example POST /v3/file Content-Type: application/octet-stream [Binary File Data] ### Response #### Success Response (202) - **Location** (header) - URL to check the status of the file upload. #### Response Example HTTP/1.1 202 Accepted Location: /v3/status/12345-abcde ``` -------------------------------- ### GET /v2/metrics/{athleteid}/{start date}/{end date} Source: https://github.com/trainingpeaks/partnersapi/wiki/v2-Metrics-Get-Athlete-Metrics Retrieves a list of metrics for a specific athlete within a defined date range. ```APIDOC ## GET /v2/metrics/{athleteid}/{start date}/{end date} ### Description Retrieves athlete metrics recorded between the specified start and end dates. ### Method GET ### Endpoint /v2/metrics/{athleteid}/{start date}/{end date} ### Parameters #### Path Parameters - **athleteid** (int) - Required - The unique identifier for the athlete. - **start date** (string) - Required - The start date in YYYY-MM-DD format. - **end date** (string) - Required - The end date in YYYY-MM-DD format. ### Request Example https://api.trainingpeaks.com/v2/metrics/123456/2022-06-01/2022-06-10 ### Response #### Success Response (200) - **MetricId** (string) - Unique identifier for the metric entry. - **AthleteId** (int) - The athlete identifier. - **DateTime** (string) - Local date and time of the recording. - **UploadClient** (string) - The application that uploaded the data. - **WeightInKilograms** (float) - Optional weight metric. - **HRV** (float) - Optional heart rate variability metric. - **Steps** (int) - Optional step count. - **Stress** (string) - Optional stress level. - **SleepQuality** (string) - Optional sleep quality description. #### Response Example [ { "MetricId": "B3AADF1C-1380-4FFE-93D5-E67C3A3491A4", "AthleteId": 123456, "DateTime": "2022-06-01T06:12:34", "UploadClient": "testapplication", "WeightInKilograms": 68.1, "HRV": 84.1, "Steps": 12345, "Stress": "Low", "SleepQuality": "Good" } ] ``` -------------------------------- ### Upload Workout File Asynchronously Source: https://context7.com/trainingpeaks/partnersapi/llms.txt Uploads a workout file (FIT, TCX, PWX) to an athlete's account. The process is asynchronous, returning a tracking URL to poll for completion status. ```bash curl -X POST https://api.trainingpeaks.com/v3/file \ -H "Authorization: Bearer ${ACCESS_TOKEN}" \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ -d '{ "UploadClient": "MyFitnessApp", "Filename": "2024-01-15-morning-ride.fit", "Data": "DhArAxU...[base64 encoded file content]...", "Title": "Morning Endurance Ride", "Comment": "Great weather, felt strong", "Type": "Bike", "WorkoutDay": "2024-01-15T00:00:00", "StartTime": "2024-01-15T06:30:00" }' curl -X GET https://api.trainingpeaks.com/v3/status/abc123-def456 \ -H "Authorization: Bearer ${ACCESS_TOKEN}" \ -H "Accept: application/json" ``` -------------------------------- ### GET /v1/metrics/{start date}/{end date} (Obsolete) Source: https://github.com/trainingpeaks/partnersapi/wiki/Metrics-Get-By-Date-Range This endpoint is obsolete and has been replaced by the v2/metrics endpoint. Please refer to the v2 documentation for current functionality. ```APIDOC ## GET /v1/metrics/{start date}/{end date} ### Description This endpoint retrieves metrics data within a specified date range. It is now obsolete and users should migrate to the v2/metrics endpoint. ### Method GET ### Endpoint /v1/metrics/{start date}/{end date} ### Parameters #### Path Parameters - **start date** (string) - Required - The start date for the metrics in local time (YYYY-MM-DD). - **end date** (string) - Required - The end date for the metrics in local time (YYYY-MM-DD). ### Request Example ``` https://api.sandbox.trainingpeaks.com/v1/metrics/2017-01-01/2017-01-04 ``` ### Response #### Success Response (200) - **MetricId** (int) - Unique ID for the metrics. - **AthleteId** (int) - TrainingPeaks athlete identifier. - **DateTime** (string) - UTC DateTime, truncated to the minute. - **TimeZoneId** (string) - IANA time zone id, optional. - **UploadClient** (string) - The client used for uploading. - **WeightInKilograms** (float) - Weight in kilograms. - **HRV** (float) - Heart Rate Variability. - **Steps** (int) - Number of steps. - **Stress** (string) - Stress level (e.g., "Low"). - **SleepQuality** (string) - Sleep quality (e.g., "Good"). - **SleepHours** (float) - Hours of sleep. - **Pulse** (int) - Resting pulse rate. #### Response Example ```json [ { "MetricId":987654321, "AthleteId":123456789, "DateTime":"2016-02-18T22:56:00Z", "TimeZoneId":"America/Denver", "UploadClient":"testapplication", "WeightInKilograms":68.1, "HRV":84.1, "Steps":12345, "Stress":"Low", "SleepQuality":"Good" }, { "MetricId":987654322, "AthleteId":123456789, "DateTime":"2016-02-19T00:56:00Z", "TimeZoneId":"America/Denver", "UploadClient":"testapplication2", "SleepHours" : 8, "Pulse" : 45 } ] ``` ### Note Not every field will be returned for every metric, and new fields may be added in the future. It is recommended to check that a key exists before accessing its value. ``` -------------------------------- ### POST /v2/workouts/plan Source: https://github.com/trainingpeaks/partnersapi/wiki/Workouts-Create Create a new planned workout on an athlete's calendar. ```APIDOC ## POST /v2/workouts/plan ### Description Allows a coach or athlete to plan workouts on an athlete’s calendar. Note that creating future planned workouts for basic athletes will result in a 403 status code. ### Method POST ### Endpoint /v2/workouts/plan ### Parameters #### Request Body - **AthleteId** (string) - Required - The unique identifier of the athlete. - **WorkoutDay** (string) - Required - The date of the workout (yyyy-MM-dd). Must be within 7 days past or 1 year future. - **WorkoutType** (string) - Required - Type of workout (swim, bike, run, x-train, mtb, strength, xc-ski, rowing, walk, other). - **Title** (string) - Optional - Title of the workout. - **Description** (string) - Optional - Description of the workout. - **StartTimePlanned** (string) - Optional - Planned start time (yyyy-MM-dd HH:mm:ss). - **TotalTimePlanned** (double) - Optional - Planned duration in decimal hours. - **DistancePlanned** (double) - Optional - Planned distance in meters. - **TSSPlanned** (double) - Optional - Planned Training Stress Score. - **IFPlanned** (double) - Optional - Planned Intensity Factor. - **Locked** (bool) - Optional - Lock status (coaches only). - **Hidden** (bool) - Optional - Hidden status (coaches only). - **Structure** (json) - Optional - Workout structure object. ### Request Example { "AthleteId": "12345", "WorkoutDay": "2023-12-01", "WorkoutType": "run", "Title": "Morning Run", "TotalTimePlanned": 1.5 } ### Response #### Success Response (200) - **WorkoutId** (string) - The ID of the created workout. #### Response Example { "WorkoutId": "abc-123-xyz" } ``` -------------------------------- ### Retrieve Athlete Metrics (GET Request) Source: https://github.com/trainingpeaks/partnersapi/wiki/v2-Metrics-Get-Athlete-Metrics This snippet demonstrates how to make a GET request to the TrainingPeaks API to retrieve athlete metrics within a specified date range. It requires an Athlete ID, start date, and end date. The response is a JSON array containing metric data. ```HTTP GET https://api.sandbox.trainingpeaks.com/v2/metrics/123456/2022-06-01/2022-06-10 ``` ```HTTP GET https://api.trainingpeaks.com/v2/metrics/123456/2022-06-01/2022-06-10 ``` -------------------------------- ### GET Athlete Profile - API Request Example Source: https://github.com/trainingpeaks/partnersapi/wiki/Athlete-Get-Profile This snippet shows how to make a GET request to the /v1/athlete/profile endpoint to retrieve an athlete's profile information. It requires the 'athlete:profile' scope. The response is a JSON object containing details like ID, name, email, and other profile attributes. ```HTTP GET https://api.sandbox.trainingpeaks.com/v1/athlete/profile GET https://api.trainingpeaks.com/v1/athlete/profile ``` -------------------------------- ### Retrieve Changed Workouts (API Example) Source: https://github.com/trainingpeaks/partnersapi/wiki/Workouts-Get-Athlete-Changes This snippet demonstrates how to call the Workouts API to get a list of workouts that have been modified or deleted for a specific athlete since a given date. It includes example URLs for testing and production environments. The API returns separate lists for deleted workout IDs and modified workout objects. ```HTTP https://api.sandbox.trainingpeaks.com/v2/workouts/changes/123456/2017-10-01?pageSize=50&page0 https://api.trainingpeaks.com/v2/workouts/changes/123456/2017-10-01?pageSize=50&page0 ``` -------------------------------- ### Fetch Structured Workout File (GET Request) Source: https://github.com/trainingpeaks/partnersapi/wiki/Workout-Of-The-Day-Structured-Workout-File This snippet demonstrates how to make a GET request to retrieve a structured workout file in a specified format. The endpoint requires a workout ID and a format parameter. Supported formats include erg, fit, mrc, zwo, and json. Ensure you have the 'workouts:wod' OAuth scope. ```HTTP GET /v2/workouts/wod/file/{workout id}/?format={format} HTTP/1.1 Host: api.sandbox.trainingpeaks.com Authorization: Bearer YOUR_ACCESS_TOKEN ``` -------------------------------- ### Obsolete: GET /v1/metrics/{athleteid}/{start date}/{end date} Source: https://github.com/trainingpeaks/partnersapi/wiki/Metrics-Get-Athlete-Metrics This endpoint is obsolete and has been replaced by the v2/metrics endpoint. It was used to retrieve athlete metrics within a specified date range. ```APIDOC ## GET /v1/metrics/{athleteid}/{start date}/{end date} ### Description This endpoint is obsolete. Please see [v2/metrics](v2-Metrics-Get-Athlete-Metrics) for more details. It was used to retrieve athlete metrics within a specified date range. ### Method GET ### Endpoint /v1/metrics/{athleteid}/{start date}/{end date} ### Parameters #### Path Parameters - **athleteid** (int) - Required - Athlete ID. - **start date** (date) - Required - Start date in local time (YYYY-MM-DD). - **end date** (date) - Required - End date in local time (YYYY-MM-DD). ### Request Example ``` Testing: https://api.sandbox.trainingpeaks.com/v1/metrics/123456/2017-01-01/2017-01-04 Production: https://api.trainingpeaks.com/v1/metrics/123456/2017-01-01/2017-01-04 ``` ### Response #### Success Response (200) - **MetricId** (int) - Unique ID for the metrics. - **AthleteId** (int) - TrainingPeaks athlete identifier. - **DateTime** (string) - UTC DateTime, truncated to the minute. - **TimeZoneId** (string) - IANA time zone id, optional. - **UploadClient** (string) - The client used for uploading. - **WeightInKilograms** (float) - Athlete's weight in kilograms. - **HRV** (float) - Heart Rate Variability. - **Steps** (int) - Number of steps taken. - **Stress** (string) - Stress level (e.g., "Low", "Medium", "High"). - **SleepQuality** (string) - Quality of sleep (e.g., "Good", "Fair", "Poor"). - **SleepHours** (float) - Hours of sleep. - **Pulse** (int) - Resting heart rate. *Note: Not every field will be returned for every metric, and new fields may be added in the future. It is recommended to check that a key exists before accessing its value.* #### Response Example ```json [ { "MetricId":987654321, "AthleteId":123456789, "DateTime":"2016-02-18T22:56:00Z", "TimeZoneId":"America/Denver", "UploadClient":"testapplication", "WeightInKilograms":68.1, "HRV":84.1, "Steps":12345, "Stress":"Low", "SleepQuality":"Good" }, { "MetricId":987654322, "AthleteId":123456789, "DateTime":"2016-02-19T00:56:00Z", "TimeZoneId":"America/Denver", "UploadClient":"testapplication2", "SleepHours" : 8, "Pulse" : 45 } ] ``` ``` -------------------------------- ### GET /OAuth/Authorize Source: https://github.com/trainingpeaks/partnersapi/wiki/OAuth Initiates the 3-legged OAuth flow by redirecting the user to the TrainingPeaks authorization server to grant permissions. ```APIDOC ## GET /OAuth/Authorize ### Description Redirects the user to the TrainingPeaks authorization page to request access to specific scopes. ### Method GET ### Endpoint https://oauth.sandbox.trainingpeaks.com/OAuth/Authorize ### Parameters #### Query Parameters - **response_type** (string) - Required - Must be 'code'. - **client_id** (string) - Required - Your unique application identifier. - **scope** (string) - Required - Space-delimited list of requested permissions. - **redirect_uri** (string) - Required - The URI to redirect to after authorization. ### Request Example GET https://oauth.sandbox.trainingpeaks.com/OAuth/Authorize?response_type=code&client_id=my_client_id&scope=workouts%3Aread&redirect_uri=https%3A%2F%2Fmyapp.com%2Fcallback ``` -------------------------------- ### Retrieve Workout by ID via GET Request Source: https://github.com/trainingpeaks/partnersapi/wiki/Workouts-Get-By-Id Demonstrates the endpoint URL structure for both sandbox and production environments. The request returns a JSON object containing workout properties such as distance, start time, and type. ```http GET /v2/workouts/id/123456789 HTTP/1.1 Host: api.trainingpeaks.com Authorization: Bearer ``` ```json [ { "Distance": 100000, "Id": 123456789, "StartTime": "2014-04-15T12:57:59", "TotalTime": 1.25, "WorkoutType": "Bike" } ] ``` -------------------------------- ### Retrieve Workout by ID via HTTP GET Source: https://github.com/trainingpeaks/partnersapi/wiki/Workouts-Get-Athlete-Workouts-By-Id Fetches a workout object from the TrainingPeaks API. Requires valid athlete and workout IDs, returning a JSON object containing workout details like distance, start time, and type. ```http GET /v2/workouts/54321/id/123456789 HTTP/1.1 Host: api.trainingpeaks.com Authorization: Bearer ``` ```json [ { "Distance": 100000, "Id": 123456789, "StartTime": "2014-04-15T12:57:59", "TotalTime": 1.25, "WorkoutType": "Bike" } ] ``` -------------------------------- ### Structured Workout Data Format Source: https://github.com/trainingpeaks/partnersapi/wiki/Workouts-Create An example JSON object representing a structured workout plan. This format allows for detailed specification of workout steps, including intensity, duration, and targets. ```JSON { "AthleteId": "134129", "Title": "Example Plan", "WorkoutDay": "2017-06-26", "TotalTimePlanned": "1", "WorkoutType": "run", "Structure": "[ { \"IntensityClass\": \"WarmUp\", \"Name\": \"Warm up\", \"Length\": { \"Unit\": \"Second\", \"Value\": 600 }, \"Type\": \"Step\", \"IntensityTarget\": { \"Unit\": \"PercentOfThresholdHr\", \"Value\": 75, \"MinValue\": 70, \"MaxValue\": 80 } }, { \"IntensityClass\": \"Active\", \"Name\": \"Active\", \"Length\": { \"Unit\": \"Second\", \"Value\": 2095 }, \"Type\": \"Step\", \"IntensityTarget\": { \"Unit\": \"PercentOfThresholdHr\", \"Value\": 90, \"MinValue\": 80, \"MaxValue\": 100 } }, { \"Type\": \"Repetition\", \"Length\": { \"Unit\": \"Repetition\", \"Value\": 3 }, \"Steps\": [ { \"IntensityClass\": \"Active\", \"Name\": \"Hard\", \"Length\": { \"Unit\": \"Second\", \"Value\": 60 }, \"Type\": \"Step\", \"IntensityTarget\": { \"Unit\": \"PercentOfThresholdHr\", \"Value\": 115 }, \"CadenceTarget\": { \"Unit\": \"rpm\", \"MinValue\": 70, \"MaxValue\": 80 } }, { \"IntensityClass\": \"Rest\", \"Name\": \"Easy\", \"Length\": { \"Unit\": \"Second\", \"Value\": 60 }, \"Type\": \"Step\", \"IntensityTarget\": { \"Unit\": \"PercentOfThresholdHr\", \"Value\": 70 } } ] }, { \"IntensityClass\": \"CoolDown\", \"Name\": \"Cool Down\", \"Length\": { \"Unit\": \"Second\", \"Value\": 600 }, \"Type\": \"Step\", \"IntensityTarget\": { \"Unit\": \"PercentOfThresholdHr\", \"Value\": 75 }, \"OpenDuration\": true }]", "Notes": "This is an example workout structure." } ``` -------------------------------- ### Create Webhook Subscription Source: https://context7.com/trainingpeaks/partnersapi/llms.txt Registers a webhook URL to receive real-time notifications for specific workout events. Requires the 'webhook:write-subscriptions' scope. ```bash curl -X POST https://api.trainingpeaks.com/v1/webhook/subscriptions \ -H "Authorization: Bearer ${ACCESS_TOKEN}" \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ -d '{ "AthleteId": 123456, "EventType": "workout-created", "WebhookUrl": "https://api.myapp.com/webhooks/trainingpeaks" }' ``` -------------------------------- ### Retrieve Metrics Data (API Request) Source: https://github.com/trainingpeaks/partnersapi/wiki/v2-Metrics-Get-By-Date-Range This snippet demonstrates how to make a GET request to the TrainingPeaks API to fetch metric data for a specified date range. Ensure you have the 'metrics:read' scope authorized. The endpoint requires start and end dates in local time. ```HTTP GET https://api.trainingpeaks.com/v2/metrics/2022-06-01/2022-06-10 ``` -------------------------------- ### POST /v1/webhook/subscriptions Source: https://context7.com/trainingpeaks/partnersapi/llms.txt Creates a webhook subscription to receive real-time notifications for workout events. ```APIDOC ## POST /v1/webhook/subscriptions ### Description Creates a webhook subscription to receive real-time notifications when workouts are created, updated, or deleted. Requires the `webhook:write-subscriptions` scope. ### Method POST ### Endpoint https://api.trainingpeaks.com/v1/webhook/subscriptions ### Parameters #### Request Body - **AthleteId** (integer) - Required - The athlete to monitor. - **EventType** (string) - Required - Event type: workout-created, workout-updated, or workout-deleted. - **WebhookUrl** (string) - Required - The destination URL for notifications. ### Request Example { "AthleteId": 123456, "EventType": "workout-created", "WebhookUrl": "https://api.myapp.com/webhooks/trainingpeaks" } ### Response #### Success Response (200) - **Id** (string) - Subscription UUID. - **Active** (boolean) - Subscription status. #### Response Example { "Id": "0d76e887-8e8a-46f4-bb2b-2f66e4fc40ee", "Active": true } ``` -------------------------------- ### GET /v2/workouts/{startDate}/{endDate} Source: https://context7.com/trainingpeaks/partnersapi/llms.txt Returns a list of workouts from an athlete's calendar for the specified date range. The date range cannot exceed 45 days, and the end date cannot be more than 365 days in the future. ```APIDOC ## GET /v2/workouts/{startDate}/{endDate} ### Description Returns a list of workouts from an athlete's calendar for the specified date range. The date range cannot exceed 45 days, and the end date cannot be more than 365 days in the future. Requires the `workouts:read` scope. ### Method GET ### Endpoint /v2/workouts/{startDate}/{endDate} ### Parameters #### Path Parameters - **startDate** (string) - Required - The start date of the range in `YYYY-MM-DD` format. - **endDate** (string) - Required - The end date of the range in `YYYY-MM-DD` format. #### Query Parameters - **includeDescription** (boolean) - Optional - Whether to include the workout description. #### Headers - **Authorization** (string) - Required - Bearer token for authentication. - **Accept** (string) - Optional - `application/json` ### Request Example ```bash curl -X GET "https://api.trainingpeaks.com/v2/workouts/2024-01-01/2024-01-31?includeDescription=true" \ -H "Authorization: Bearer ${ACCESS_TOKEN}" \ -H "Accept: application/json" ``` ### Response #### Success Response (200) - **Array of Workout Objects**: Each object contains details about a workout, including: - **Id** (integer) - Unique identifier for the workout. - **AthleteId** (integer) - The ID of the athlete the workout belongs to. - **WorkoutDay** (string) - The date of the workout (ISO 8601 format). - **StartTime** (string) - The start time of the workout (ISO 8601 format). - **WorkoutType** (string) - The type of workout (e.g., "Bike", "Run"). - **Title** (string) - The title of the workout. - **Description** (string) - The description of the workout (if `includeDescription` is true). #### Response Example ```json [ { "Id": 139283664, "AthleteId": 123456, "WorkoutDay": "2024-01-15T00:00:00", "StartTime": "2024-01-15T12:57:59", "WorkoutType": "Bike", "Title": "Endurance Ride", "Description": "Zone 2 base building ride" } ] ``` ``` -------------------------------- ### Get API Version Info (GET /v1/info/version) Source: https://github.com/trainingpeaks/partnersapi/wiki/Info-Version This snippet demonstrates how to call the /v1/info/version endpoint to get the API's current version and build information. This endpoint requires no OAuth scope and returns a JSON object containing 'Version' and 'Build' fields. ```HTTP GET /v1/info/version ``` ```JSON { "Version": "2.0.1234.0", "Build": "2.0.1234 1abcd2345 Release" } ``` -------------------------------- ### JSON Payload for Workout File Upload Source: https://github.com/trainingpeaks/partnersapi/wiki/WorkoutDay-and-StartTime-overrides Example JSON payload for uploading workout files. This demonstrates how to include WorkoutDay and StartTime when local date/time is provided without a specific timezone. ```json { "UploadClient": "app_name", "Filename": "file_name.tcx", "Data": "encoded_content", "WorkoutDay": "2020-01-31", "StartTime": "2020-01-31T13:14:15" } ``` -------------------------------- ### GET /v2/workouts/changes/{since_date} Source: https://github.com/trainingpeaks/partnersapi/wiki/Workouts-Get-Changes Retrieves a list of workouts that have been updated or deleted since a specified date. This endpoint is deprecated and replaced by Workouts: Get Changed. ```APIDOC ## GET /v2/workouts/changes/{since_date} ### Description Returns a list of workouts that have been updated or deleted since the date provided. This will return two lists, one of deleted workout ids and another of workouts that have been modified. This endpoint is deprecated. ### Method GET ### Endpoint /v2/workouts/changes/{since_date} ### Parameters #### Path Parameters - **since_date** (string) - Required - The date in local time to retrieve changes since. Minimum date is 2000-01-01. #### Query Parameters - **pageSize** (int) - Optional - Number of results to return per request. Max 100. - **page** (int) - Optional - Zero-based index for paging. - **workoutTypeFilter** (string) - Optional - Filter to a specific workout type. ### Request Example ```json { "example": "https://api.sandbox.trainingpeaks.com/v2/workouts/changes/2017-10-01?pageSize=50&page=0" } ``` ### Response #### Success Response (200) - **Deleted** (array) - An array of deleted workout ids. - **Modified** (array) - An array of updated workouts, including properties like LastModifiedDate, Id, AthleteId, WorkoutType, Title, and WorkoutDay. #### Response Example ```json { "Deleted": [ 123456789 ], "Modified": [ { "LastModifiedDate": "2017-09-25T17:31:28.9428265Z", "Id": 234567890, "AthleteId": 12345, "WorkoutType": "Bike", "Title": null, "WorkoutDay": "2017-09-13T00:00:00" } ] } ``` ``` -------------------------------- ### GET /v2/workouts/wod/file/{workout id} Source: https://github.com/trainingpeaks/partnersapi/wiki/Workout-Of-The-Day-Structured-Workout-File Retrieves a structured workout file for a specific workout ID in a requested format. Requires the workouts:wod OAuth scope. ```APIDOC ## GET /v2/workouts/wod/file/{workout id} ### Description Returns a structured workout file for the specified workout ID in the requested format. The workout must be structured, otherwise a 400 error is returned. ### Method GET ### Endpoint /v2/workouts/wod/file/{workout id}/?format={format} ### Parameters #### Path Parameters - **workout id** (string) - Required - The unique identifier of the workout. #### Query Parameters - **format** (string) - Required - The file format requested (erg, fit, mrc, zwo, json). ### Request Example GET https://api.trainingpeaks.com/v2/workouts/wod/file/123456789/?format=mrc ### Response #### Success Response (200) - **Content-Disposition** (header) - attachment; filename="filename.ext" - **Body** (binary/json) - The workout file content. #### Response Example { "workout_data": "...binary content or json structure..." } ```