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

export const driveGetFile = createAction({
  auth: googleDriveAuth,
  name: 'drive_get_file',
  classification: 'READ',
  displayName: 'Get File or Folder',
  description: 'Get a file folder for files/sub-folders',
  audience: 'ai',
  aiMetadata: {
    description:
      'Fetches metadata for a single file or folder by its exact ID (name, MIME type, parents, owners, links). Use when you already have an ID (e.g. from a trigger or `drive_search_files`) and need its details, including its parent folder IDs. Read-only and safe to retry.',
    idempotent: true,
  },
  outputSchema: driveGetFileOutputSchema,
  props: {
    file_id: Property.ShortText({
      displayName: 'File / Folder ID',
      description:
        'The ID of the file/folder to fetch. Resolve it via `drive_search_files` or `drive_list_files`.',
      required: true,
    }),
  },
  async run(context) {
    const authClient = await createGoogleClient(context.auth);
    const drive = googleDrive({ version: 'v3', auth: authClient });
    const response = await drive.files.get({
      fileId: context.propsValue.file_id,
      supportsAllDrives: true,
    });

    if (response.data) {
      return response.data;
    } else {
      return null;
    }
  },
});