Google Sheets Example: add row to Google sheets with hardcoded data
@dylburger
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 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.
add_single_row_to_sheet
Add a single row of data to Google Sheets
auth
(auths.google_sheets)
params
Columns

Enter the data to insert into each column. Click + to add columns in structured mode, or turn structured mode off to enter array of column values as an expression — e.g., {{[1,2,3]}}

[0]:
Luke
[1]:
Jedi
array ·params.columns
Spreadsheet ID

The spreadsheet ID can be extracted from its URL. E.g., the spreadsheet ID in the URL docs.google.com/spreadsheets/d/abc1234567/edit#gid=0 is abc1234567.

1lDCfU081VCB5Wi7eDYmV31o0Y0ZcmBpOu-JU0u7zync
string ·params.spreadsheetId
Sheet Name

Enter the name of the tab in the spreadsheet where you want to add data. The default name for a new sheet is Sheet1.

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
19
20
21
22
23
24
25
26
27
}
28
const { columns } = params

// validate input
if (!columns || !columns.length) {
  throw new Error("Please enter an array of elements in the `Columns` parameter above")
} else if (!Array.isArray(columns)) {
  throw new Error("Column data is not an array. Please enter an array of elements in the `Columns` parameter above.")
} else if (Array.isArray(columns[0])) {
  throw new Error("Column data is a multi-dimensional array. A one-dimensional is expected. If you're trying to send multiple rows to Google Sheets, search for the action to add multiple rows to Sheets, or try modifying the code for this step.")
}

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: {
   values: [columns],
  }
}
return (await require("@pipedreamhq/platform").axios(this, config)).updates