1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { fetch } from "https://esm.town/v/std/fetch";
export let pelotonWorkouts = async (credentials) => {
/*
call this function:
@stevekrouse.pelotonWorkouts({username_or_email: 'xxxxx', password: 'yyyyy'})
*/
let loginResponse = await fetch('https://api.onepeloton.com/auth/login', {
method: 'post',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(credentials)
})
let cookie = loginResponse.headers.get('set-cookie')
let {user_id} = await loginResponse.json()
let workouts = await fetch(`https://api.onepeloton.com/api/user/${user_id}/workouts?=peloton.ride&limit=10&page=0&sort_by=-created`, {
method: 'get',
headers: {'Content-Type': 'application/json', 'Cookie': cookie},
})
return workouts.json()
}