API access to Intervals.icu

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
1 Like

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.

5 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”

3 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.

you could also add a time-driven trigger for the importIntervalsICU function from the script editor instead of a button so it will import at regular intervals without manual intervention

Does this work with google sheets, even when the file is not open? Would be a big advantage over excel, also for other stuff.

Yes, triggers will fire even if you are not logged in to Google

I think that’s useless load to David’s servers :slight_smile:

1 Like

triggering every hour - agreed. But once or twice a day - if that kills the servers then he really does need more Stripe subscribers! :grin:

1 Like

:slight_smile: Thats very small compared to processing all the activities that come in every day.

Hello everyone. First of all, this app is great.
According the API I would like to ask if there is an endpoint, which could be used to update weight in the user settings section. This would help me to update weight on every measurement taken. Thank you. M

1 Like

Tx. You need to use the update wellness data endpoint:

PUT JSON to https://intervals.icu/api/v1/athlete/2049151/wellness/2021-01-24
{
    "weight": 71.0
}

The endpoint also takes an optional query parameter ‘localDate’ which is the current date for the user in yyyy-MM-dd format. If this matches the date being updated then the user’s “current” weight and resting HR are updated.

2 Likes