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 { microsoftSharePointAuth } from '../auth';
import { createAction, Property } from '@activepieces/pieces-framework';
import { getGraphBaseUrl } from '../common/microsoft-cloud';
import { microsoftSharePointCommon } from '../common';
import { Client } from '@microsoft/microsoft-graph-client';

export const getSiteInformationAction = createAction({
  auth: microsoftSharePointAuth,
  name: 'microsoft_sharepoint_get_site_information',
  classification: 'READ',
  displayName: 'Get Site Information',
  description: 'Fetch metadata of a SharePoint site (site ID, title, URL, description, etc.).',
  audience: 'both',
  aiMetadata: {
    description: 'Fetches metadata for a single SharePoint site by its site ID (title, URL, description, and similar properties), with optional field selection. Use to inspect or confirm site details once you have its ID. Read-only and idempotent.',
    idempotent: true,
  },
  props: {
    siteId: microsoftSharePointCommon.siteId,
    select: Property.ShortText({
        displayName: 'Select Fields (Optional)',
        description: 'A comma-separated list of properties to return. If left blank, all default properties are returned. Example: `id,displayName,webUrl,description`',
        required: false,
    }),
  },
  async run(context) {
    const { siteId, select } = context.propsValue;

    const cloud = context.auth.props?.['cloud'] as string | undefined;
    const client = Client.initWithMiddleware({
      authProvider: {
        getAccessToken: () => Promise.resolve(context.auth.access_token),
      },
      baseUrl: getGraphBaseUrl(cloud),
    });

    const request = client.api(`/sites/${siteId}`);
    
    if (select) {
        request.select(select.split(',').map(s => s.trim()));
    }

    return await request.get();
  },
});