Microsoft OneDrive

The Microsoft OneDrive connector is a Palantir-provided driver for Microsoft OneDrive.

To create a new Microsoft OneDrive source, follow the standard setup flow for Palantir-provided drivers, then use the sections below for Microsoft OneDrive-specific configuration and networking. For the complete property reference, see the official Microsoft OneDrive driver documentation ↗.

Beta

The Microsoft OneDrive connector is in the beta phase of development and may not be available on your enrollment. Functionality may change during active development.

Supported capabilities

CapabilityStatus
Exploration🟡 Beta
Batch syncs🟡 Beta
Incremental🟡 Beta
OAuth 2.0 authentication🟡 Beta

Introduction

The Microsoft OneDrive connector reads files, folders, drives, permissions, and sharing metadata through Microsoft Graph. For scheduled reads, use a batch sync to write selected tables to a dataset.

To download a file, call the DownloadFile stored procedure in a batch sync. Alternatively, use a OneDrive source in code to download, upload, or replace files.

Authentication

Set AuthScheme=AzureAD to access Microsoft OneDrive as a user through delegated authentication.

Delegated user authentication (AzureAD)

With AuthScheme=AzureAD, the source accesses Microsoft OneDrive as the user who authorizes the connection.

  1. Register an application in the Microsoft Entra admin center ↗. Record its client ID, generate a client secret, and note the tenant ID or domain.
  2. Grant the application a delegated Microsoft Graph file permission for the required access, such as Files.Read.All. Add Files.ReadWrite.All when the user must write files. An administrator may need to grant consent, depending on the tenant's consent policy.
  3. Create the source and set AuthScheme=AzureAD, AzureTenant, OAuthClientId, OAuthClientSecret, and InitiateOAuth=REFRESH.
  4. Copy the source's generated CallbackURL into the application as a Web redirect URI. Save the source, select Authorize, and sign in as the user whose OneDrive the source should access.

Reading data

The tables available in the source explorer contain metadata about OneDrive files, folders, drives, permissions, and sharing, rather than the files' contents. Select a table and set up a batch sync to read this metadata into a dataset.

Download files

To download a file, use the DownloadFile stored procedure ↗ in a batch sync or use a OneDrive source in code.

For a batch sync, add the following query to the sync definition:

Copied!
1 EXECUTE DownloadFile ResourceId = '1234'

The output dataset stores the file contents as a Base64-encoded string. Decode the string to binary in a downstream transform.

Microsoft OneDrive sync extracting a file using a stored procedure.

The screenshot sets Encoding='NONE'. Leave Encoding unset, as in the query above, to receive Base64-encoded file contents.

Configuration

The properties below are mandatory or recommended.

PropertyRequired?DescriptionDefault
AuthScheme ↗RecommendedSpecifies the type of authentication to use when connecting to Microsoft OneDrive. If this property is left blank, the default authentication is used.AzureServicePrincipal
AzureTenant ↗RecommendedIdentifies the Microsoft OneDrive tenant being used to access data, either by name (for example, contoso.onmicrosoft.com) or ID. (Conditional).—
InitiateOAuth ↗RecommendedSpecifies the process for obtaining or refreshing the OAuth access token, which maintains user access while an authenticated, authorized user is working.GETANDREFRESH
OAuthClientId ↗RecommendedSpecifies the client Id that was assigned when the custom OAuth application was created. (Also known as the consumer key.) This ID registers the custom application with the OAuth authorization server.—
OAuthClientSecret ↗RecommendedSpecifies the client secret that was assigned when the custom OAuth application was created. (Also known as the consumer secret). This secret registers the custom application with the OAuth authorization server.—

Networking

The table below lists the domains that the source must be able to access to run.

For each domain, add a corresponding egress policy. If the source is hosted on-premises and not directly reachable from Foundry, use an agent proxy egress policy instead. The agent host itself must also be able to reach the listed domains. See using an agent as a proxy for details.

DomainRequired
graph.microsoft.comIf AzureEnvironment=GLOBAL (default)
login.microsoftonline.comIf AuthScheme=AzureAD (default), AzureServicePrincipal, AzureServicePrincipalCert AND AzureEnvironment=GLOBAL
microsoftgraph.chinacloudapi.cnIf AzureEnvironment=CHINA
login.chinacloudapi.cnIf AuthScheme=AzureAD (default), AzureServicePrincipal, AzureServicePrincipalCert AND AzureEnvironment=CHINA
graph.microsoft.usIf AzureEnvironment=USGOVT
login.microsoftonline.usIf AuthScheme=AzureAD (default), AzureServicePrincipal, AzureServicePrincipalCert AND AzureEnvironment=USGOVT or USGOVTDOD
dod-graph.microsoft.usIf AzureEnvironment=USGOVTDOD

