This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Adding a Training Plan into a group.

Former Member
Former Member
I know you can create and share and event or a course with your group. But how about a workout?
Say If I make a Gym or Swim Programs to share with my training mates, They have to manually look at my calendar.
Is there a way I can either share my calendar or workout or put my workout on the group calendar.

Cheers,

Trav
  • I'm not really sure that what I'm telling you will be helpful, but you can download your workouts from Garmin Connect by accessing their web service api. If you are logged into Garmin Connect, you can get a list of your workouts here. This will give you the workout name and the workoutId. Once you have the workoutId, you can download a .fit or .tcx file for the activity by plugging the workoutId into the following urls

    http://connect.garmin.com/proxy/workout-service-1.0/fit/workout/workoutId
    http://connect.garmin.com/proxy/workout-service-1.0/tcx/workout/workoutId

    Once you have the .tcx or .fit file, you'd need to get it onto the device. You used to be able to do this by copying the file into the appropriate place on the device.

    Travis
  • It seems that I've found a relatively simple way to copy workouts into Garmin Connect via the web service api. If you follow my instructions above for getting the activity number, you can use that to get the json representation of the activity. For example, when I go to this page...

    connect.garmin.com/.../workoutlist


    I see entries for my workouts like this...

    {"com.garmin.connect.workout.dto.BaseUserWorkoutListDto":
    { "baseUserWorkouts": [
    {
    "workoutId": 4298819,
    "workoutName": "CFR-09 (2:30)"
    },
    {
    "workoutId": 4298824,
    "workoutName": "CFR-08 (2:15)"
    },

    As mentioned above, I can insert the workoutId into the following

    http://connect.garmin.com/proxy/workout-service-1.0/json/workout/{workoutId}


    Here is the output of that page for workoutId 4298819.

    {"com.garmin.connect.workout.json.UserWorkoutJson": {
    "workoutId": 4298819,
    "workoutName": "CFR-09 (2:30)",
    "createdDate": "2013-04-17 03:55:52.0 GMT",
    "updatedDate": "2013-07-24 18:58:52.0 GMT",
    "ownerId": 2156413,
    "sportTypeKey": "cycling",
    "workoutSteps": [
    {
    "stepId": 34152491,
    "stepOrder": 1,
    "groupId": 0,
    "parentGroupId": 0,
    "endConditionId": 1,
    "endConditionValue": 9000000.0,
    "endConditionUnitPk": 41,
    "targetValueUnitPk": 6,
    "stepTypeKey": "interval",
    "intensityTypeKey": "active",
    "endConditionTypeKey": "time",
    "targetTypeKey": "no.target",
    "endConditionUnitKey": "ms",
    "endConditionDisplayValue": "02:30:00",
    "endConditionDisplayUnit": "Hours:Minutes:Seconds",
    "endConditionDisplayUnitAbbr": "h:m:s",
    "targetValueUnitKey": "dimensionless"
    }
    ]
    }}

    If you send that text to your friends, and have them load up this page, they can paste and submit the workout text to create a copy of your workout workout in their account. You can try it out yourself by copy/pasting the above workout data.

    I know that this is really a big hack, but I'm too busy to write up a utility to slurp one persons workout calendar down and then upload that calendar to another user account. I could do it, but I'd need a night or two.

    Travis
  • Hi Travis,

    The link to the page for uploading the workout is not working, can you update it?

    Regards
    Claus
  • Former Member
    0 Former Member over 9 years ago
    Hi Travis,
    I know this is an old thread but I'd like to try the page you created for adding a new workout from the json export. The page you created is no longer accessible, would it be possible to stand it back up or perhaps share the code?

    Thanks!
    Rob
  • Comcast pulled their web hosting in October and I didn't archive the files that were being hosted there. Sorry.
  • Former Member
    0 Former Member over 9 years ago
    Just to follow up on this thread incase anyone else is interested, I figured out how to download and upload workouts using the GC REST API. Here is some python code with the REST endpoints:
    def get_session(email=None, password=None):
    session = requests.Session()

    data = {
    "username": email,
    "password": password,
    "_eventId": "submit",
    "embed": "true",
    }
    params = {
    "service": "connect.garmin.com/.../login",
    "clientId": "GarminConnect",
    "consumeServiceTicket": "false"
    }

    preResp = session.get("sso.garmin.com/.../login", params=params)
    data["lt"] = re.search("name=\"lt\"\s+value=\"([^\"]+)\"", preResp.text).groups(1)[0]
    ssoResp = session.post("sso.garmin.com/.../login", params=params, data=data, allow_redirects=False)
    ticket_match = re.search("ticket=([^']+)'", ssoResp.text)
    ticket = ticket_match.groups(1)[0]
    gcRedeemResp = session.get("connect.garmin.com/.../login", params={"ticket": ticket}, allow_redirects=False)
    expected_redirect_count = 6
    current_redirect_count = 1
    while True:
    gcRedeemResp = session.get(gcRedeemResp.headers["location"], allow_redirects=False)
    if current_redirect_count >= expected_redirect_count and gcRedeemResp.status_code != 200:
    raise APIException("GC redeem %d/%d error %s %s" % (current_redirect_count, expected_redirect_count, gcRedeemResp.status_code, gcRedeemResp.text))
    if gcRedeemResp.status_code == 200 or gcRedeemResp.status_code == 404:
    break
    current_redirect_count += 1
    if current_redirect_count > expected_redirect_count:
    break
    return session

    def get_workouts(gc):
    return gc.get("connect.garmin.com/.../workoutlist").text

    def get_workout_string(gc, workoutId):
    return gc.get("connect.garmin.com/.../" + workoutId).text

    def create_workout(gc, json_str):
    json_str = json.dumps(json.loads(json_str), separators=(',', ':'))
    payload = {'data':json_str}
    return gc.post("connect.garmin.com/.../createWorkout", headers={"content-type":"application/x-www-form-urlencoded"}, params=payload)

    def delete_workout(gc, workoutId):
    return gc.delete("connect.garmin.com/.../" + workoutId).text


    Here is a flask project that you can run yourself (https://github.com/rcaudill/flask-garmin_workouts_tool) or you can use mine (http://robc.duckdns.org/).

    Special thanks to Travis Vitek, Sergey Krasnov, and the Tapiriik project.