Integrations / OneDrive
OneDrive
Browse, search, organise and share files in OneDrive through Microsoft Graph.
9 actions
OAuth 2
5 read3 write1 destructive
Calls graph.microsoft.com
Connect
const conn = await setu.connections.initiate({ userId: "user_1", toolkit: "onedrive" });
console.log(conn.connectUrl); // show this to your user
await conn.waitUntilActive();Permissions requested
| Scope | Why it is requested |
|---|---|
Files.Read | Read the files in your OneDrive |
Files.ReadWrite | Create folders, rename, delete and share files in your OneDrive |
User.Read | Identify which Microsoft account you connected |
offline_access | Stay connected without asking you to sign in again |
Actions
Create folderwriteonedrive.create_folderCreate a new folder inside a OneDrive folder. By default a name clash gets a numbered name.
Needs scope: Files.ReadWrite
| Input | Type | Description | |
|---|---|---|---|
parent_id | string | Required | Parent folder item ID, for example from get_drive_root |
name | string | Required | Name of the new folder |
conflict_behavior | string | Optional | What to do if the name exists (default rename) |
await setu.execute({
userId: "user_1",
action: "onedrive.create_folder",
input: {
"parent_id": "<parent_id>",
"name": "<name>"
},
});Create sharing linkwriteonedrive.create_sharing_linkCreate a link that shares a file or folder, view-only or editable, for anyone, the organization or specific people. Anyone with an anonymous link can open the item.
Needs scope: Files.ReadWrite
| Input | Type | Description | |
|---|---|---|---|
item_id | string | Required | Item ID from a listing or search |
type | string | Required | Kind of link |
scope | string | Optional | Who can use the link (default is the organization's setting) |
await setu.execute({
userId: "user_1",
action: "onedrive.create_sharing_link",
input: {
"item_id": "<item_id>",
"type": "<type>"
},
});Delete file or folderdestructiveonedrive.delete_itemDelete a OneDrive file or folder (it goes to the recycle bin). A folder is deleted with everything inside it.
Needs scope: Files.ReadWrite
| Input | Type | Description | |
|---|---|---|---|
item_id | string | Required | Item ID from a listing or search |
await setu.execute({
userId: "user_1",
action: "onedrive.delete_item",
input: {
"item_id": "<item_id>"
},
confirm: true,
});Get OneDrive root folderreadonedrive.get_drive_rootGet the root folder of the user's OneDrive, including its ID, which other actions need as a parent folder.
Needs scope: Files.Read
No input.
await setu.execute({
userId: "user_1",
action: "onedrive.get_drive_root",
input: {},
});Get file or folderreadonedrive.get_itemGet the details of one OneDrive file or folder: name, size, type, last modified time and its web link.
Needs scope: Files.Read
| Input | Type | Description | |
|---|---|---|---|
item_id | string | Required | Item ID from a listing or search |
await setu.execute({
userId: "user_1",
action: "onedrive.get_item",
input: {
"item_id": "<item_id>"
},
});List files in a folderreadonedrive.list_folder_childrenList the files and folders inside one OneDrive folder, given the folder's item ID.
Needs scope: Files.Read
| Input | Type | Description | |
|---|---|---|---|
item_id | string | Required | Folder item ID from a listing, search or get_drive_root |
top | integer | Optional | Maximum number of items to return |
await setu.execute({
userId: "user_1",
action: "onedrive.list_folder_children",
input: {
"item_id": "<item_id>"
},
});List files in OneDrive rootreadonedrive.list_root_filesList the files and folders at the top level of the user's OneDrive.
Needs scope: Files.Read
| Input | Type | Description | |
|---|---|---|---|
top | integer | Optional | Maximum number of items to return |
await setu.execute({
userId: "user_1",
action: "onedrive.list_root_files",
input: {},
});Rename file or folderwriteonedrive.rename_itemRename a OneDrive file or folder without changing its content or location.
Needs scope: Files.ReadWrite
| Input | Type | Description | |
|---|---|---|---|
item_id | string | Required | Item ID from a listing or search |
name | string | Required | The new name, including the file extension |
await setu.execute({
userId: "user_1",
action: "onedrive.rename_item",
input: {
"item_id": "<item_id>",
"name": "<name>"
},
});Search filesreadonedrive.search_filesSearch the user's OneDrive by file name, metadata and content. Avoid apostrophes in the search text.
Needs scope: Files.Read
| Input | Type | Description | |
|---|---|---|---|
q | string | Required | Search text, for example: Contoso Project (no apostrophes) |
top | integer | Optional | Maximum number of items to return |
await setu.execute({
userId: "user_1",
action: "onedrive.search_files",
input: {
"q": "<q>"
},
});