How to Retrieve the Last Row of Data in a Google Sheets Workflow?

This topic was automatically generated from Slack. You can find the original thread here.

I have a workflow where the triggered by GOOGLE SHEET - NEW ROW ADDED.

How can I get the last row of data?

To get the last row of data when using the “Google Sheets - New Row Added” trigger, you can access the row data in the steps.trigger.event object. Here’s an example of how to use the row data in a code step: ```
export default defineComponent({ async run({ steps }) { // Access the last row data from the trigger step const lastRowData = steps.trigger.event; // Use the lastRowData as needed console.log(“Last row data:”, lastRowData); }, });

I would like to pull the last row of data from the Google Spreadsheet.

I would like to tell it which Google Spreadsheet to pull by ID.

To pull the last row of data from a Google Spreadsheet by its ID, you can use the Google Sheets API. Here’s a Pipedream component that retrieves the last row of data from a specified Google Sheet: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google: { type: "app", app: "google", }, sheetId: { type: "string", label: "Google Sheet ID", }, }, async run({ steps, $ }) { // Get the sheet metadata to find the sheet name const sheetMetadata = await axios($, { url: `https://sheets.googleapis.com/v4/spreadsheets/${this.sheetId}`, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, }, }); const sheetName = sheetMetadata.sheets[0].properties.title; // Get the sheet data const sheetData = await axios($, { url: `https://sheets.googleapis.com/v4/spreadsheets/${this.sheetId}/values/${sheetName}`, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, }, }); // Get the last row of data const lastRowData = sheetData.values.pop(); console.log("Last row data:", lastRowData); return lastRowData; }, }); Replace sheetId prop with the ID of the Google Spreadsheet you want to pull data from. This component will retrieve the last row of data from the first sheet in the specified Google Spreadsheet.