Facebook Pixel
Fit'DistanceDocumentation
Open the app
On this page

Assign a program

Send a program to one or more students with programs.assign: one copy per student, the immediate notification, keeping or consuming the source with consumeSource, and the preview before sending.

programs.assign sends a program to your students. Each student gets their own full copy (workouts, blocks, exercises, sets): changing one student's copy touches neither the source nor the others. You need a key with Training › Write (training:write) and a plan that includes writes.

Each student is told right away

On sending, each student gets an in-app notification and a push notification ("You received a program!"), with no delay and no option to turn them off. The program.assigned event is sent for each copy. Go through the preview first (dry_run: true), above all in a loop.

Keep or consume the source: consumeSource

ValueWhat happens to the sourceWhat for
false (the API default)It stays in your list of programs, unchanged.A program you send to several students, or want to reuse.
trueIt is deleted once copied, in the same operation.A draft prepared for one student: no duplicate draft is left behind. This is what the app does when you assign a program.

Without consumeSource, the API keeps the source. The MCP server consumes it by default, like the app, and asks for your confirmation before sending.

Through the API

curl -X POST https://api.fitdistance.io/api/partner/v1/operations/programs.assign \
  -H "Authorization: Bearer $FITDISTANCE_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: assign-3f9c2a7e-42" \
  -d '{"programUid": "3f9c2a7e-…", "studentIds": [42], "consumeSource": true, "dry_run": true}'

The preview sends nothing and costs nothing: its message gives the program name, the number and names of the students, and what happens to the source. Remove dry_run to send, with another Idempotency-Key (dry_run is part of the body). The answer gives the uid of each student's copy:

{
  "data": {
    "programUid": "3f9c2a7e-…",
    "studentIds": [42],
    "sourceConsumed": true,
    "copies": [{ "programUid": "b71d04c9-…", "studentId": 42 }]
  },
  "message": "Programme \"Bloc force\" assigné à 1 élève(s) — ils ont été notifiés (inbox + push). Le programme source a été remplacé par une copie par élève.",
  "dry_run": false
}

The message is in French, like every message of the API. Keep one Idempotency-Key per program and student: a retry with the same key does not send a second copy. See Writes and idempotency.

With the CLI

fitdistance programs.assign --programUid 3f9c2a7e-… --studentIds '[42]' --consumeSource --dry-run
fitdistance programs.assign --programUid 3f9c2a7e-… --studentIds '[42]' --consumeSource --yes --idempotency-key assign-3f9c2a7e-42

--studentIds takes a JSON list. Without --consumeSource, the source stays in your list. The options are described in The CLI.

What is refused before anything is sent

These cases answer 400 VALIDATION, in the preview too, without copying anything or telling anyone. details.code says which:

codeCase
STUDENT_NOT_FOUNDAn id is not one of your current students (not found, or coached by someone else). details.student_ids lists them.
DUPLICATE_STUDENT_IDSA student appears twice: they would get two copies.
PROGRAM_IS_TEMPLATEThe source is a template. Its copy would stay a template, without dates, that the student would not see. Duplicate it first with a start date (programs.write, action: "duplicate"), then assign the copy.
PROGRAM_NOT_READYThe source is still being copied (cloning) or its copy failed (clone_failed).
SOURCE_ASSIGNEDconsumeSource: true on a program already assigned to a student: they would lose it, with its history. With consumeSource: false, the sending goes through.

A program of another account answers 400 VALIDATION, with ACCESS_TO_WORKOUT in details. A key without training:write gets 403 SCOPE_MISSING.

What it costs

A sending costs one credit, whatever the number of students. The preview (dry_run: true) costs nothing, even when it answers with a refusal: it is the free way to check a list of students. A sending refused by the table above is billed like any write error, see Errors. Reference: programs.assign.

Next pageErrorsThe shape of an API error, the thirteen codes with their HTTP status and what they cost, and what to do with each.