All Products
Search
Document Center

Data Transmission Service:Connect Lark to a DTS RAGFlow knowledge base

Last Updated:Jul 17, 2026

You can transfer data from Lark to a RAGFlow knowledge base in Data Transmission Service (DTS). Supported data types include Lark Docs, Sheets, Bitable, and Wiki.

Prerequisites

You have created a RAGFlow knowledge base in DTS and configured an IP whitelist.

Background information

Supported data types

DTS RAGFlow supports data from Lark Docs, Sheets, Bitable, and Wiki.

Access methods

Lark data can be accessed by using either an application access token (tenant_access_token) or a user access token (user_access_token).

Method

Permission type

Pros

Cons

tenant_access_token (Recommended)

Application identity

  • Supports resumable transfer.

  • Requires only a one-time configuration for transferring a single folder or Wiki.

More complex authorization. You must configure separate access permissions for Drive and Wiki.

user_access_token

User identity

Simpler authorization. Grants access to all folders without requiring separate permissions for Drive and Wiki.

  • You must obtain a new Lark authorization code every time you run the KBSync program.

  • The Lark authorization code expires.

Before you begin

  1. Log in to the Lark Open Platform, and go to the Developer Console.

  2. Create an app.

    You can click Create Enterprise-developed Application, configure related information such as Name and Application Description, and then click Create.

  3. Click the app card to open its configuration page.

    By default, you are on the Basic Information > Credentials and Basic Information page.

  4. On the Credentials and Basic Information page, in the Application Credentials section, record the App ID and App Secret.

Procedure

Note

For detailed instructions on Lark, see the official Lark documentation (Help Center and development documents).

Step 1: Configure access permissions

Application access token

  1. Log in to the Lark Open Platform, and go to the Developer Console.

  2. Click the app that you created in the Before you begin section.

  3. Add a bot and release the app.

    1. In the left navigation bar, select Application Capabilities > Add Application Capability.

    2. On the Add by Capability tab, in the card for the bot, click Add.

    3. At the top of the page, click Create Version.

      Note

      Alternatively, in the left navigation bar, select App Publishing > Version Management and Publishing, and then click Create Version.

    4. On the Version Details page, enter the Application Version and Update Description.

      Note

      You can use the default bot for the default mobile client capabilities and default desktop client capabilities.

    5. Click Save.

    6. In the dialog box that appears, click Confirm Publish.

  4. Configure API permissions.

    1. In the left navigation bar, select Development Configuration > Permission Management.

    2. Click Batch Import/Export Permissions.

    3. On the Import tab, in the JSON text box, configure the following user identity permissions for the application.

      {
        "scopes": {
          "tenant": [
            "docs:document:export",
            "drive:drive",
            "wiki:wiki"
          ],
          "user": []
        }
      }
    4. Click Next to confirm the new permissions.

    5. Click Activate Now.

  5. Log in to the Lark client, create a new group, and add the application that you created in the Preparations section as a group bot.

  6. Configure access permissions for Drive and Wiki.

    Drive permissions

    1. Go to the target folder in Drive.

    2. On the right side of the page, click Share.

    3. For Invite collaborators, add the group that you created in Step 5.

      The default Read permission is sufficient for this purpose.

    4. Click Send.

    Wiki permissions

    1. Go to the All Wikis page.

    2. Move the pointer over the target knowledge base, and then click Knowledge Base Settings.

    3. Click the Member Settings tab, and on the Administrator tab in the Roles and Permissions area, click Add Administrator.

    4. In the dialog box that appears, add the group that you created in Step 5, and click Next.

    5. Click Send.

User access token

  1. Log in to the Lark Open Platform, and go to the Developer Console.

  2. Click the app that you created in the Before you begin section.

  3. Configure API permissions.

    1. In the left navigation bar, select Development Configuration > Permission Management.

    2. Click Batch Import/Export Permissions.

    3. Paste the following JSON to grant the required user identity permissions to the app you created.

      {
        "scopes": {
          "tenant": [],
          "user": [
            "offline_access",
            "docs:document:export",
            "drive:drive",
            "wiki:wiki"
          ]
        }
      }
    4. Click Next, Confirm New Permissions.

    5. Click Activate Now.

  4. Configure the redirect URL.

    1. In the left navigation bar, select Development Configuration > Security Settings.

    2. In the Redirect URL text box, enter https://www.aliyun.com.

    3. Click Add to the right of the text box.

    4. Turn on the Refresh user_access_token switch.

      Note

      If this switch is not visible, the feature is enabled by default.

  5. Obtain the authorization code.

    1. Construct the URL for the Lark authorization page.

      Note

      You must replace YOUR_FEISHU_CLIENT_ID in the URL with the App ID recorded in Preparations.

      https://accounts.feishu.cn/open-apis/authen/v1/authorize?client_id=YOUR_FEISHU_CLIENT_ID&redirect_uri=https://www.aliyun.com&scope=drive:drive offline_access docs:document:export wiki:wiki
    2. Open the authorization page in a browser.

    3. Click Authorize.

    4. Obtain the authorization code (code) from the redirect URL.

      Note

      The authorization code does not include code=, &, or information that follows the & symbol.

Step 2: Get the Lark folder token and Wiki ID

  1. Log on to the Lark client.

  2. Obtain the folder token for the Lark Docs folder.

    1. Go to the target folder.

    2. From the address bar of your browser, copy the URL for the folder.

    3. Obtain the token from the URL (the information after folder/).

      Note

      The token does not include the ? or any information that follows.

  3. Obtain the ID of the Wiki.

    1. Go to the All Wikis page.

    2. Move the pointer over the target knowledge base, and then click Knowledge Base Settings.

    3. From the address bar of your browser, copy the URL for the target Wiki.

    4. Obtain the knowledge base ID from the URL (the string after settings/).

      Note

      The knowledge base ID is purely numeric and does not include the # symbol or any information that follows it.

