A program ends this week → an alert
Every Monday, get on Telegram the list of the programs that end during the week, with n8n or Make.
Every Monday at 8 am, you get on Telegram the list of the programs that end during the week: the student, the program, the day it ends. You have time to prepare the next one. The use case only reads: the message is sent by the Telegram node of your tool, not by the API. You need a key with Training › Read (training:read) and Students › Read (students:read). If you do not have one, create it in the app.
What this use case does
- Trigger: every Monday at 8 am. The window is the week, from Monday to Sunday included.
- Programs:
GET /programswithlimit=50, every page. Keep those whosestatusisin_progressand whose last day, the date ofend_at, is in the window. A program with no student (student_idnull) is ignored. - Students: if a program is left,
GET /students, every page, to show the first and last name. If the student is not in the list (they left or are not accepted yet), the program is ignored. - Send: one message, one line per program; nothing if no program ends.
curl "https://api.fitdistance.io/api/partner/v1/programs?limit=50" \
-H "Authorization: Bearer fd_live_xxxxxxxx"The message
Programmes qui se terminent cette semaine :
— Léa Martin · Prise de masse · fin le mardi 27 octobre
— Tom Durand · Sèche été · fin le vendredi 30 octobreThe day shown is the last day of the program. The windows follow each other without overlapping: a program is announced once, on the Monday of the week of its last day. If your tool is off on a Monday, the programs of that week are not caught up.
What it costs
A page read costs one credit, debited before the call. GET /programs returns every program, finished and draft ones included, 50 per page. A Monday with no program to announce costs these pages; otherwise at least one page of students is added, one per 50 students. Sending on Telegram or WhatsApp costs nothing on the API side. A refused parameter still costs a credit; a 401, a 403 or a 429 costs nothing.
In n8n
- Choose Import from URL… and paste
https://fitdistance.io/documentation/api/cas-pratiques/programme-fin-semaine.n8n.json, or download the workflow and choose Import from File…. Pick theFit'Distance APIcredential from Connect n8n in each HTTP Request node. - In Send alert, create the Telegram credential
Fit'Distance alertswith the token of the bot, or pick it if it exists, and replaceta_conversationwith yourchat_id. You get the bot, its token and thechat_idas in the Monday recap. - Run the workflow and read the text of Build the alert, then activate it. Run by hand on another day, it shows the current week.
Each list is a loop of Connect n8n. Programs ending keeps, on each page read, the programs whose last day is in the week: end_at is that day at 23:59 UTC, and the node reads its date without shifting it. Anything to say? stops the workflow when there is none. The text and the language of the day names are at the top of the code of Build the alert, in French: replace them with your own. The hours and the windows follow the time zone of the workflow (Timezone in its settings, New York by default).
The file sends on Telegram. For WhatsApp, replace Send alert with WhatsApp Business Cloud › Send Template. Outside the 24 hours after a message from your contact, WhatsApp only accepts a message template approved by Meta: the detail is in the Monday recap, where you also remove esc() from the code of Build the alert. Meta charges for each template sent.
In Make
- HTTP › Make a request (schedule: every Monday at 8 am):
GETonhttps://api.fitdistance.io/api/partner/v1/programs,limit=200, Parse response set toYes. - Iterator on
data, then a filter:statusequal toin_progress,end_atlater than or equal to{{now}}and earlier than{{addDays(now; 7)}}. Then a Flow Control › Array aggregator onname. - A filter:
lengthof the aggregated array greater than0. Then Telegram Bot › Send a Text Message or Reply, with your Chat ID andjoin(map(<aggregated array>; name); ", ")in Text. For WhatsApp, WhatsApp Business Cloud › Send a Template Message.
Make counts seven days from the run, stops at 200 programs and names the program without the student. Reference: training, students.