auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
// This is sample data we'll add to Google Sheets
// The data will be available in the variable steps.sample_data.$return_value
return {
"data": [
{ "name": "Luke", "title": "Jedi" },
{ "name": "Leia", "title": "General" }
]
}
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
// For each element in the `data` array above,
// create a new array with the name as the first element, and the title as the second
return steps.sample_data.$return_value.data.map(character => [character.name, character.title])
Enter individual cell values below, or turn structured mode off to pass an array of arrays representing multiple rows of data enclosed in {{...}}
— e.g., {{event.arrayOfArrays}}
or {{[[1,2,3],['a','b','c']]}}
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
.
Enter the name of the tab in the spreadsheet where you want to add data. The default name for new sheets is Sheet1
.
async
(params, auths) => {
}
const { rows } = params
// Validate data input -- check `rows` data is an array of arrays
let inputValidated = true
if (!rows || !rows.length || !Array.isArray(rows)) {
inputValidated = false
} else {
rows.forEach(row => { if(!Array.isArray(row)) { inputValidated = false } })
}
// Throw an error if input validation failed
if(!inputValidated) {
console.error("Data Submitted:")
console.error(rows)
throw new Error("Rows data is not an array of arrays. Please enter an array of arrays in the `Rows` parameter above. If you're trying to send a single rows to Google Sheets, search for the action to add a single row to Sheets or try modifying the code for this step.")
}
// Configure object to post data to Google Sheets
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: rows,
}
}
// Post data to Google Sheets and return transaction metadata
return (await require("@pipedreamhq/platform").axios(this, config)).updates