OAuth 2.0 authentication

This connector supports OAuth 2.0 authentication. Follow the OAuth 2.0 guidance for Palantir-provided drivers to configure and authorize the connection.

Writing data

To upload or replace a file in OneDrive, import the source into an external transform or external function. Then call Microsoft Graph as shown in Use Microsoft OneDrive sources in code.

Before writing, complete the export configuration for external transforms or the external API access setup for functions. Functions also require Enable exports to this source without markings validations. Grant the application the Microsoft Graph permission required for writing.

Use Microsoft OneDrive sources in code

The examples below require a OneDrive source that stores an OAuth client secret in OAuthClientSecret. They reuse that secret and the source's governed egress to request a short-lived application token through the OAuth 2.0 client-credentials flow. This code path is separate from the AuthScheme used for connector batch syncs.

Grant the application the Microsoft Graph application permission required for your workflow:

  • Download files: Files.Read.All.
  • Upload or replace files: Files.ReadWrite.All.

An administrator must grant consent for the selected permission.

These code examples hard code the global Microsoft identity and Graph endpoints, so use them only with sources configured as AzureEnvironment=GLOBAL. They do not parameterize the endpoints required for sovereign-cloud environments.

Import the source into the code repository. Replace each placeholder with the source, tenant, application, drive, item, destination, output file, output dataset, and expected download host values used by your project. You can obtain drive and item IDs from the connector's Files view or Microsoft Graph.

Configure the source's egress policies to allow the tenant-specific host returned by the Microsoft Graph download redirect ↗, alongside the Graph and sign in hosts. In each read example, set <expected_download_host> to that permitted hostname. In the TypeScript v1 examples, replace OneDriveSource with the identifier generated from the source's API name.

The Python examples use the requests ↗ package. Add this package to the repository's dependencies for your selected Python example.

Read data

The pipeline adds the downloaded bytes to an unstructured dataset. The Python function returns the bytes directly. The TypeScript Functions return the same bytes as Base64.

