0

Delete workout plans for a given user ID

by
Published Oct 17, 2025

Used to delete 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
 * Delete workout plans for a given user ID
4
 * Used to delete 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(auth: RT.Terra, user_id: string | undefined, body: Body) {
7
	const url = new URL(`https://api.tryterra.co/v2/plannedWorkout`)
8
	for (const [k, v] of [['user_id', user_id]]) {
9
		if (v !== undefined && v !== '') {
10
			url.searchParams.append(k, v)
11
		}
12
	}
13
	const response = await fetch(url, {
14
		method: 'DELETE',
15
		headers: {
16
			'dev-id': auth.devId,
17
			'Content-Type': 'application/json',
18
			'X-api-key': auth.apiKey
19
		},
20
		body: JSON.stringify(body)
21
	})
22
	if (!response.ok) {
23
		const text = await response.text()
24
		throw new Error(`${response.status} ${text}`)
25
	}
26
	return await response.json()
27
}
28

29
/* eslint-disable */
30
/**
31
 * This file was automatically generated by json-schema-to-typescript.
32
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
33
 * and run json-schema-to-typescript to regenerate this file.
34
 */
35

36
export interface Body {
37
	/**
38
	 * List of identifiers for planned workout entries to be deleted
39
	 */
40
	data?: string[]
41
	[k: string]: unknown
42
}
43