0

List Drives

by
Published today

List the drives available to the connected account: its OneDrive and, on work or school accounts, the document libraries it can reach. Use a drive's `id` as `drive_id` in the other scripts. Requires Files.Read (covered by the default Files.ReadWrite).

Script ms_onedrive Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 4 hours ago
1
//native
2

3
const graph = "https://graph.microsoft.com/v1.0"
4

5
/**
6
 * List Drives
7
 * List the drives available to the connected account: its OneDrive and, on work or school accounts, the document libraries it can reach. Use a drive's `id` as `drive_id` in the other scripts. Requires Files.Read (covered by the default Files.ReadWrite).
8
 */
9
export async function main(auth: RT.MsOnedrive) {
10
  const response = await fetch(`${graph}/me/drives`, {
11
    headers: {
12
      Authorization: `Bearer ${auth.token}`,
13
      Accept: "application/json",
14
    },
15
  })
16

17
  if (!response.ok) {
18
    throw new Error(`${response.status} ${await response.text()}`)
19
  }
20

21
  return await response.json()
22
}
23