OneDrive API module for Node.js. It's built with pure functional programing, there are no unnecessary objects.
It's built for internal project so it supports only basic CRUD operations needed for project (for now). I will accept any pull requests.
npm install onedrive-apivar oneDriveAPI = require('onedrive-api');Create Folder
Returns: Object - folder object
| Param | Type | Default | Description |
|---|---|---|---|
| params | Object |
||
| params.accessToken | String |
OneDrive access token | |
| [params.rootItemId] | String |
root |
Item id |
| params.name | String |
New folder name |
oneDriveAPI.items.createFolder({
accessToken: accessToken,
rootItemId: "root",
name: "Folder name"
}).then((item) => {
// console.log(item)
// returns body of https://dev.onedrive.com/items/create.htm#response
})Delete item (file or folder)
Returns: undefined - (204 No content)
| Param | Type | Description |
|---|---|---|
| params | Object |
|
| params.accessToken | String |
OneDrive access token |
| params.itemId | String |
Item id |
oneDriveAPI.items.delete({
accessToken: accessToken,
itemId: createdFolder.id
}).then(() => {
})Download item content
Returns: Object - Readable stream with item's content
| Param | Type | Description |
|---|---|---|
| params | Object |
|
| params.accessToken | String |
OneDrive access token |
| params.itemId | String |
item id |
var fileStream = oneDriveAPI.items.download({
accessToken: accessToken,
itemId: createdFolder.id
});
fileStream.pipe(SomeWritableStream);Get items metadata (file or folder)
Returns: Object - Item's metadata
| Param | Type | Description |
|---|---|---|
| params | Object |
|
| params.accessToken | String |
OneDrive access token |
| params.itemId | String |
Item id |
oneDriveAPI.items.getMetadata({
accessToken: accessToken,
itemId: createdFolder.id
}).then((item) => {
// console.log(item);
// returns body of https://dev.onedrive.com/items/update.htm#response
})List childrens
Returns: Array - object of children items
| Param | Type | Default | Description |
|---|---|---|---|
| params | Object |
||
| params.accessToken | String |
OneDrive access token | |
| [params.itemId] | String |
root |
Item id |
oneDriveAPI.items.listChildren({
accessToken: accessToken,
itemId: createdFolder.id
}).then((childrens) => {
// console.log(childrens);
// returns body of https://dev.onedrive.com/items/list.htm#response
})Update item metadata
Returns: Object - Item object
| Param | Type | Description |
|---|---|---|
| params | Object |
|
| params.accessToken | String |
OneDrive access token |
| params.itemId | String |
Item id |
| params.toUpdate | Object |
Object to update |
oneDriveAPI.items.update({
accessToken: accessToken,
itemId: createdFolder.id,
toUpdate: {
name: "newFolderName"
}
}).then((item) => {
// console.log(item);
// returns body of https://dev.onedrive.com/items/update.htm#response
})Create file with simple upload
Returns: Object - Item
| Param | Type | Default | Description |
|---|---|---|---|
| params | Object |
||
| params.accessToken | String |
OneDrive access token | |
| params.filename | String |
File name | |
| [params.parentId] | String |
root |
Parent id |
| [params.parentPath] | String |
Parent path (if parentPath is defined, than parentId is ignored) | |
| params.readableStream | Object |
Readable Stream with file's content |
oneDriveAPI.items.uploadSimple({
accessToken: accessToken,
filename: filename,
readableStream: readableStream
}).then((item) => {
// console.log(item);
// returns body of https://dev.onedrive.com/items/upload_put.htm#response
})