Non-interactive rclone configuration for SharePoint with custom API

2021-03-20

Rclone is a usual way to connect to cloud disks headlessly. Its command rclone config is easy to use but involves trivial steps. This post described a flexible way to setup rclone SharePoint configuration without rclone config.

Rclone always recommend to use rclone config, the interactive way to manipulate its configurations. But this flow becomes cumbersome if we have lots of similar remotes to setup. So here we want to generate rclone configuration files without its built-in interactive rclone config.

Another thing is the rclone’s default API for OneDrive/SharePoint may cause low speed of files transferring (YMMV). That’s to say, a custom API is considered for speed.

Right here, readers are assumed to have some experience of setting up rclone OneDrive/SharePoint configs, or at least know about both rclone and Microsoft SharePoint. Please stop reading if you have no idea about them. BTW, you are welcomed to change any step if you feel like to.

To begin, let’s look at an example template of a sharepoint remote in the rclone.conf file. It’s in a standard INI format.

[your_remote_drive_title] 
type = onedrive
client_id = your_client_id
client_secret = your_client_secret
token = {"access_token":"Lorem-ipsum","token_type":"Bearer","refresh_token":"Lorem-ipsum","expiry":"Lorem-ipsum"}
drive_id = b!Lorem-ipsum
drive_type = documentLibrary

With the template, all we need to do is to fill in the blanks. This requires us to get the values of client_id, client_secret, token, and drive_id one by one.

To get client_id and client_secret, follow this document section to set up our own custom MS API. The registered API can only be authorized within the same organization/domain/tenant, according to Microsoft’s new policy .

To get a token, run the command rclone authorize "onedrive" "your_client_id" "your_client_secret" --auth-no-open-browser and follow the appearing instructions. If everything goes well, the token string will appear on rclone CLI.

Getting drive_id might be the most valuable part of this post, because I didn’t find anyone else reporting this method.

  1. Go to https://your_domain_name.sharepoint.com/sites/your_site_name/_api/site/id to collect the site ID
  2. Log in https://developer.microsoft.com/en-us/graph/graph-explorer with a corresponding organization account. Run GET https://graph.microsoft.com/v1.0/sites/your_site_id/drives, so that we can find the drive_id at value.id of the response JSON.

Now with all required field values obtained, we are able to create a remote in the rclone config file, based on the template showing before.

Here comes the magic to connect 10 sharepoint drives under an MS 365 account: Copy & paste the whole section of one single remote configuration for 9 times, and change only 2 fields in the latter 9 remotes. The title field [my_new_remote_drive] and the drive_id. Isn’t this way much easier than repeating the interactive rclone config 10 times?

OperationGuidercloneapisharepointonedrivems-office-365



Support Me

您可以 打赏 支持本文作者

Upload videos to YouTube Brand Account via API

调查长江水情