0

Retrieve workout plans for a given user ID

by
Published Oct 17, 2025

Used to get workout plans the user has registered on their account. This can be strength workouts (sets, reps, weight lifted) or cardio workouts (warmup, intervals of different intensities, cooldown etc)

Script terra Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Retrieve workout plans for a given user ID
4
 * Used to get workout plans the user has registered on their account. This can be strength workouts (sets, reps, weight lifted) or cardio workouts (warmup, intervals of different intensities, cooldown etc)
5
 */
6
export async function main(
7
	auth: RT.Terra,
8
	user_id: string | undefined,
9
	start_date: string | undefined,
10
	end_date?: string | undefined,
11
	to_webhook?: string | undefined
12
) {
13
	const url = new URL(`https://api.tryterra.co/v2/plannedWorkout`)
14
	for (const [k, v] of [
15
		['user_id', user_id],
16
		['start_date', start_date],
17
		['end_date', end_date],
18
		['to_webhook', to_webhook]
19
	]) {
20
		if (v !== undefined && v !== '') {
21
			url.searchParams.append(k, v)
22
		}
23
	}
24
	const response = await fetch(url, {
25
		method: 'GET',
26
		headers: {
27
			'dev-id': auth.devId,
28
			'X-api-key': auth.apiKey
29
		},
30
		body: undefined
31
	})
32
	if (!response.ok) {
33
		const text = await response.text()
34
		throw new Error(`${response.status} ${text}`)
35
	}
36
	return await response.json()
37
}
38