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.


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


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.

import ballerinax/microsoft.onedrive;

Step 2 - Create a new connector instance

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

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:
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());
} else {
  1. Use bal run command to compile and run the Ballerina program.

You can find a list of samples here

Other versions

See more...