Module microsoft.onedrive

ballerinax/microsoft.onedrive Ballerina library

2.1.0

Overview

Ballerina connector for Microsoft OneDrive connects to the OneDrive file storage API in Microsoft Graph v1.0 via the Ballerina language. The connector allows you to programmatically perform basic drive functionalities such as file upload, download. It also allows you to share files and folders stored on Microsoft OneDrive.

This module supports Microsoft Graph API v1.0 and allows performing functions only on behalf of the currently signed-in user.

Prerequisites

Before using this connector in your Ballerina application, complete the following:

Quickstart

To use the OneDrive connector in your Ballerina application, update the .bal file as follows:

Step 1 - Import connector

Import the ballerinax/microsoft.onedrive module into the Ballerina project.

Copy
import ballerinax/microsoft.onedrive;

Step 2 - Create a new connector instance

To make the connection, use the OAuth2 refresh token grant configuration.

Copy
onedrive:ConnectionConfig configuration = {
    auth: {
        refreshUrl: <REFRESH_URL>,
        refreshToken : <REFRESH_TOKEN>,
        clientId : <CLIENT_ID>,
        clientSecret : <CLIENT_SECRET>,
        scopes: [<NECESSARY_SCOPES>]
    }
};

Step 3 - Invoke connector operation

  1. Create a folder
    To create a folder, use the following code block:
Copy
string parentID = "<PARENT_FOLDER_ID>";
string newFolderName = "Samples_Test";
onedrive:FolderMetadata item = {
    name: newFolderName,
    conflictResolutionBehaviour : "rename"
};

onedrive:DriveItemData|onedrive:Error driveItem = driveClient->createFolderById(parentID, item);

if (driveItem is onedrive:DriveItemData) {
    log:printInfo("Folder Created " + driveItem.toString());
    log:printInfo("Success!");
} else {
    log:printError(driveItem.message());
}
  1. Use bal run command to compile and run the Ballerina program.

You can find a list of samples here

Import

import ballerinax/microsoft.onedrive;Copy

Metadata

Released date: almost 3 years ago

Version: 2.1.0

License: Apache-2.0


Compatibility

Platform: any

Ballerina version: slbeta6

GraalVM compatible: Yes


Pull count

Total: 2254

Current verison: 48


Weekly downloads


Source repository


Keywords

Content & Files/File Management & Storage

Cost/Freemium

Vendor/Microsoft


Contributors

Other versions

See more...