AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
import { Property, createAction } from '@activepieces/pieces-framework';
import { HttpError } from '@activepieces/pieces-common';
import { areSheetIdsValid, googleSheetsCommon, mapRowsToHeaderNames } from '../common/common';
import { googleSheetsAuth } from '../common/common';
import { commonProps } from '../common/props';
import { findRowByNumActionOutputSchema } from '../output-schemas';
export const findRowByNumAction = createAction({
auth: googleSheetsAuth,
name: 'find_row_by_num',
classification: 'READ',
displayName: 'Get Row by Number',
description: 'Retrieve one row by its row number.',
audience: 'human',
aiMetadata: {
description:
'Reads a single row from a worksheet by its row number, optionally keyed by header names instead of column letters. Use when an agent already knows the exact row to fetch. Read-only and idempotent.',
idempotent: true,
},
propertyGroups: [
{
key: 'spreadsheet',
display: 'section',
label: 'Spreadsheet',
icon: 'file',
props: ['spreadsheetId', 'sheetId'],
},
{
key: 'target_row',
display: 'section',
label: 'Row',
icon: 'markdown',
props: ['rowNumber', 'headerRow'],
},
],
props: {
...commonProps,
rowNumber: Property.Number({
displayName: 'Row Number',
description: 'The row to retrieve, counting from 1.',
required: true,
}),
headerRow: Property.Number({
displayName: 'Header Row',
description: 'The row that contains the column names.',
required: true,
defaultValue: 1,
}),
useHeaderNames: Property.Checkbox({
displayName: 'Use Column Names',
description: 'Key each row by column name instead of A, B, C.',
required: false,
defaultValue: true,
advanced: true,
}),
},
outputSchema: findRowByNumActionOutputSchema,
async run(context) {
const { spreadsheetId, sheetId, rowNumber, headerRow, useHeaderNames } = context.propsValue;
if (!areSheetIdsValid(spreadsheetId, sheetId)) {
throw new Error('Please select a spreadsheet and sheet first.');
}
let rows: Awaited<ReturnType<typeof googleSheetsCommon.getGoogleSheetRows>>;
try {
rows = await googleSheetsCommon.getGoogleSheetRows({
auth: context.auth,
sheetId: sheetId as number,
spreadsheetId: spreadsheetId as string,
rowIndex_s: rowNumber,
rowIndex_e: rowNumber,
headerRow: headerRow,
});
} catch (error) {
if (isRowOutOfGridError(error)) {
return {
found: false,
row: null,
};
}
throw error;
}
if (rows.length === 0) {
return {
found: false,
row: null,
};
}
const finalRows = await mapRowsToHeaderNames(
rows,
useHeaderNames ?? false,
spreadsheetId as string,
sheetId as number,
headerRow,
context.auth,
);
return {
found: true,
row: finalRows[0].row,
values: finalRows[0].values,
};
},
});
function isRowOutOfGridError(error: unknown): boolean {
const pattern = /exceeds grid limits/i;
if (error instanceof HttpError) {
const apiMessage = extractApiErrorMessage(error.response?.body);
if (apiMessage !== undefined && pattern.test(apiMessage)) {
return true;
}
}
if (error instanceof Error) {
return pattern.test(error.message);
}
return false;
}
function extractApiErrorMessage(body: unknown): string | undefined {
if (typeof body === 'string') {
return body;
}
if (!body || typeof body !== 'object' || !('error' in body)) {
return undefined;
}
const inner = body.error;
if (!inner || typeof inner !== 'object' || !('message' in inner)) {
return undefined;
}
const message = inner.message;
return typeof message === 'string' ? message : undefined;
}