Shot from the hip: if they end up in the wellness fields, then yes just get the wellness data via the api. Otherwise get whatever endpoint of the api assembles the „position“ of the garmin data you’re looking for (e.g. workouts for hrv for a specific workout synced via garmin)
Yes if you have enabled Garmin wellness integration in /settings and can see the data in Intervals.icu then you can get it from the API.
Would you have a basic example of how to query the API using Python? I just can’t get it to produce results. Been playing around with this, but keep getting “<Response [200]>” as result.
import requests
import json
url = "http://intervals.icu"
api_url = 'https://intervals.icu/api/v1/athlete/yyyyyyy'
api_key = 'xxxxxxxxx'
data = {
"url" : api_url,
"API_KEY": api_key,
"accept": 'application/json, text/plain, */*'
}
Response = requests.get( url, data )
print( Response)
You should check correct field in Response
Try print(Response.content)
You can get information on how to parse response provided by requests.get() at
requests module help
In any case, you could use following code to also encode user/password
import base64
import requests
yourID = 'xxxxxxxxx'
yourAPIKEY = 'xxxxxxxxxxxxxxxxxxxxx'
userpass = 'API_KEY:' + yourAPIKEY
userpass_bytes = userpass.encode('ascii')
base64_bytes = base64.b64encode(userpass_bytes)
base64_userpass = base64_bytes.decode('ascii')
url = 'https://intervals.icu/api/v1/athlete/' + yourID
headers = {
'accept': '*/*',
'Authorization': 'Basic ' + base64_userpass,
}
response = requests.get(url, headers=headers)
print(response.content)
Thank you! This works. Now I can work further from here
Just in case others come across this Python snippet, it can be simplified even more since requests
supports basic auth credentials with the auth
argument. Getting your athlete summary can be done in Python like this:
import requests
intervals_id = 'xxx'
intervals_api_key = 'xxx'
url = 'https://intervals.icu/api/v1/athlete/' + intervals_id
response = requests.get(url, auth=('API_KEY', intervals_api_key))
print(response.json())
Note also the use of .json()
on the response object. Requests gives you this helper which will automatically convert the JSON response into a dictionary for you.
Even better!! Thank you
Hi David/others, I have written a crude script that syncs my intervals.icu weight (coming from Garmin connect) with Wahoo Systm. Now I want to automate it. Is there any webhook or efficient way of only running the script when the weight changes? Or do I have to schedule the script to run every X hours? If I have to schedule it is there preference on number of calls per minute/hour/day etc; I don’t want to unwittingly hammer the intervals api for the occasional daily weight update. Thanks.
There aren’t any webhooks so just running every few hours is the solution. That won’t overly stress the servers. Tx for asking.
If you are still playing with this, you can peruse the source at GitHub - rday/py-intervalsicu (shameless plug). I haven’t been actively keeping this up, but if there is interest in it I would be happy to do so. If not, maybe it would help with basic connections to the API.
I actually studied your code as sample of how to work with the API, so thank you for that. Though I don’t know yet how to work with classes like you build, I now made separate functions to query or write to the intervals API. But I also added withings, Strava and Wahoo already.
Now breaking my head on how to make it userfriendly to choose from which app you want which metrics to sync to which app
Very early stage:
Send me a PM if you want input/help
@david is there a simple way to determine if an activity has any GPS data w/o going into the activity stream endpoint and actually pulling data?
I’m looking at how you “enable / disable” the MAP button on the activity page but havent figured it out yet.
For Per Athlete settings, I see that on the web, you’re pulling from
https://intervals.icu/api/v1/athlete?deviceClass=Desktop
But when I try it, I had to append the athleteId to it otherwise it will result in an error.
https://intervals.icu/api/v1/athlete/{athlete_id}?deviceClass=Desktop
However, the end result is that the returned data is different. All these items are not available.
Can you advise? I’m not sure the costs of hitting the API multiple times vs 1x to collect all these data. Which is better?
Tx
Hi @david,
Had another explore of the api to create myself a mini workout comparison tool in R or Python.
I’ve looked at the end points for both activities
and events
and can see the ride and the workout note but there doesn’t appear to be any way of linking them together. Have I missed something or is this not possible?
Aiming for something like this on say all 2x15 workouts:
Work Set 1 | Work Set 2 | ||||||||
---|---|---|---|---|---|---|---|---|---|
Date | RPE | Target Power | Avg Power | Avg HR | Avg Cadence | Target Power | Avg Power | Avg HR | Avg Cadence |
16/02/2023 | 6 | … | … | … | … | … | … | … | … |
06/02/2023 | 7 | … | … | … | … | … | … | … | … |
04/02/2023 | 4 | … | … | … | … | … | … | … | … |
31/01/2023 | 9 | … | … | … | … | … | … | … | … |
30/01/2023 | 3 | … | … | … | … | … | … | … | … |
**** |
-=- EDIT -=-
Ignore me, found the field paired_event_id
in an activity, be good if you could go the other way but suppose you only have to loop through the activities on the given day of event
You can look for “latlng” in activity.stream_types. This contains all the stored streams for the activity.
Calling /api/v1/athlete/{id} will return the athlete object and not the settings you are looking for. You need to call:
GET /v1/athlete/{id}/settings/{deviceClass}
Maybe somebody could help me a bit with my laziness?
I’ve a script to extract What’s-on-Zwift workouts into i.icu format:
Currently, this simply prints the converted file to the command line, which is fine for me and intermittent use.
However, it would be cool, also for users, to be able to have this directly upload the workout into the (running) user’s workout library, e.g., into a folder “What’s on Zwift?”.
I do not want to mess up my i.icu account for this matter and would appreciate it a lot if someone could help me with the appropriate commands to create the workout in the i.icu library and set name and content;-)
I have some basic experience with the Python webbrowser and json modules to extract data from Strava and think the same approach should help with putting data into i.icu.
You already know how to talk to the ICU API ?
No, but I assume that’s not too complicated following the opening post in this thread;-)
Question is which commands I have to send to get a workout into (a specific folder of) the workout library of the authorized user, and what “data” I have to send to set name, type, and content…
In Python, e.g., using the json module.
See my code for some examples:
But you’d have to use the swagger site to find the correct data to pull:
https://intervals.icu/api/v1/docs/swagger-ui/index.html
Hi guys,
I feel like I am going crazy just trying to Auth and use my API key - I constantly get 403 or 422 errors when using what appears to be a valid API key an Athlete ID - Would it be possible to just post what you are using in Python to simply authorize and call a list of your last 5 workouts? I tried the below but I feel like a moron it’s not working - all my other API auths seem to work pretty easily this one I just can’t figure out (newbie scripter)
import requests
api_key = “my_api_key”
headers = {“Authorization”: "Bearer " + api_key}
url = “https://intervals.icu/api/v1/athlete/ATHLETE_ID/activities”
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
print(data)
else:
print(“Error retrieving data:”, response.status_code)