Google Sheets — Iterate over an array, add multiple rows
@dylburger
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.
nodejs
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
return [
  ["Luke", 1],
  ["Leia", 2],
  ["Han", 3],
]
steps.
add_new_row_to_sheet
auth
to use OAuth tokens and API keys in code via theauths object
(auths.google_sheets)
params
Spreadsheet ID

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

 
123
string ·params.spreadsheetId
Sheet Name

The sheet you'd like to add a row to

Sheet1
string ·params.sheetName
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
const returnData = []
for (const row of steps.nodejs.$return_value) {
  const data = {
    values: [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,
  }
  returnData.push(await require("@pipedreamhq/platform").axios(this, config))
}