A knowledge base in Enterprise Knowledge Space supports periodic synchronization of files from a SharePoint Online document library or a specified folder within a document library. This is suitable for scenarios where you want to keep the knowledge base content up to date with the source documents. After you register a Microsoft Entra application and grant the required Microsoft Graph permissions, you can create a synchronization link in the PolarDB console to start the synchronization.
Scope of application
Before you begin, make sure that you have prepared the following resources:
-
A PolarDB knowledge base that has been created. For more information, see Use enterprise knowledge spaces.
-
A SharePoint Online organization tenant and the document library to be synchronized.
-
Permissions to register applications in Microsoft Entra, and access to a Microsoft Entra administrator who can grant admin consent.
-
Access permissions to the SharePoint site and document library to be synchronized. You must be able to open the target directory and copy its address. To verify the synchronization of file updates, you also need edit permissions on the synchronized files. The following SharePoint Online environments are supported:
Environment
Example SharePoint domain
Global Microsoft 365
contoso.sharepoint.comMicrosoft 365 operated by 21Vianet
contoso.sharepoint.cnNoteOn-premises SharePoint Server is not supported. Personal OneDrive addresses (whose domain contains
-my.sharepoint.) are not supported either.
Workflow
-
Register a Microsoft Entra application and obtain the directory (tenant) ID and the application (client) ID.
-
Create a client secret for the application.
-
Grant Microsoft Graph SharePoint site read permissions to the application and grant admin consent.
-
Copy the full address of the SharePoint document library or folder to be synchronized.
-
Create a SharePoint synchronization link in PolarDB. Enter the application credentials, SharePoint address, and synchronization interval.
-
Wait for the next synchronization cycle and check the files in the target knowledge base.
NoteSynchronized files are saved in their original format without conversion. Whether a file can be parsed by the knowledge base depends on the file formats currently supported by the knowledge base. For more information, see Synchronization behavior and file formats.
Step 1: Register a Microsoft Entra application
-
Log on to the Microsoft Entra admin center for the tenant to which your SharePoint site belongs.
-
Go to Microsoft Entra ID > App registrations and click New registration.
-
Enter an application name, for example,
PolarDB SharePoint Document Sync. -
Under Supported account types, select Accounts in this organizational directory only (Single tenant) and complete the registration. You do not need to configure a redirect URI.
-
On the Overview page of the application, copy and securely store the following information:
-
Directory (tenant) ID: enter this value in
TenantIdwhen you create the synchronization link. -
Application (client) ID: enter this value in
ClientIdwhen you create the synchronization link.
ImportantDo not use the Object ID as
ClientId. Otherwise, the synchronization link creation will fail. -
Step 2: Create a client secret
-
On the application page, go to Certificates & secrets > Client secrets.
-
Click New client secret, enter a description, and select an expiration period.
-
Immediately copy the value in the Value column after the secret is created. Enter this value in
ClientSecretwhen you create the synchronization link.ImportantThe value of a client secret is displayed only once after it is created. Do not use the Secret ID, and do not transmit the client secret in plain text by email, instant messaging, or screenshots. If you did not copy the value in time, create a new client secret and use the new value to create the synchronization link.
Step 3: Grant Microsoft Graph permissions
-
On the application page, go to API permissions > Add a permission.
-
Select Microsoft Graph > Application permissions.
-
Search for and add the following permission:
API
Permission type
Permission
Purpose
Microsoft Graph
Application
Sites.Read.AllRead the content of SharePoint sites, document libraries, folders, and files.
-
Click Grant admin consent for your organization.
-
Confirm that the permission status shows that consent has been granted for the current organization.
The synchronization task uses the application identity to access Microsoft Graph. Delegated permissions, user sign-in, and redirect URIs are not required. Microsoft Graph requires the Sites.Read.All application permission to resolve site paths. This permission also covers the operations needed to enumerate document libraries, traverse folders, and read files. For more information about the relevant APIs, see the Microsoft documentation: Get a SharePoint site by path, List document libraries, and List folder contents.
Step 4: Get the SharePoint document library or folder address
Each synchronization link supports only one SharePoint document library or one folder within a document library. To synchronize multiple document libraries or directories, create a separate synchronization link for each.
-
Open the SharePoint site to be synchronized in a browser.
-
Go to the target document library:
-
To synchronize the entire document library, stay in the root directory of the document library.
-
To synchronize a single folder, open that folder.
-
-
Copy the full address from the browser address bar.
NoteCopy the document library view address directly from the browser address bar. Do not enter a sharing link or short link of a single file or a personal OneDrive address. You do not need to manually obtain the site ID, document library ID, or folder ID.
Format requirements:
-
Use HTTPS.
-
The domain ends with
.sharepoint.comor.sharepoint.cn. -
The path ends with
/Forms/AllItems.aspx. -
To synchronize a subfolder, the address contains the
idquery parameter that points to that folder.
Examples:
-
Example address for synchronizing an entire document library:
https://contoso.sharepoint.com/sites/Knowledge/Shared%20Documents/Forms/AllItems.aspx -
Example address for synchronizing a specified folder in a document library:
https://contoso.sharepoint.com/sites/Knowledge/Shared%20Documents/Forms/AllItems.aspx?id=%2Fsites%2FKnowledge%2FShared%20Documents%2FProductDocs -
Example address for the 21Vianet environment:
https://contoso.sharepoint.cn/sites/Knowledge/Shared%20Documents/Forms/AllItems.aspx
-
Step 5: Create a SharePoint synchronization link
You can create a SharePoint synchronization link in the console or by calling the CreateKBSyncLink OpenAPI operation.
Console
-
Log on to the PolarDB console.
-
In the left-side navigation pane, choose .
-
On the knowledge space card, click View Details to open the knowledge space details page.
-
Click the target knowledge base to open the knowledge base details page, and then click the Synchronization Link tab.
-
Click Add Synchronization Link and configure the following parameters in the panel that appears.
Parameter
Required
Description
Link Name
Yes
Enter a name for the synchronization link.
IM Platform
Yes
Select SharePoint.
Tenant ID
Yes
The directory (tenant) ID in Microsoft Entra.
Client ID
Yes
The application (client) ID in Microsoft Entra.
Secret
Yes
The value of the client secret.
Sync Directory
Yes
The full address of the document library or folder copied in Step 4.
Sync Interval (Minutes)
No
The synchronization interval. The value must be a positive integer in the range of 1 to 1440. Default value:
30. Recommended value:10.Sync Link Notes
No
Optional. A description of the link.
-
Click OK.
OpenAPI
Call the CreateKBSyncLink operation to create the link. The following table describes the parameters.
|
Parameter |
Example |
Description |
|
|
|
The region where the knowledge base is located. |
|
|
|
The ID of the target knowledge base. |
|
|
SharePoint Product Doc Sync |
The name of the synchronization link. |
|
|
|
Set the value to |
|
|
|
The directory (tenant) ID in Microsoft Entra. |
|
|
|
The application (client) ID in Microsoft Entra. |
|
|
|
The value of the client secret. |
|
|
|
The full address of the document library or folder copied in Step 4. |
|
|
|
The synchronization interval in minutes. The value must be a positive integer in the range of 1 to 1440. Recommended value: |
|
|
Synchronize SharePoint product documents |
Optional. A description of the link. |
When you create the link, PolarDB uses the application credentials that you entered to access Microsoft Graph and verifies that the target site, document library, and folder are readable. After the link is created, the system returns a synchronization link ID that starts with pkbl-. Keep a record of this ID. It is required when you query the link, adjust the synchronization interval, or delete the link.
Step 6: Verify the synchronization result
-
Confirm that the synchronization link has been created and that the link status is normal.
-
Wait for at least one synchronization cycle. The first synchronization needs to recursively scan directories, download files, and complete ingestion and indexing. It may take longer if there are many files.
-
Open the file list of the target knowledge base and confirm that files from SharePoint have appeared.
-
Modify a synchronized SharePoint file, wait for the next synchronization cycle, and check whether the file in the knowledge base has been updated.
Synchronization behavior and file formats
-
The system recursively scans the subfolders in the selected document library or folder.
-
SharePoint files are downloaded and synchronized in their original format and are not converted to other formats.
-
Whether a file can be parsed by the knowledge base depends on the file formats currently supported by the knowledge base.
-
SharePoint list items, web pages, and folders that are used only as directories are not synchronized as files.
-
The current version synchronizes new and updated files, but does not automatically delete files in the knowledge base when the corresponding files are deleted from the SharePoint source. To delete such files, handle them separately in the knowledge base.
-
TenantId,ClientId, andClientSecretmust belong to the target SharePoint organization tenant. The cloud environment of the application must match the cloud environment of the SharePoint address: a global Microsoft 365 tenant uses.sharepoint.comaddresses, and a Microsoft 365 tenant operated by 21Vianet uses.sharepoint.cnaddresses.
FAQ
-
Q: The synchronization link fails to be created.
A: Check the following items in order:
-
Whether
TenantIdis the directory (tenant) ID. -
Whether
ClientIdis the application (client) ID rather than the Object ID. -
Whether
ClientSecretis the value of the client secret, whether it is complete, and whether it is still valid. -
Whether
Sites.Read.Allis added as an application permission and admin consent has been granted. -
Whether
SourceDiris the full document library view address from the browser address bar and ends with/Forms/AllItems.aspx. -
Whether the application tenant and the SharePoint address belong to the same organization and use the same environment (global Microsoft 365 or Microsoft 365 operated by 21Vianet).
-
-
Q: Only some files are synchronized.
A: Common causes include:
-
SourceDirpoints to a subfolder in the document library rather than the root directory of the document library. -
The formats of some files are not within the parsable scope of the knowledge base.
-
The ingestion or indexing of the files has not been completed.
-
-
Q: Modified files are not updated immediately.
A: The synchronization task runs at the interval specified by
SyncIntervalMinutes. After the source files are downloaded, ingestion and indexing are still required. Wait for the next synchronization cycle and allow time for file processing.