Function getSharepointApi

  • Gets SharePoint data. This function initializes and returns a SharePointApi instance. To set up the necessary options for SharePoint access, follow these steps:

    1. Create an App Registration in SharePoint:

      • Navigate to https://{DOMAIN}.sharepoint.com/sites/{SITE_NAME}/_layouts/15/appregnew.aspx.
      • Generate a Client ID and Secret.
      • Name the application.
      • Set the App domain to 'localhost' and the Redirect URI to 'https://localhost'.
      • Save the generated Client ID and Secret.
    2. Grant Permissions to the App:

      • Go to https://{DOMAIN}.sharepoint.com/sites/{SITE_NAME}/_layouts/15/appinv.aspx.
      • Enter the App ID and click 'lookup'.
      • Provide the Permission Request XML: <AppPermissionRequests AllowAppOnlyPolicy="true"><AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web/list" Right="FullControl" /></AppPermissionRequests>.
      • Select the desired list/folder and click 'trust'.
      • Repeat this step for multiple lists/folders as needed.
    3. Retrieve Tenant ID:

      • Run the following curl command:
        curl --location 'https://{DOMAIN}.sharepoint.com/sites/{SITE}/_vti_bin/client.svc/' --header 'Authorization: Bearer'
        
      • Note: The 'client_id' in the response is different from the one saved in step 1.
    4. Configure SharePoint Options:

      • Set clientId to {CLIENT_ID}@{TENANT_ID}.
      • Set clientSecret to {CLIENT_SECRET}.
      • Set tenantId to {TENANT_ID}.
      • Set resource to {TENANT}/{DOMAIN}@{TENANT_ID}.
      • Include the domain and siteName as well.

    Parameters

    Returns Promise<SharepointAPI>

    A SharePointApi instance.

    const sharePointOptions: SharePointOptions = {
    clientId: 'clientId',
    clientSecret: 'clientSecret',
    tenantId: 'tenantId',
    resource: 'resource',
    domain: 'domain',
    siteName: 'siteName',
    };
    const msApi = await getSharepointApi(ctx, sharePointOptions);
    const file = await msApi.getFileByName('folderName', 'fileName', 'mimeType');

    use graph api instead