-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (41 loc) · 1.24 KB
/
index.js
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
const axios = require("axios");
/**
Example function for writing to a Google Sheet with Workflows
`workflowPayload` contains the object sent to the workflow URL
This is what the data object looks like:
{
"integrationMetadata": {
"sheetId": "YOUR_SHEET_ID",
"sheetTitle": "YOUR_SHEET_TITLE"
},
"auth": {
"oauthToken": "TOKEN"
},
"workflowPayload": {
"name": "John Doe",
"email": ".."
}
}
**/
exports.handler = async (data, context) => {
try {
const { integrationMetadata, auth, workflowPayload } = data;
const url = `https://sheets.googleapis.com/v4/spreadsheets/${integrationMetadata.sheetId}/values/${integrationMetadata.sheetTitle}:append?valueInputOption=USER_ENTERED`;
const headers = {
Authorization: `Bearer ${auth.oauthToken}`,
"Content-Type": "application/json",
};
const newLine = {
values: [Object.values(workflowPayload)],
};
await axios.post(url, newLine, { headers });
return {
message: "Sheet updated successfully",
};
} catch (error) {
console.error("Error creating sheet: ", error.message);
return {
error: error.message
};
}
};