auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, params) => {
}
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
}
auths
objectThe email address of the recipient.
The email address of the sender.
The email address to which responses will be sent.
The mime type of the content you are including in your email. For example, text/plain or text/html.
The actual content of the specified mime type that you are including in your email.
return
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, params, auths) => {
}
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
}
})
}
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
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
}
})