Skip to content

Function: getSharepointApi()

ts
function getSharepointApi(ctx: Context, options: SharepointOptions): Promise<SharepointAPI>;

Defined in: src/ms-graph/sharepoint.ts:223

Parameters

ParameterTypeDescription
ctxContextThe SDK context.
optionsSharepointOptionsThe SharePoint connection options.

Returns

Promise<SharepointAPI>

A SharePointAPI instance with file and list operations.

Deprecated

Use the Graph API instead.

Create a SharePoint REST API client. Return an object with methods for files, lists, and folders.

Set up SharePoint access in four steps:

  1. Register an app at https://{DOMAIN}.sharepoint.com/sites/{SITE_NAME}/_layouts/15/appregnew.aspx. Generate a Client ID and Secret. Set the App domain to localhost and Redirect URI to https://localhost.

  2. Grant permissions at https://{DOMAIN}.sharepoint.com/sites/{SITE_NAME}/_layouts/15/appinv.aspx. Enter the App ID, click lookup, provide the Permission Request XML, and trust the list or folder.

  3. Retrieve your Tenant ID:

    bash
    curl --location 'https://{DOMAIN}.sharepoint.com/sites/{SITE}/_vti_bin/client.svc/' --header 'Authorization: Bearer'
  4. Configure SharePoint options: set clientId to {CLIENT_ID}@{TENANT_ID}, clientSecret, tenantId, resource to {TENANT}/{DOMAIN}@{TENANT_ID}, plus domain and siteName.

Example

ts
const sharepointOptions = {
  clientId: 'abc123@tenant-id',
  clientSecret: 'superSecret42',
  tenantId: 'tenant-id',
  resource: '00000003-0000-0ff1-ce00-000000000000/contoso.sharepoint.com@tenant-id',
  domain: 'https://contoso.sharepoint.com',
  siteName: 'ProjectAlpha',
};
const api = await getSharepointApi(ctx, sharepointOptions);
const file = await api.getFileByName('Invoices', 'invoice-007.pdf', 'application/pdf');

Matterway Assistant SDK Documentation