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

export const googleDriveGetResourceById = createAction({
  auth: googleDriveAuth,
  name: 'get-file-or-folder-by-id',
  classification: 'READ',
  displayName: 'Get File Information',
  description: 'Get the details of a file or folder by its ID.',
  audience: 'human',
  aiMetadata: { description: 'Fetches metadata for a single file or folder in Google Drive by its exact ID (name, MIME type, parents, etc.). Use when an agent already has a file/folder ID and needs its details. Read-only and idempotent. Requires the resource ID, not a name or path.', idempotent: true },
  props: {
    id: Property.ShortText({
      displayName: 'File or Folder ID',
      description: "The ID from the item's Drive URL or an earlier step.",
      required: true,
      placeholder: '1dpv4-sKJfKRwI9qx1vWqQhEGEn3EpbI5',
    }),
    include_team_drives: common.properties.include_team_drives,
  },
  outputSchema: getFileOrFolderByIdActionOutputSchema,
  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.id,
      supportsAllDrives: context.propsValue.include_team_drives,
    });

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