RequestBin with an Event API
@pravin
code:
data:privatelast updated:4 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 1,000,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.
readme
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
}
44
/*
DESCRIPTION:
Persist HTTP request data to a real-time data store with
an API to query event counts, event data, and reset to 
delete data in the store.

GETTING STARTED:
Copy this workflow into your account to run it for free.

HOW IT WORKS:

- Event details for any HTTP requests to the endpoint URL 
  for this workflow will be saved to $checkpoint (e.g.,
  (headers, body, query data, etc).

- To query the number of events that were made/saved in 
  $checkpoint, make a request to the workflow endpoint
  with the path `/api/events/count`

- To retrieve the contents for any requests made to this
  workflow, make a request to the worfklow endpoint URL 
  with the path `/api/events/`

- To reset $checkpoint, make a request to the workflow 
  endpoint URL with the path `/api/events/reset`

- To customize this works workflow, just edit the Node.js 
  code below in `steps.process_event_data`  

SAVING DATA TO PIPEDREAM'S SQL SERVICE:

- Enable `steps.sql` at the end of this workflow.

- Add a table name -- Pipedream will automagically create
  a table and schema to match your data.

- Navigate to the SQL tab above to query your data. Data will
  automatically be deleted after 30 days.

You can delete this step at any time (or just move it down 
using the arrovs at the top right of the step). 
*/
steps.
process_event_data
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
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
}
74
// customize the max number of events to save in $checkpoint
const event_cache_size = 1000

if (!Array.isArray($checkpoint)) {
  // if $checkpoint is not an array, instantiate it
  $checkpoint = []
}

const eventCount = $checkpoint.length

if (event.url.indexOf('/api/events/count') !== -1) {
  // if the request URL contains /api/events/count, 
  // return the count of events in $checkpoint
  $respond({
    status: 200,
    headers: {
      'content-type': 'application/json'
    },
    body: JSON.stringify({ eventCount } )
  })
  console.log(`Returned count of events: ${eventCount}`)
} else if (event.url.indexOf('/api/events/reset') !== -1) {
  // if the request URL contains /api/events/reset, set 
  // $checkpoint to an empty array.
  $checkpoint = []
  $respond({
    status: 200,
    headers: {
      'content-type': 'application/json'
    },
    body: JSON.stringify({ 'reset': true })
  })
  console.log('Reset $checkpoint')
} else if (event.url.indexOf('/api/events') !== -1) {
  // if the request URL contains /api/events, return the 
  // event contents.
  $respond({
    status: 200,
    headers: {
      'content-type': 'application/json'
    },
    body: JSON.stringify($checkpoint)
  })
  console.log(`Returned ${eventCount} events.`)
} else { 
  // in all other cases, save the event data to $checkpoint.
  // if the number of events is >= event_cache_size, remove 
  // older items first.
  const overage = eventCount + 1 - event_cache_size
  let eventsRemoved = 0
  if (overage > 0) {
    for (let i = 0; i < overage; i++) {
      $checkpoint.shift(overage)  
    }
    eventsRemoved = overage
  }

  // then add the event to $checkpoint and respond to the client.
  $checkpoint.push(event)
  $respond({
    status: 200,
    headers: {
      'content-type': 'application/json'
    },
    body: JSON.stringify({ 
      'success': true, 
      'eventCount': $checkpoint.length, 
      'oldEventsRemoved': eventsRemoved 
    })
  })
  console.log(`Added event to $checkpoint.`)
}
steps.
sql
Pipedream automatically generates a table and schema based on the event shape.
params
Table Name

Enter the name of the table (e.g., my_table_name) to load the payload data into. Pipedream's SQL service automatically creates the table and adapts the schema to your data.

 
string ·params.table
Payload

Enter a reference to the data (for example, event.body or steps.step_name.return_value) you'd like to insert into the table. Pipedream’s SQL service automatically converts the data to JSON and maps the table schema to its keys.

{{event}}
string ·params.payload
code
async params => {
1
2
3
4
5
}
6
  $send.sql({
    table: params.table,
    payload: params.payload,
  })