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.7 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { googleDriveAuth, createGoogleClient } from '../auth';
import { common } from '../common';
import { drive as googleDrive } from '@googleapis/drive';
import { createNewGdriveFolderActionOutputSchema } from '../output-schemas';

export const googleDriveCreateNewFolder = createAction({
  auth: googleDriveAuth,
  name: 'create_new_gdrive_folder',
  classification: 'WRITE',
  description: 'Create an empty folder in Google Drive.',
  audience: 'human',
  aiMetadata: { description: 'Creates a new empty folder in Google Drive, optionally nested under a parent folder. Use to set up a destination before uploading or moving files. Not idempotent: each call creates a distinct folder even with the same name (Drive permits duplicate folder names).', idempotent: false },
  displayName: 'Create Folder',
  props: {
    folderName: Property.ShortText({
      displayName: 'Folder Name',
      required: true,
      placeholder: 'Invoices 2026',
    }),
    parentFolder: common.properties.parentFolder,
    include_team_drives: common.properties.include_team_drives,
  },
  outputSchema: createNewGdriveFolderActionOutputSchema,
  async run(context) {
    const authClient = await createGoogleClient(context.auth);

    const drive = googleDrive({ version: 'v3', auth: authClient });

    const response = await drive.files.create({
      requestBody: {
        mimeType: 'application/vnd.google-apps.folder',
        name: context.propsValue.folderName,
        ...(context.propsValue.parentFolder
          ? { parents: [context.propsValue.parentFolder] }
          : {}),
      },
      supportsAllDrives: context.propsValue.include_team_drives,
    });

    return response.data;
  },
});