Google Sheets Example - reference array via variable
@dylan
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 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.
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
// The variable `event.body` contains the HTTP payload.
// It's often easiest to construct the array of row data 
// Google Sheets expects for a new row in a code step,
// so we do that here and reference the variable below

// Assumes event.body contains a name and title property,
// which we add to our Google Sheet.
const { name, title } = event.body

// We can reference this data in future steps using steps.data.array
// See https://docs.pipedream.com/workflows/steps/#step-exports
this.array = [name, title]
steps.
add_new_row_to_sheet
Add a row to a sheet using the append API: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append
auth
(auths.google_sheets)
params
Row

The array of data representing the cells of the row, for example [1, 2, 3]

[0]:
 
array ·params.row
Spreadsheet ID

The ID of the target spreadsheet, found at the end of the URL: https://docs.google.com/spreadsheets/d/{id}

11Gl7ay0HHGdZyGwRYFI_jLtIt_WORuR7fqmqDzh7YQo
string ·params.spreadsheetId
Sheet Name

The sheet you'd like to add a row to

Sheet1
string ·params.sheetName
code
async (params, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
}
18
const data = {
  values: [params.row],
}
const config = {
  method: "post",
  url: `https://sheets.googleapis.com/v4/spreadsheets/${params.spreadsheetId}/values/${params.sheetName}:append`,
  params: {
    includeValuesInResponse: true,
    valueInputOption: "USER_ENTERED"
  },
  headers: {
    Authorization: `Bearer ${auths.google_sheets.oauth_access_token}`,
  },
  data,
}
return await require("@pipedreamhq/platform").axios(this, config)