API access to Intervals.icu

I forgot to add the /api/ to each endpoint in the post (will edit now). This call just worked for me:

$ curl -u API_KEY:xxx https://intervals.icu/api/v1/athlete/2049151/folders

Perfect thanks David;

Is there a away of filtering the “events” call to only return from a single calendar? I have tried passing “calendar_id” as a param

Ross

I just added calendar_id param as you suggested. Will deploy Tues AM (GMT+2).

Do any of the current endpoints allow you to return fitness or form for a given day? I checked the information returned in the activity JSON and the calendar endpoint but I didn’t see anything.

Each activity should have icu_fitness and other related fields. Thats not quite what you are asking for but close.

Specifically this endpoint: /api/v1/athlete/{id}/activities.csv

ahh, I see that. To replicate the values on the fitness chart, though, I assume I would need to do the same calculations referenced in the descriptions for fitness and fatigue, which would require storing the data from the .csv data and essentially duplicating the great work you have here.

My goal was to pull in the fatigue/fitness/form into my Home Assistant server. If those values were available via an endpoint, I could do it via the API. I’d considered using an iframe for the fitness page but I don’t have a way to utilize the basic authentication that way.

No worries! It’s a pretty niche case.

I do plan to add that. At the moment the Intervals.icu client and server both “fill in the gaps” between activities when needed but I can easily add a “fitness” endpoint that has that done already.

2 Likes

Hi David,

When i try to pull it in Excel the authentication seems to work, however am I right, that I need to put my athlete ID in the adress and not “{id}”? Where can we find our own athlete id? So far I have not found it.

BR
Urs

I’ve not used the API yet but to get your ID just go Strava > My Profile
The ID is then just in the address. eg https://www.strava.com/athletes/35946345

35946345

(not me, I just smahed the keyboard aha)

1 Like

For any fellow R users here’s a quick 101 on how to access the data.

Let me know if you ever need assistance.

##Packages
library(httr)
library(jsonlite)
library(tidyverse) #not really needed if you remove the pip but force of habit I load this

##Inputs
username <- "API_KEY"  # leave
key <- "KEY_GENERATED_FROM_ICU" #<edit
strava <- "YOUR_STRAVA_ID" #<edit

##Functions
url <- sprintf("https://intervals.icu/api/v1/athlete/%s/activities.csv", strava)

##Get Data
test1 <- httr::GET(url, authenticate(username, key)) %>%
  content()

test1

Currently it is just your Strava ID … but that will soon be changing. I will organise to get it displayed on the settings page. You can also use the athlete IDs of people you are following on Intervals.icu.

Low-priority suggestion: wellness data in API

2 Likes

I have just implemented some API support for wellness.

GET /api/v1/athlete/{id}/wellness?oldest=2020-12-01&newest=2020-12-31

[
  {
    "id": "2020-12-01",
    "updated": "2021-01-01T15:14:22.925+0000",
    "weight": 72.6,
    "restingHR": 44,
    "hrv": null,
    "menstrualPhase": null,
    "menstrualPhasePredicted": null,
    "kcalConsumed": null,
    "sleepSecs": null,
    "sleepQuality": null,
    "soreness": 1,
    "fatigue": 2,
    "stress": 3,
    "mood": 4,
    "motivation": 3,
    "spO2": null,
    "systolic": null,
    "diastolic": null
  },...]

Weight is in kg. Soreness etc. are on a 1-4 scale where 1 is good (not sore) and 4 is bad (very sore).

GET /api/v1/athlete/2049151/wellness/2020-12-01

Get the record for the day.

PUT /api/v1/athlete/2049151/wellness/2020-12-01

Create or update the record for the day. Only include fields you want to change in the body:

{ "weight": 74.2 }

To ‘unset’ numeric fields send -1.

You can also supply a ‘localDate’ query parameter in yyyy-MM-dd format. If that matches the id of the record you are updating then the athlete’s ‘current’ weight and/or resting HR in /settings are also updated.

3 Likes

This works, thanks! Had to find a huuuge Google App Script to import JSON into Sheets, but that’s okay — now I don’t need to enter the wellness data 3 times, only 2 :slight_smile:

I will add a CSV version at some point.

Would you be able to provide any pointers on what you did to import into Sheets? The script you used? An example sheet potentially? I bet it would help a lot of us to get started.

I’ve created a document with 2 special sheets: intervals.icu and intervals.icu_wellness.

Then I used the Tools -> Script editor to enter this: Intervals.icu import into Google Sheets · GitHub (enter your athlete id and API_KEY in the variables close to the end of file).

Then I added a Drawing resembling a button to a separate sheet and assigned a script to it (right click to select it, then click the triple-dot menu to access the context menu, click “assign a script” and enter importIntervalsICU() in the modal window).

Now I have a button that I press every time when I want to fetch the data from the Intervals. The sheets intervals.icu and intervals.icu_wellness are rewritten every time, so best not to edit them manually (unless you know what you’re doing).

When I do analytics, I import the relevant values to other sheets by specifying a date and using the function VLOOKUP to get the row corresponding to the date. Like so:

=IFNA(VLOOKUP(<date>,{intervals.icu_wellness!A12:A,intervals.icu_wellness!F12:F},2,FALSE))

You might also want to transform the ICU dates like so:
=DATE(MID(<date>,1,4),MID(<date>,6,2),MID(<date>,9,2))

In summary, try to make a copy of this document: Intervals.ICU analysis - Google Таблиці
However, I’m not sure if it will “just work”

2 Likes

Yeah, removing my private information messed up parts of the logic. However, it should be possible to figure this out using the parts that work. Those mostly rely on the named ranges

Got it, thanks.