Before running a function example, complete the external API access configuration, including enabling exports for the source. This Foundry requirement also applies to functions that only download files from OneDrive.

Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 from urllib.parse import quote, urlparse import requests from transforms.api import LightweightOutput, Output, transform from transforms.external.systems import ResolvedSource, Source, external_systems SOURCE_RID = "<source_rid>" TENANT_ID = "<tenant_id>" CLIENT_ID = "<client_id>" DRIVE_ID = "<drive_id>" ITEM_ID = "<item_id>" EXPECTED_DOWNLOAD_HOST = "<expected_download_host>" OUTPUT_FILE_NAME = "<output_file_name>" @external_systems(onedrive=Source(SOURCE_RID)) @transform.using(output=Output("<output_dataset_rid>")) def download_onedrive_file( onedrive: ResolvedSource, output: LightweightOutput, ) -> None: session = requests.Session() proxy = onedrive.get_https_proxy_uri() if proxy: session.proxies.update({"http": proxy, "https": proxy}) token_response = session.post( f"https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/token", data={ "client_id": CLIENT_ID, "client_secret": onedrive.get_secret("OAuthClientSecret"), "scope": "https://graph.microsoft.com/.default", "grant_type": "client_credentials", }, allow_redirects=False, ) token_response.raise_for_status() access_token = token_response.json()["access_token"] item_url = ( f"https://graph.microsoft.com/v1.0/drives/{quote(DRIVE_ID, safe='')}" f"/items/{quote(ITEM_ID, safe='')}/content" ) graph_response = session.get( item_url, headers={"Authorization": f"Bearer {access_token}"}, allow_redirects=False, ) if graph_response.is_redirect: location = graph_response.headers["Location"] download_url = urlparse(location) if ( download_url.scheme != "https" or (download_url.hostname or "").lower() != EXPECTED_DOWNLOAD_HOST.lower() ): raise RuntimeError("Microsoft Graph returned an unexpected download host.") file_response = session.get(location, allow_redirects=False) else: file_response = graph_response file_response.raise_for_status() with output.filesystem().open(OUTPUT_FILE_NAME, "wb") as output_file: output_file.write(file_response.content)
Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 from urllib.parse import quote, urlparse import requests from functions.api import function from functions.sources import get_source SOURCE_RID = "<source_rid>" TENANT_ID = "<tenant_id>" CLIENT_ID = "<client_id>" DRIVE_ID = "<drive_id>" EXPECTED_DOWNLOAD_HOST = "<expected_download_host>" @function(sources=[SOURCE_RID]) def download_onedrive_file(item_id: str) -> bytes: source = get_source(rid=SOURCE_RID) session = requests.Session() proxy = source.get_https_proxy_uri() if proxy: session.proxies.update({"http": proxy, "https": proxy}) token_response = session.post( f"https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/token", data={ "client_id": CLIENT_ID, "client_secret": source.get_secret("OAuthClientSecret"), "scope": "https://graph.microsoft.com/.default", "grant_type": "client_credentials", }, allow_redirects=False, ) token_response.raise_for_status() access_token = token_response.json()["access_token"] graph_response = session.get( f"https://graph.microsoft.com/v1.0/drives/{quote(DRIVE_ID, safe='')}" f"/items/{quote(item_id, safe='')}/content", headers={"Authorization": f"Bearer {access_token}"}, allow_redirects=False, ) if graph_response.is_redirect: location = graph_response.headers["Location"] download_url = urlparse(location) if ( download_url.scheme != "https" or (download_url.hostname or "").lower() != EXPECTED_DOWNLOAD_HOST.lower() ): raise RuntimeError("Microsoft Graph returned an unexpected download host.") file_response = session.get(location, allow_redirects=False) else: file_response = graph_response file_response.raise_for_status() return file_response.content
Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 import { ExternalSystems, Function, UserFacingError } from "@foundry/functions-api"; import { OneDriveSource } from "@foundry/external-systems/sources"; import { Buffer } from "buffer"; const TENANT_ID = "<tenant_id>"; const CLIENT_ID = "<client_id>"; const DRIVE_ID = "<drive_id>"; const EXPECTED_DOWNLOAD_HOST = "<expected_download_host>"; interface TokenResponse { access_token: string; } export class OneDriveReadFunctions { @ExternalSystems({ sources: [OneDriveSource] }) @Function() public async downloadOneDriveFile(itemId: string): Promise<string> { const tokenResponse = await OneDriveSource.fetch( `https://login.microsoftonline.com/${TENANT_ID}/oauth2/v2.0/token`, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: new URLSearchParams({ client_id: CLIENT_ID, client_secret: OneDriveSource.getSecret("OAuthClientSecret"), scope: "https://graph.microsoft.com/.default", grant_type: "client_credentials", }).toString(), redirect: "manual", }, ); if (!tokenResponse.ok) { throw new UserFacingError(`Token request returned HTTP ${tokenResponse.status}.`); } const token = await tokenResponse.json() as TokenResponse; const graphResponse = await OneDriveSource.fetch( `https://graph.microsoft.com/v1.0/drives/${encodeURIComponent(DRIVE_ID)}` + `/items/${encodeURIComponent(itemId)}/content`, { method: "GET", headers: { Authorization: `Bearer ${token.access_token}` }, redirect: "manual", }, ); let fileResponse = graphResponse; if ([301, 302, 303, 307, 308].includes(graphResponse.status)) { const location = graphResponse.headers.get("location"); if (!location) { throw new UserFacingError("Microsoft Graph returned no download location."); } const downloadUrl = new URL(location); if (downloadUrl.protocol !== "https:" || downloadUrl.hostname.toLowerCase() !== EXPECTED_DOWNLOAD_HOST.toLowerCase()) { throw new UserFacingError("Microsoft Graph returned an unexpected download host."); } fileResponse = await OneDriveSource.fetch(location, { method: "GET", redirect: "manual", }); } if (!fileResponse.ok) { throw new UserFacingError(`Download returned HTTP ${fileResponse.status}.`); } return Buffer.from(await fileResponse.arrayBuffer()).toString("base64"); } }
Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 import { Buffer } from "node:buffer"; import { UserFacingError } from "@osdk/functions"; import { getFetch, getSource } from "@palantir/functions-sources"; const SOURCE_RID = "<source_rid>"; const TENANT_ID = "<tenant_id>"; const CLIENT_ID = "<client_id>"; const DRIVE_ID = "<drive_id>"; const EXPECTED_DOWNLOAD_HOST = "<expected_download_host>"; interface TokenResponse { access_token: string; } export const config = { apiName: "downloadOneDriveFileTsV2", sources: [SOURCE_RID], }; export default async function downloadOneDriveFile(itemId: string): Promise<string> { const source = await getSource(SOURCE_RID); const sourceFetch = await getFetch(source); const clientSecret = source.secrets["OAuthClientSecret"]; if (!clientSecret) { throw new UserFacingError("The OneDrive source has no OAuth client secret."); } const tokenResponse = await sourceFetch( `https://login.microsoftonline.com/${TENANT_ID}/oauth2/v2.0/token`, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: new URLSearchParams({ client_id: CLIENT_ID, client_secret: clientSecret, scope: "https://graph.microsoft.com/.default", grant_type: "client_credentials", }).toString(), redirect: "manual", }, ); if (!tokenResponse.ok) { throw new UserFacingError(`Token request returned HTTP ${tokenResponse.status}.`); } const token = await tokenResponse.json() as TokenResponse; const graphResponse = await sourceFetch( `https://graph.microsoft.com/v1.0/drives/${encodeURIComponent(DRIVE_ID)}` + `/items/${encodeURIComponent(itemId)}/content`, { method: "GET", headers: { Authorization: `Bearer ${token.access_token}` }, redirect: "manual", }, ); let fileResponse = graphResponse; if ([301, 302, 303, 307, 308].includes(graphResponse.status)) { const location = graphResponse.headers.get("location"); if (!location) { throw new UserFacingError("Microsoft Graph returned no download location."); } const downloadUrl = new URL(location); if (downloadUrl.protocol !== "https:" || downloadUrl.hostname.toLowerCase() !== EXPECTED_DOWNLOAD_HOST.toLowerCase()) { throw new UserFacingError("Microsoft Graph returned an unexpected download host."); } fileResponse = await sourceFetch(location, { method: "GET", redirect: "manual" }); } if (!fileResponse.ok) { throw new UserFacingError(`Download returned HTTP ${fileResponse.status}.`); } return Buffer.from(await fileResponse.arrayBuffer()).toString("base64"); }

