0

Retrieve user profile info for a given user ID

by
Published Oct 17, 2025

Fetches relevant profile info such as first & last name, birth date etc. for a given user ID

Script terra Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Retrieve user profile info for a given user ID
4
 * Fetches relevant profile info such as first & last name, birth date etc. for a given user ID
5
 */
6
export async function main(
7
	auth: RT.Terra,
8
	user_id: string | undefined,
9
	to_webhook?: string | undefined
10
) {
11
	const url = new URL(`https://api.tryterra.co/v2/athlete`)
12
	for (const [k, v] of [
13
		['user_id', user_id],
14
		['to_webhook', to_webhook]
15
	]) {
16
		if (v !== undefined && v !== '') {
17
			url.searchParams.append(k, v)
18
		}
19
	}
20
	const response = await fetch(url, {
21
		method: 'GET',
22
		headers: {
23
			'dev-id': auth.devId,
24
			'X-api-key': auth.apiKey
25
		},
26
		body: undefined
27
	})
28
	if (!response.ok) {
29
		const text = await response.text()
30
		throw new Error(`${response.status} ${text}`)
31
	}
32
	return await response.json()
33
}
34