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
publish: false and keep the returned pwId.Read it back
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
programIdnumber
The program that receives the session. Use a team's program or a roster athlete's calendar; a personal calendar rejects coach writes.
numberindexExerciseIndex
The exercise library. Every exercise and its units are checked against it before the first write.
ExerciseIndexblocksBlockSpec[]
The session's blocks, each with a title and its exercises.
BlockSpec[]date?[year, month, day]
The calendar day for the session, with a 1-based month. Required unless you pass timelineDay.
[year, month, day]timelineDay?number
The day number in a fixed-length program. Use it in place of date.
numberpublish?boolean
Publish the session to athletes after it saves. Leave it off to build a draft.
booleanfalseinstruction?string
The session's coach instructions, saved after the blocks.
stringconfirmSetSplit?boolean
Allow a prescription above ten sets to become consecutive blocks.
booleanfalseWhat it returns
pwIdnumberrequiredThe session’s placement in the program. Read, publish, unpublish, copy, and remove operations use it.
workoutIdnumberrequiredThe underlying workout record.
advisories{ notes: string[]; warnings: string[] }requiredNotes and warnings from the build, such as a set count that was split across blocks.