Share Peloton ride
@droosevelt
code:
data:privatelast updated:3 years ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 800,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
{{process.env.PELOTON_USERNAME}}
string ·params.username_or_email
Password
{{process.env.PELOTON_PASSWORD}}
string ·params.password
Method
POST
string ·params.method
Url
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 executions 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 executions 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

The destination phone number. Format with a '+' and country code e.g., +16175551212 (E.164 format).

 
string ·params.To
From

A Twilio phone number (in E.164 format) or alphanumeric sender ID enabled for the type of message you wish to send. Phone numbers or short codes purchased from Twilio work here. You cannot (for example) spoof messages from your own cell phone number.

 
string ·params.From
Body

The text of the message you want to send, limited to 1600 characters.

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
 
string ·params.subject
Text
 
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)