//native
/**
* Retrieve activity data for a given user ID
* Fetches completed workout sessions, with a defined start and end time and activity type (e.g. running, cycling, etc.)
*/
export async function main(
auth: RT.Terra,
user_id: string | undefined,
start_date: string | undefined,
end_date?: string | undefined,
to_webhook?: string | undefined,
with_samples?: string | undefined
) {
const url = new URL(`https://api.tryterra.co/v2/activity`)
for (const [k, v] of [
['user_id', user_id],
['start_date', start_date],
['end_date', end_date],
['to_webhook', to_webhook],
['with_samples', with_samples]
]) {
if (v !== undefined && v !== '') {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
'dev-id': auth.devId,
'X-api-key': auth.apiKey
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 235 days ago