Pingdom check: skilbjo.duckdns.org frontend, also trigger statuspage.io
@skilbjo
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.
send_http_request
auth
to use OAuth tokens and API keys in code via theauths object
params
Url
 
string ·params.url
Payload
 
string ·params.payload
Optional
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
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
39
40
41
42
}
43
const axios = require("axios")
const config = {
  method: params.method ||  "post",
  url: params.url,
  validateStatus: () => true,  // axios will throw on >=400 errors
}
for (const { key, value } of params.query || []) {
  if (!config.params) config.params = {}
  config.params[key] = value
}
for (const { key, value } of params.headers || []) {
  if (!config.headers) config.headers = {}
  config.headers[key] = value
}
if (params.auth) {
  config.auth = {
    username: params.auth.username,
    password: params.auth.password,
  }
}
if (params.payload)  config.data = params.payload
try {
  const response = await axios(config)
  let status = response.status
  console.log(`Status code: ${status}`) 
  // return response
  if (status >= 400) {
    this.err = {
      code: status,
      message: `Request failed with status ${status}`,
    }
  }
  return this
} catch (err) {  // this doesn't ever get called because of line 6
  this.err = {
    code: status,
    message: `Request failed with status ${status}`,
  }
  return this.err
  // throw err  // js note; comment this line, and proceed w/ error handling here
} 
steps.
send_email
auth
to use OAuth tokens and API keys in code via theauths object
(auths.sendgrid)
params
To email

The email address of the recipient.

 
string ·params.to_email
From email

The email address of the sender.

 
string ·params.from_email
Reply to_email

The email address to which responses will be sent.

 
string ·params.reply_to_email
Type

The mime type of the content you are including in your email. For example, text/plain or text/html.

 
string ·params.type
Value

The actual content of the specified mime type that you are including in your email.

 
string ·params.value
Optional
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, 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
}
54
const axios = require('axios')
var state;

const { id, workflow_id } = steps.trigger.context

if (!steps.send_http_request.err) {
  state = 'UP'
} else {
  state = 'DOWN'
}

// we are up now, but were we down previously?
if ($checkpoint && $checkpoint[workflow_id] && $checkpoint[workflow_id]['prevState'] != state) {

  return await require("@pipedreamhq/platform").axios(this, {
    url: `https://api.sendgrid.com/v3/mail/send`,
    headers: {
      Authorization: `Bearer ${auths.sendgrid.api_key}`,
    },
    method: 'POST',
    data: {
      "personalizations": [{
        "to": [{
          "email": params.to_email,
          "name": params.to_name
        }],
        "subject": state,
        "headers": params.headers,
        "substitutions": params.substitutions,
        "custom_args": params.custom_args,
        "send_at": params.send_at
      }],
      "from": {
        "email": params.from_email,
        "name": params.from_name
      },
      "reply_to": {
        "email": params.reply_to_email,
        "name": params.reply_to_name
      },
      "content": [{
        "type": params.type,
        "value": params.value
      }],
      "template_id": params.template_id,
      "sections": params.sections,
      "categories": params.categories,
      "batch_id": params.batch_id,
      "ip_pool_name": params.ip_pool_name
    }
  })
}
steps.
checkpoint
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
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
}
29
const merge = require('lodash.merge')

const { id, workflow_id } = steps.trigger.context
const ts = + new Date()

var state, code;

if (!steps.send_http_request.err) {
  state = 'UP'
  code = 200
} else {
  state = 'DOWN'
  code = steps.send_http_request.err.code

  // First run of Error Workflow. Checkpointing initial state
  if (!$checkpoint) {
    $checkpoint = {} // workflow error gets set on merge below
  }
}

merge($checkpoint, {
  [workflow_id]: {
    prevState: state,
    lastSeen: ts,
    lastHttpStatusCode: code
  }
})