onedrive-api
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.
Install
npm install onedrive-api
API
Items
- createFolder
- delete
- download
- getMetadata
- listChildren
- update
- sync
- customEndpoint
- uploadSimple
- uploadSession
Examples
Require module
var oneDriveAPI = ;
oneDriveAPIitems
items.createFolder
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 | |
params.shared | Boolean |
false |
A flag to indicated whether this files is owned by the user or shared from another user. If true params.user has to be set. |
params.user | String |
The user who shared the file. Must be set if params.shared is true. |
oneDriveAPIitems
items.delete
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 |
params.shared | Boolean |
false |
params.user | String |
oneDriveAPIitems
items.download
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 |
params.shared | Boolean |
false |
params.user | String |
var fileStream = oneDriveAPIitems;fileStream;
items.customEndpoint
Call custom endpoint
Returns: Object
- Readable stream with item's content
Param | Type | Description |
---|---|---|
params | Object |
|
params.accessToken | String |
OneDrive access token |
params.url | String |
Endpoint url. Ex. 'groups/{groupId}/drives' |
params.body | Object |
false |
params.method | String |
Optional method |
oneDriveAPIitems
items.sync
Sync changes
Returns: Array
- Changes since last sync
Param | Type | Description |
---|---|---|
params | Object |
|
params.accessToken | String |
OneDrive access token |
params.next | String |
nextLink (or deltaLink returned from last session). |
oneDriveAPIitems
items.getMetadata
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 |
params.shared | Boolean |
false |
params.user | String |
oneDriveAPIitems
items.listChildren
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 |
params.shared | Boolean |
false |
A flag to indicated whether this files is owned by the user or shared from another user. If true params.user has to be set. |
params.user | String |
The user who shared the file. Must be set if params.shared is true. |
oneDriveAPIitems
items.update
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 |
params.shared | Boolean |
false |
params.user | String |
oneDriveAPIitems
items.uploadSimple
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 | |
params.shared | Boolean |
false |
A flag to indicated whether this files is owned by the user or shared from another user. If true params.user has to be set. |
params.user | String |
The user who shared the file. Must be set if params.shared is true. |
oneDriveAPIitems
items.uploadSession
Create file with session upload. Use this for the files over 4MB. This is a synchronous wrapper around asynchronous method, which means that on the failed upload you can't resume the upload but need to retry the implementation. I am accepting PRs for asynchronous implementation
Returns: Object
- Item
Param | Type | Default | Description |
---|---|---|---|
params | Object |
||
params.accessToken | String |
OneDrive access token | |
params.filename | String |
File name | |
params.fileSize | Number |
Size of the file | |
[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 | |
params.shared | Boolean |
false |
A flag to indicated whether this files is owned by the user or shared from another user. If true params.user has to be set. |
params.user | String |
The user who shared the file. Must be set if params.shared is true. | |
[params.chunksToUpload] | Number |
20 |
Chunks to upload per request. More chunks per request requires more RAM |
[writeStream] | Boolean |
false |
Return writeStream instead of handling upload directly |
[cb] | Function (err, results) |
Callback for writestream |
// Handle by upload using this library (starts at once)oneDriveAPIitems // Handle upload using write streamlet writestream = await oneDriveAPIitems // Start the upload by piping a readstreamreadstream