Step 3: Run the KBSync program

  1. Obtain the KBSync file.

    Note

    You can join the DingTalk group (ID: 79690034672) and contact technical support to obtain the KBSync file.

  2. Prepare the runtime environment for the KBSync program.

    Note

    The KBSync program requires a Linux environment with access to the Lark Open Platform and RAGFlow.

  3. Prepare the config file.

    1. Create a Linux system file named config.

    2. Copy the following code to the config file.

      whiteList=
      blackList=
      sinkType=RagFlow
      sourceType=FeiShu
      ragflowUrl=http://XX.XX.XX.XX
      ragflowApiKey=Bearer RAGFlow-BmND******MDI0Mm
      ragflowDatasetId=928d061******2ac120006
      feishuAppId=cli_a8a******d00d
      feishuAppSecret=pMp73Si******UDrWXBSOa
      feishuUserAccessCode=bGzpx6******B9KFCdzdCDHG
      feishuCloudSpaceDirToken=ESJm*******CRdn002cii3bnAc
      feishuWikiSpaceId=7504968******8674
    3. Replace the parameters in the config file.

      Important
      • For parameters that you do not need to configure, leave the value empty.

      • If you provide values for both the feishuCloudSpaceDirToken and feishuWikiSpaceId parameters, only Lark Docs and their parent folders are transferred because only the feishuCloudSpaceDirToken parameter takes effect.

      • The blackList parameter has a higher priority than the whiteList parameter.

      Parameter

      Required

      Description

      How to obtain

      whiteList

      No

      The paths of files to transfer (whitelist) and files to exclude (blacklist). These paths include folder paths in Lark Docs and document paths in the knowledge base.

      Note

      Regular expressions are supported. Separate multiple paths with spaces.

      Obtain the paths from the Lark client.

      blackList

      No

      sinkType

      Yes

      The type of the destination.

      Set this parameter to RagFlow.

      sourceType

      Yes

      The type of the source.

      Set this parameter to Feishu.

      ragflowUrl

      Yes

      The address of RAGFlow (API server).

      Obtain the API server address of the RAGFlow knowledge base.

      ragflowApiKey

      Yes

      The API key for the RAGFlow knowledge base.

      Obtain the API key for the RAGFlow knowledge base.

      ragflowDatasetId

      Yes

      The ID of the RAGFlow knowledge base.

      Obtain the ID of the RAGFlow knowledge base.

      feishuAppId

      Yes

      The ID of the application in Lark (App ID).

      Obtain the App ID and App Secret.

      feishuAppSecret

      Yes

      The secret of the application in Lark (App Secret).

      feishuUserAccessCode

      No

      Note

      This parameter is required only when you access Lark data using the user_access_token method.

      The authorization code for Lark.

      Obtain the authorization code.

      feishuCloudSpaceDirToken

      No

      Note

      Pass a value for only one of these parameters.

      The token for the folder that contains the Lark Docs.

      Obtain the token for the Lark Docs folder and the ID of the knowledge base.

      feishuWikiSpaceId

      The ID of the Lark knowledge base.

  4. Place the KBSync file and the config configuration file in the same directory in a Linux environment.

  5. In your Linux environment, run the ./KBSync --config config command to start the KBSync program.

    The following output indicates that KBSync is running correctly.

    ./KBSync --config config
    
    INFO config whiteList=, blackList=
    INFO config ragflowUrl=http://XX.XX.XX.XX/, ragflowApiKey=Bearer RAGFlow-BmND******MDI0Mm
    INFO config ragflowDatasetId=928d061******2ac120006
    INFO config feishuAppId=cli_a8a******d00d, feishuAppSecret=pMp73Si******UDrWXBSOa
    INFO Response from https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal: 200, headers: {'Server': 'Tengine', 'Content-Type': 'application/json', 'Content-Length': '102', 'Connection': 'keep-alive', 'Date': 'Tue, 08 Jul 2025 02:49:01 GMT', 'Request-Id': '25bf****-d386-4a86-****-f440f070****', 'Tt_st****': '1', 'X-Lgw-Dst-Svc': 'jbpiSR****OiA0J3d****-Oz0xugYAH9otZIFg4x****', 'X-Request-Id': '25bf****-d386-4a86-b9f4-f440f070****', 'X-Tt-Logid': '202507081049012933B870245850D****', 'server-timing': 'inner; dur=73, cdn-cache;desc=MISS,edge;dur=0,origin;dur=129', 'x-tt-trace-host': '****', 'x-tt-trace-tag': '****', 'x-tt-trace-id': '00-****', 'X-Timestamp': '175194****.952', 'Via': 'cache8.cn6540[129,0]', 'Timing-Allow-Origin': '*', 'EagleId': '6ae3651c1751942941849****'}, body: b'{"code":0,"expire":4340,"msg":"ok","tenant_access_token":"t-g10478a*******CSC3YVY"}'
    INFO set feishu tenant access token expires in: 4340

Appendix

Get the RAGFlow API server address

  1. Log on to the RAGFlow page.

  2. In the navigation pane on the left, click API.

  3. Obtain the API server.

Get the RAGFlow API key

  1. Log on to the RAGFlow page.

  2. In the navigation pane on the left, click API.

  3. To the right of RAGFlow API, click API KEY.

  4. In the API KEY dialog box, click Create New Key.

  5. Click image to copy the key, and then save it in a secure location.

Get the RAGFlow knowledge base ID

  1. Log on to the RAGFlow page.

  2. On the Knowledge Base page, click the target knowledge base.

  3. In the URL in your browser's address bar, copy the knowledge base ID.

    Note

    The knowledge base ID is the string of characters that follows id=.