Script No Longer Works

Not sure if I missed an update on this, noticed Joules is Work now, maybe it was always like that, but a script I was using to get the total Work done from my activities for a day is no longer working. Error seems to be coming from entry.get(‘icu_joules’), Here’s my script (Note I pass the date from apple shortcuts):

import requests
import json
import sys
from datetime import datetime


ATHLETE_ID = 000000  # Change this if necessary
API_KEY = "blahblahblahblah"
DATE = sys.argv[1]
url = f'https://intervals.icu/api/v1/athlete/0/activities?oldest={DATE}&newest={DATE}'


response = requests.get(url,  auth=('API_KEY', API_KEY))
if response.status_code == 200:
  pass
else:
    print(f"Failed to connect. Status code: {response.status_code}")

days_activities = response.json()
joules = []
for entry in days_activities:
	joules.append(entry.get('icu_joules'))
print(round(sum(joules)/1000))

Also, what happened to post that listed all the icu variables? I can’t for the life me find it.

icu_joules works for me (for an activity 10h ago). Is there a work field in you activity?

The post is here where to find the variables

If you don’t want to install it, you can open the Code page on the linked page from David and then dist → index.d.ts and you find all API variables.

Good to know icu_joules is working for you and I do have Work in my activities. I’ll try to see if I can see the whole json file I’m requesting. Something must of changed if it stopped working though, after it had been working fine for a few months. Broke maybe a month or two ago, and finally had time to work on this.

Hold on, I’m actually not connecting. Argh.

Ok, fixed it, acutally was connecting but wasn’t getting status_code 200 but 204, put a catch for that and it works now. Was the server side returning 200 before where it should have been returning 204? :man_shrugging:. Here’s working code if anyone encounter the same issue and doesn’t get what I’m talking about.

import requests

ATHLETE_ID = YOURATHLETEID  # Change this if necessary
API_KEY = "your_api_key_here"
DATE = sys.argv[1]
url = f'https://intervals.icu/api/v1/athlete/0/activities?oldest={DATE}&newest={DATE}'


response = requests.get(url,  auth=('API_KEY', API_KEY))
if response.status_code == 200:
    pass
elif response.status_code == 204:
    pass
else:
    print(f"Failed to connect. Status code: {response.status_code}")

days_activities = response.json()
joules = []
for entry in days_activities:
	joules.append(entry.get('icu_joules'))
print(round(sum(joules)/1000))