Earlier today, I asked you for a code which would take the HEADER out of a Google Doc. It was having the same issue of only grabbing the number and not the rest of the value. You fixed it.
Here is the code that you reworked.
import { axios } from "@pipedream/platform";
export default defineComponent({
props: {
google: {
type: "app",
app: "google",
},
docId: {
type: "string",
label: "Google Doc ID",
},
},
async run({ steps, $ }) {
const response = await axios($, {
url: `https://docs.googleapis.com/v1/documents/${this.docId}`,
headers: {
Authorization: `Bearer ${this.google.$auth.oauth_access_token}`,
},
});
const firstH1 = response.body.content.find(
(element) => element.paragraph && element.paragraph.paragraphStyle.namedStyleType === "HEADING_1"
);
if (firstH1) {
const h1Text = firstH1.paragraph.elements.map(element => element.textRun.content).join("").trim();
return h1Text;
} else {
console.log("No H1 found in the document");
}
},
});
So what I’m looking for is a way to connect to a Google Sheet using variables using the FILE ID, and ‘SHEET 1’ and then adding 3 values in a row.
This was the original code that worked, but cut off after the number:
import { axios } from "@pipedream/platform";
export default defineComponent({
props: {
google: {
type: "app",
app: "google",
},
fileId: {
type: "string",
label: "File ID",
},
sheetName: {
type: "string",
label: "Sheet Name",
},
rowData: {
type: "string[]",
label: "Row Data",
},
},
async run({ $ }) {
const apiUrl = `https://sheets.googleapis.com/v4/spreadsheets/${this.fileId}/values/${encodeURIComponent(this.sheetName)}:append`;
const requestBody = {
range: this.sheetName,
majorDimension: "ROWS",
values: [this.rowData],
};
return await axios($, {
method: "POST",
url: apiUrl,
headers: {
Authorization: `Bearer ${this.google.$auth.oauth_access_token}`,
"Content-Type": "application/json",
},
data: requestBody,
params: {
valueInputOption: "RAW",
},
});
},
});