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 { createAction } from '@activepieces/pieces-framework';
import {
  httpClient,
  HttpMethod,
  AuthenticationType,
} from '@activepieces/pieces-common';
import { oneDriveAuth } from '../auth';
import { oneDriveCommon } from '../common/common';
import { getCloudProp } from '../common/microsoft-cloud';
import { listFoldersOutputSchema } from '../output-schemas';

export const listFolders = createAction({
  auth: oneDriveAuth,
  name: 'list_folders',
  classification: 'SEARCH',
  description: 'List folders in a OneDrive folder',
  audience: 'human',
  aiMetadata: { description: 'List the subfolders contained in a Microsoft OneDrive folder (file items are excluded). Provide a parent folder ID to scope the listing, or leave it empty to list folders at the drive root; useful for discovering a folder ID to pass to other actions. Read-only and idempotent.', idempotent: true },
  displayName: 'List Folders',
  outputSchema: listFoldersOutputSchema,
  props: {
    markdown:oneDriveCommon.parentFolderInfo,
    parentFolder: oneDriveCommon.parentFolder,
  },
  async run(context) {
    const parentId = context.propsValue.parentFolder ?? 'root';
    const cloud = getCloudProp(context.auth);

    const result = await httpClient.sendRequest({
      method: HttpMethod.GET,
      url: `${oneDriveCommon.getBaseUrl(cloud)}/items/${parentId}/children?$filter=folder ne null`,
      authentication: {
        type: AuthenticationType.BEARER_TOKEN,
        token: context.auth.access_token,
      },
    });

    return result.body['value'];
  },
});