Share Peloton ride
@danny
code:
data:privatelast updated:10 months ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 100,000+ developers using the Pipedream platform
steps.
trigger
HTTP API
Deploy to generate unique URL
This workflow runs on Pipedream's servers and is triggered by HTTP / Webhook requests.
steps.
peloton_auth
auth
to use OAuth tokens and API keys in code via theauths object
params
Username or_email
1
{{process.env.PELOTON_USERNAME}}
string ·params.username_or_email
Password
1
{{process.env.PELOTON_PASSWORD}}
string ·params.password
Method
1
POST
string ·params.method
Url
1
https://api.onepeloton.com/auth/login
string ·params.url
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across invocations with$checkpoint.
async (event, steps, params) => {
1
2
3
4
5
6
7
8
9
10
11
}
12
const { username_or_email, password } = params 
const config = {
  method: params.method,
  url: params.url,
  data: {
    username_or_email,
    password,
  },
}
return await require("@pipedreamhq/platform").axios(this, config)
steps.
make_peloton_request
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across invocations with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
}
9
const {promisify} = require('util');
const got = require('got');
const {CookieJar} = require('tough-cookie');
const cookieJar = new CookieJar();
const setCookie = promisify(cookieJar.setCookie.bind(cookieJar));
await setCookie(`peloton_session_id=${steps.peloton_auth.$return_value.session_id}`, 'https://api.onepeloton.com');
this.me = JSON.parse((await got(`https://api.onepeloton.com/api/user/${steps.peloton_auth.$return_value.user_id}/workouts?joins=ride,ride.instructor&limit=1&page=0`, {cookieJar})).body)
steps.
send_new_message
Sends a new SMS message
auth
(auths.twilio)
params
To
1
string ·params.To
From
1
string ·params.From
Body
1
https://members.onepeloton.com/profile/workouts/{{steps.make_peloton_request.me.data[0].id}}
string ·params.Body
Optional
code
async (params, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
}
38
// Read the Twilio docs at https://www.twilio.com/docs/sms/api/message-resource#create-a-message-resource
const phone = require('phone');

// Parse the given number into its E.164 equivalent
// The E.164 phone number will be included in the first element
// of the array, but the array will be empty if parsing fails.
// See https://www.npmjs.com/package/phone
const toParsed = phone(params.To)
if (!toParsed.length) {
  throw new Error(`Phone number ${params.To} couldn't be parsed as a valid number.`)
}
const fromParsed = phone(params.From)
if (!fromParsed.length) {
  throw new Error(`Phone number ${params.From} couldn't be parsed as a valid number.`)
}

const data = {
  To: toParsed[0],
  From: fromParsed[0],
  MessagingServiceSid: params.MessagingServiceSid,
  Body: params.Body,
  MediaUrl: params.MediaUrl,
}
const config = {
  method: "post",
  url: `https://api.twilio.com/2010-04-01/Accounts/${auths.twilio.AccountSid}/Messages.json`,
  headers: {
    "Content-Type": "application/x-www-form-urlencoded",
  },
  auth: {
    username: auths.twilio.Sid,
    password: auths.twilio.Secret,
  },
  data: require("qs").stringify(data),
}
return await require("@pipedreamhq/platform").axios(this, config)
steps.
email_me
Customize and send an email to the email address you registered with Pipedream. The email will be sent by notifications@pipedream.com.
params
Subject
1
string ·params.subject
Text
1
string ·params.text
Optional
code
async params => {
1
2
3
4
5
6
7
8
9
10
11
12
}
13
const options = {
  subject: params.subject,
  text: params.text,
}
if (params.html) {
  options.html = params.html
}
if (params.include_collaborators) {
  options.include_collaborators = params.include_collaborators
}
$send.email(options)