Write data

Each example performs a Microsoft Graph simple upload with PUT and returns the uploaded item's ID.

These examples overwrite the contents of any existing file at the destination path. Choose the destination carefully, and use an unused path to create a new file. Before retrying after an unclear result, check whether the upload succeeded.

Application authentication cannot replace a sensitivity-labeled file; use a delegated user workflow for that case.

Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 import json from urllib.parse import quote import requests from transforms.api import LightweightOutput, Output, transform from transforms.external.systems import ResolvedSource, Source, external_systems SOURCE_RID = "<source_rid>" TENANT_ID = "<tenant_id>" CLIENT_ID = "<client_id>" DRIVE_ID = "<drive_id>" DESTINATION_PATH = "<new_destination_path>" UPLOAD_CONTENT = b"OneDrive upload from a Foundry Python transform.\n" @external_systems(onedrive=Source(SOURCE_RID)) @transform.using(output=Output("<output_dataset_rid>")) def upload_onedrive_file( onedrive: ResolvedSource, output: LightweightOutput, ) -> None: session = requests.Session() proxy = onedrive.get_https_proxy_uri() if proxy: session.proxies.update({"http": proxy, "https": proxy}) token_response = session.post( f"https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/token", data={ "client_id": CLIENT_ID, "client_secret": onedrive.get_secret("OAuthClientSecret"), "scope": "https://graph.microsoft.com/.default", "grant_type": "client_credentials", }, allow_redirects=False, ) token_response.raise_for_status() access_token = token_response.json()["access_token"] encoded_path = "/".join(quote(segment, safe="") for segment in DESTINATION_PATH.split("/")) response = session.put( f"https://graph.microsoft.com/v1.0/drives/{quote(DRIVE_ID, safe='')}" f"/root:/{encoded_path}:/content", headers={ "Authorization": f"Bearer {access_token}", "Content-Type": "text/plain; charset=utf-8", }, data=UPLOAD_CONTENT, allow_redirects=False, ) response.raise_for_status() result = response.json() with output.filesystem().open("upload-result.json", "wb") as output_file: output_file.write( json.dumps({"itemId": result["id"], "fileName": result["name"]}).encode() )
Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 from urllib.parse import quote import requests from functions.api import function from functions.sources import get_source SOURCE_RID = "<source_rid>" TENANT_ID = "<tenant_id>" CLIENT_ID = "<client_id>" DRIVE_ID = "<drive_id>" UPLOAD_CONTENT = b"OneDrive upload from a Foundry Python Function.\n" @function(sources=[SOURCE_RID]) def upload_onedrive_file(destination_path: str) -> str: source = get_source(rid=SOURCE_RID) session = requests.Session() proxy = source.get_https_proxy_uri() if proxy: session.proxies.update({"http": proxy, "https": proxy}) token_response = session.post( f"https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/token", data={ "client_id": CLIENT_ID, "client_secret": source.get_secret("OAuthClientSecret"), "scope": "https://graph.microsoft.com/.default", "grant_type": "client_credentials", }, allow_redirects=False, ) token_response.raise_for_status() access_token = token_response.json()["access_token"] encoded_path = "/".join(quote(segment, safe="") for segment in destination_path.split("/")) response = session.put( f"https://graph.microsoft.com/v1.0/drives/{quote(DRIVE_ID, safe='')}" f"/root:/{encoded_path}:/content", headers={ "Authorization": f"Bearer {access_token}", "Content-Type": "text/plain; charset=utf-8", }, data=UPLOAD_CONTENT, allow_redirects=False, ) response.raise_for_status() return response.json()["id"]
Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 import { ExternalSystems, Function, UserFacingError } from "@foundry/functions-api"; import { OneDriveSource } from "@foundry/external-systems/sources"; import { Buffer } from "buffer"; const TENANT_ID = "<tenant_id>"; const CLIENT_ID = "<client_id>"; const DRIVE_ID = "<drive_id>"; const UPLOAD_CONTENT = Buffer.from( "OneDrive upload from a Foundry TypeScript v1 Function.\n", "utf8", ); interface TokenResponse { access_token: string; } interface UploadResult { id: string; } export class OneDriveWriteFunctions { @ExternalSystems({ sources: [OneDriveSource] }) @Function() public async uploadOneDriveFile(destinationPath: string): Promise<string> { const tokenResponse = await OneDriveSource.fetch( `https://login.microsoftonline.com/${TENANT_ID}/oauth2/v2.0/token`, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: new URLSearchParams({ client_id: CLIENT_ID, client_secret: OneDriveSource.getSecret("OAuthClientSecret"), scope: "https://graph.microsoft.com/.default", grant_type: "client_credentials", }).toString(), redirect: "manual", }, ); if (!tokenResponse.ok) { throw new UserFacingError(`Token request returned HTTP ${tokenResponse.status}.`); } const token = await tokenResponse.json() as TokenResponse; const encodedPath = destinationPath.split("/").map(encodeURIComponent).join("/"); const response = await OneDriveSource.fetch( `https://graph.microsoft.com/v1.0/drives/${encodeURIComponent(DRIVE_ID)}` + `/root:/${encodedPath}:/content`, { method: "PUT", headers: { Authorization: `Bearer ${token.access_token}`, "Content-Type": "text/plain; charset=utf-8", }, body: UPLOAD_CONTENT, redirect: "manual", }, ); if (!response.ok) { throw new UserFacingError(`Upload returned HTTP ${response.status}.`); } return (await response.json() as UploadResult).id; } }
Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 import { Buffer } from "node:buffer"; import { UserFacingError } from "@osdk/functions"; import { getFetch, getSource } from "@palantir/functions-sources"; const SOURCE_RID = "<source_rid>"; const TENANT_ID = "<tenant_id>"; const CLIENT_ID = "<client_id>"; const DRIVE_ID = "<drive_id>"; const UPLOAD_CONTENT = Buffer.from( "OneDrive upload from a Foundry TypeScript v2 Function.\n", "utf8", ); interface TokenResponse { access_token: string; } interface UploadResult { id: string; } export const config = { apiName: "uploadOneDriveFileTsV2", sources: [SOURCE_RID], }; export default async function uploadOneDriveFile(destinationPath: string): Promise<string> { const source = await getSource(SOURCE_RID); const sourceFetch = await getFetch(source); const clientSecret = source.secrets["OAuthClientSecret"]; if (!clientSecret) { throw new UserFacingError("The OneDrive source has no OAuth client secret."); } const tokenResponse = await sourceFetch( `https://login.microsoftonline.com/${TENANT_ID}/oauth2/v2.0/token`, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: new URLSearchParams({ client_id: CLIENT_ID, client_secret: clientSecret, scope: "https://graph.microsoft.com/.default", grant_type: "client_credentials", }).toString(), redirect: "manual", }, ); if (!tokenResponse.ok) { throw new UserFacingError(`Token request returned HTTP ${tokenResponse.status}.`); } const token = await tokenResponse.json() as TokenResponse; const encodedPath = destinationPath.split("/").map(encodeURIComponent).join("/"); const response = await sourceFetch( `https://graph.microsoft.com/v1.0/drives/${encodeURIComponent(DRIVE_ID)}` + `/root:/${encodedPath}:/content`, { method: "PUT", headers: { Authorization: `Bearer ${token.access_token}`, "Content-Type": "text/plain; charset=utf-8", }, body: UPLOAD_CONTENT, redirect: "manual", }, ); if (!response.ok) { throw new UserFacingError(`Upload returned HTTP ${response.status}.`); } return (await response.json() as UploadResult).id; }