API access to Intervals.icu

It is working for me. Are some activities missing? Can you see the same on your calendar?

Solved, thanks. that was my problem.

You can now download planned workouts:

GET /api/v1/athlete/{id}/events/{eventId}/download{ext} Download a planned workout in .zwo, .mrc or .erg format.

1 Like

Some changes to the endpoints that create/update workouts on the calendar and in folders:

  • The workout description is now parsed. This means that workouts created or updated via the API have training load calculated and get “time in zones” and so on. This also applies to workouts synced from an external calendar.
  • You can now create/update workouts from zwo, mrc and erg files.

POST /api/v1/athlete/{id}/events

{
  "category": "WORKOUT",
  "start_date_local": "2021-04-29T00:00:00",
  "type": "Ride",
  "filename": "4x8m.zwo",
  "file_contents": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<workout_file>..."
}

Response:

{
  "id": 610062,
  "icu_training_load": 116,
  ...
  "name": "4x8m VO2 Max",
  "description": "These are horribly nasty.\nCategory: Horrible\n\n- 20m 60% 90-100rpm\n\nMain set 4x\n- 8m 110%\n- 8m 50%\n\n- 10m 60%\n",
  ...
  "workout_doc": {
    "steps": [
      {
        "power": {"units": "%ftp", "value": 60},
        "cadence": {"end": 100, "start": 90, "units": "rpm"}, "duration": 1200
      }, ...
    ],
    "duration": 5640,
    "zoneTimes": [1920, 1800, 0, 0, 1920, 0, 0, 0],
    "hrZoneTimes": [1920, 1800, 0, 0, 1920, 0, 0, 0]
  },
  "icu_intensity": 86.04798
}
2 Likes

Is there an endpoint to post .fit files to?

For completed activities or planned workouts? You can upload completed activities:

POST /v1/athlete/{id}/activities

This accepts form data with ‘file’ containing the data as well as optional name and description fields. The file can be .fit, .gpx, .fit.gz, .gpx.gz or a zip file containing one or more of the same.

It won’t create duplicate activities (hash of file data is checked). It returns status code 201 if at least one activity was created, else 200. The body is an array of { icu_athlete_id, id } for each activity.

3 Likes

This is really interesting! Thanks for all the great work.
Having a play with this, is there a way to get just the last activity full data set instead of all of them, for the activities.csv endpoint?
Cheers!

Tx. You can do:

GET /api/v1/athlete/{id}/activities?oldest=2019-07-22T16:18:49&newest=2019-08-23T12:18:24

To list activities in JSON format between 2 local dates in local date order.

GET /api/v1/activity/{id} to get a single activity in JSON format
GET /api/v1/activity/{id}/file to get the raw file for a single activity (if available)

You can also upload new activities:

POST /api/v1/athlete/{id}/activities

Accepts form data with ‘file’ being the fit, gpx or tax file. Also optional name and description. De-dups uploaded files on content hash.

1 Like

G’day david,

I’m encountering an issue with the activities.csv export.

Seemingly at random, some rows have too many columns.

Here is an example.

Inspecting the .csv, here is the plain text content for row 7:

...,false,false,false,1728,,,,,,,145,143,10897,717,..."

It would appear that between icu_recording_time and icu_pm_cp there ought to be six commas, but there are seven for some reason.

This exhibits itself randomly throughout my csv file.

Cheers!

Tx. I have fixed this for deploy Friday AM (GMT+2). Rows with no hrrc data were shifted over. Sorry about that.

Hi David;

Top work as always - is there a way to get headline stats for any of the riders you coach?

Ross

You mean for all of them at once or an individual athlete? What stats are you looking for?

Hi David,
Thanks for coming back to me -
I’m thinking an endpoint like /coach/overview
which would return the data found on this part of the screen
image

Assume it would be like
athletes: {
id : { fitneess: X , fatigue: X, Form: X, Weight: X, last7day: { load: x, hours: float },
id : { fitneess: X , fatigue: X, Form: X, Weight: X, last7day: { load: x, hours: float },
repeats for all coached riders
}

Something like the CSV link on that page? I have just added that to the API (will deploy Tues AM GMT+2):

GET /api/v1/athlete/{id}/athlete-summary{ext}?start=yyyy-MM-dd&end=yyyy-MM-dd

  • Calculates totals by week
  • Fitness, fatigue and form are as of the last activity completed in the week which may not be the last day of the week
  • ext is .csv for CSV output and JSON otherwise
  • tags Optional comma separated list of athlete tags to only return those athletes

Note that the format of this is going to change. I still need to change ‘byCategory’ to bySport and include time in zones for power, HR and pace separately etc…

2 Likes

Hi -
How do I go about pulling planned activities for only today? eg: Today’s workout much like TP’s workout of the day

I tried to use this URL
https://intervals.icu/api/v1/athlete/{id}/events?oldest=2021-09-07&newest=2021-09-07

I placed 2 workouts, one on sept6 and sept7, I would like to get the activityID for only sept7 (which is today)

I can only get it to work if I put tomorrow’s date.
eg:
https://intervals.icu/api/v1/athlete/{id}/events?oldest=2021-09-08&newest=2021-09-08

@David could you please let me know what I’m doing wrong? Appreciate it. Thanks

I have fixed this. It would have worked if you included a time in newest e.g. 2021-09-07T23:59:59. The server now does that automatically.

TQ! I could have sworn that I saw in a post somewhere that it was just the date w/o the time included as well.

in any case, Appreciate the help.

Hi @david

I was testing my app’s abiity to get the workouts for Today(WOD). Same like previous, i only have workouts on Sept6 and Sept7 (workoutname is same as the date to make it easier to understand)

Is the following expected given that you have indicated that the “server now does this automatically”?

In any case, knowing how the API expects the date, it’s no issue for me to do the “T23:59:59” (Which I am doing now and works)

intervals.icu/api/v1/athlete/{ID}/events?oldest=2021-09-05&newest=2021-09-05
No workouts

intervals.icu/api/v1/athlete/{ID}/events?oldest=2021-09-06&newest=2021-09-06
WorkoutName:Sept6

intervals.icu/api/v1/athlete/{ID}/events?oldest=2021-09-07&newest=2021-09-07
WorkoutName:Sept6

intervals.icu/api/v1/athlete/{ID}/events?oldest=2021-09-08&newest=2021-09-08
WorkoutName:Sept7

intervals.icu/api/v1/athlete/{ID}/events?oldest=2021-09-09&newest=2021-09-09
No Workout

intervals.icu/api/v1/athlete/{ID}/events?oldest=2021-09-05T00:00:00&newest=2021-09-05T23:59:59
No Workouts

intervals.icu/api/v1/athlete/{ID}/events?oldest=2021-09-06T00:00:00&newest=2021-09-06T23:59:59
WorkoutName:Sept6

intervals.icu/api/v1/athlete/{ID}/events?oldest=2021-09-07T00:00:00&newest=2021-09-07T23:59:59
WorkoutName:Sept7

intervals.icu/api/v1/athlete/{ID}/events?oldest=2021-09-08T00:00:00&newest=2021-09-08T23:59:59
No Workout

Looks like I have a few bugs to fix if you don’t supply time with the date.

Thanks @david no issues here as the format is now known.
Don’t worry about fixing it.

1 Like