Appearance
Function: getSharepointApi()
ts
function getSharepointApi(ctx: Context, options: SharepointOptions): Promise<SharepointAPI>;Defined in: src/ms-graph/sharepoint.ts:223
Parameters
| Parameter | Type | Description |
|---|---|---|
ctx | Context | The SDK context. |
options | SharepointOptions | The 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:
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 tolocalhostand Redirect URI tohttps://localhost.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.Retrieve your Tenant ID:
bashcurl --location 'https://{DOMAIN}.sharepoint.com/sites/{SITE}/_vti_bin/client.svc/' --header 'Authorization: Bearer'Configure SharePoint options: set
clientIdto{CLIENT_ID}@{TENANT_ID},clientSecret,tenantId,resourceto{TENANT}/{DOMAIN}@{TENANT_ID}, plusdomainandsiteName.
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');