Skip to content
On this page

Build workouts

Resolve exercises, build a draft session, read it back, and publish separately.

buildSession() creates one session inside a program, saves its blocks and exercises, and can optionally publish it. The safer workflow is draft first, inspect second, publish last.

Resolve every exercise

Use the exercise library to turn names into TrainHeroic ids.

Build a draft

Set publish: false and keep the returned pwId.

Read it back

Verify the encoded session before it becomes athlete-visible.

Publish deliberately

Call publishSession() only after the draft matches the intended programming.

import { buildSession } from "@trainheroic-unofficial/js";

const { match } = await library.resolve("Back Squat");
if (!match) throw new Error("Choose one exercise before building");
if (match.units[0] !== "reps" || match.units[1] !== "lb") {
  throw new Error("Choose an exercise with reps and pounds as its fixed units");
}

const { pwId, workoutId } = await buildSession(client, {
  programId: 12345,
  index: library,
  date: [2026, 8, 17], // [year, month, day], with a 1-based month
  instruction: "Warm up first.",
  blocks: [
    {
      title: "Strength",
      exercises: [
        {
          id: match.id,
          sets: 5,
          reps: 5,
          primaryUnit: "reps",
          weight: 225,
          secondaryUnit: "lb",
          rpe: 8,
        },
      ],
    },
  ],
  publish: false,
});

reps and weight accept one scalar for every set or a per-set array such as reps: [5, 5, 3]. State primaryUnit for the reps slot and secondaryUnit for the weight slot. buildSession checks both against the exercise library before writing.

Session handles

  • pwId identifies the session’s placement in the program. Read, publish, unpublish, copy, and remove operations use it.
  • workoutId identifies the underlying workout record.

Was this page helpful?