403 trying to delete a workout

Trying to make a workout planner with python but having massive issues with a 403 error. Even in the API documentation when I try to delete workouts with the right user ID and date range, the error keeps coming back (both Auth methods used)

This first. Then here is the snippet I`m working on in Python:

-------------------

Delete existing events safely

-------------------

def delete_events(start_date, end_date):
“”“Fetch all events in range and delete individually”“”
url = f"{BASE_URL}athlete/{ATHLETE_ID}/events"
params = {
“start_date_local”: start_date.isoformat(),
“end_date_local”: end_date.isoformat(),
“category”: “WORKOUT”
}
resp = requests.get(url, headers=HEADERS, auth=AUTH, params=params)
if resp.status_code != 200:
print(f":cross_mark: Failed to fetch events: {resp.status_code} {resp.text}“)
return
events = resp.json()
for ev in events:
ev_id = ev[“id”]
del_url = f”{BASE_URL}athlete/{ATHLETE_ID}/events/{ev_id}"
del_resp = requests.delete(del_url, headers=HEADERS, auth=AUTH)
if del_resp.status_code in (200, 204):
print(f":wastebasket: Deleted event {ev_id}“)
else:
print(f":cross_mark: Failed to delete event {ev_id}: {del_resp.status_code} {del_resp.text}”)

Unfortunately always getting back a 403.. In Python I only used the bearer token.

You have to use basic auth. Username is literally ‘API_KEY’ and the password is your API key from the settings.

ITs set up like this:
USER = “API_KEY”
PASS = “my key, the long number”
ATHLETE_ID = “1749703”
BASE_URL = f"https://intervals.icu/api/v1/athlete/{ATHLETE_ID}"

AUTH = requests.auth.HTTPBasicAuth(PASS, “”)

But I only get a 403 back

That seems to be wrong. It’s probably

AUTH = requests.auth.HTTPBasicAuth(USER, PASS)

Got it working now, thanks a lot.
:smiley: