Skip to content
On this page

Build workouts

Resolve exercises, build a TrainHeroic session as a draft, read it back, and publish it to athletes as a separate, deliberate step.

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. For source data in Excel or CSV, start with the spreadsheet import workflow before mapping rows to the SDK input below.

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");

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. When a stated unit matches the exercise’s library default, buildSession keeps that default. A different unit is set on this session only, so secondaryUnit: "%max" prescribes a percentage of max on a built-in pounds lift and primaryUnit: "m" puts meters on a miles exercise. buildSession throws before writing when a unit is unknown or conflicts with an explicit param_1_type or param_2_type.

Options

PropType
programIdnumber

The program that receives the session. Use a team's program or a roster athlete's calendar; a personal calendar rejects coach writes.

Typenumber
indexExerciseIndex

The exercise library. Every exercise and its units are checked against it before the first write.

TypeExerciseIndex
blocksBlockSpec[]

The session's blocks, each with a title and its exercises.

TypeBlockSpec[]
date?[year, month, day]

The calendar day for the session, with a 1-based month. Required unless you pass timelineDay.

Type[year, month, day]
timelineDay?number

The day number in a fixed-length program. Use it in place of date.

Typenumber
publish?boolean

Publish the session to athletes after it saves. Leave it off to build a draft.

Typeboolean
Defaultfalse
instruction?string

The session's coach instructions, saved after the blocks.

Typestring
confirmSetSplit?boolean

Allow a prescription above ten sets to become consecutive blocks.

Typeboolean
Defaultfalse

What it returns

pwIdnumberrequired

The session’s placement in the program. Read, publish, unpublish, copy, and remove operations use it.

workoutIdnumberrequired

The underlying workout record.

advisories{ notes: string[]; warnings: string[] }required

Notes and warnings from the build, such as a set count that was split across blocks.