Skip to content

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

1.8 KB
Raw Blame
import { googleSheetsAuth } from '../common/common';
import { createAction } from '@activepieces/pieces-framework';
import { includeTeamDrivesProp, sheetIdProp, spreadsheetIdProp } from '../common/props';
import { sheets as googleSheets } from '@googleapis/sheets';
import { createGoogleClient } from '../common/common';
import { deleteWorksheetActionOutputSchema } from '../output-schemas';

export const deleteWorksheetAction = createAction({
    auth: googleSheetsAuth,
    name: 'delete-worksheet',
    classification: 'DESTRUCTIVE',
    displayName: 'Delete Worksheet',
    description: 'Permanently delete a specific worksheet.',
    audience: 'human',
    aiMetadata: {
        description:
            'Permanently removes one worksheet (tab) from a spreadsheet, identified by its stable sheet id. Use when an agent needs to drop an entire tab and its data. Idempotent on the stable sheet id — the tab ends up absent; this is destructive and cannot be undone.',
        idempotent: true,
    },
    props: {
        includeTeamDrives: includeTeamDrivesProp(),
        spreadsheetId: spreadsheetIdProp('Spreadsheet', 'The spreadsheet to work in.'),
        sheetId: sheetIdProp('Worksheet', 'The tab to delete.'),
    },
    outputSchema: deleteWorksheetActionOutputSchema,
    async run(context) {
        const authClient = await createGoogleClient(context.auth);
        const sheets = googleSheets({ version: 'v4', auth: authClient });

        const response = await sheets.spreadsheets.batchUpdate({
            spreadsheetId: context.propsValue.spreadsheetId,
            requestBody: {
                requests:[
                    {
                       deleteSheet:{
                        sheetId:context.propsValue.sheetId
                       }
                    }
                ]
            },
        });

        return response.data;
    },
});