- February 3, 2025
- Posted by: Ram Senthil Kumar
- Category: Mendix
Organizations today are placing greater emphasis on delivering exceptional customer experiences, recognizing that this is central for achieving their objectives. To support their goal, many are turning to innovative technologies and seamless platform integrations. Among the most impactful advancements is the synergy between low-code development platforms, and robust cloud storage solutions. This combination is rapidly becoming a cornerstone of digital transformation strategies, empowering businesses to enhance agility, streamline processes, and deliver superior service to their customers.
Mendix is a low-code application development platform that enables businesses to rapidly build, deploy, and manage applications. This makes it an ideal solution for businesses looking to accelerate their digital transformation efforts. By reducing the time and resources required to build and launch applications, organizations can quickly implement new processes and technologies and start seeing results faster.
Microsoft OneDrive, on the other hand, is a cloud-based storage solution that allows users to store, share, and access files from anywhere on any device. This makes it an ideal complement to Mendix, as it enables users to easily access and use the data and files they need when they need them.
When these two platforms are integrated, the possibilities are endless. For example, organizations can use Mendix to build custom applications that leverage the power of OneDrive for data storage and access. This could include applications for file management, project management, or customer relationship management, to name a few.
Here’s our step-by-step guide that outlines OneDrive integration using a specific user’s ID.
Azure Portal Configuration
Introduction
Mendix and Azure can only be connected using
1. Tenant ID
2. Application ID
3. Client Secret Value
To get this, you need to create an Enterprise application and register the app. The steps to follow are below.
1. Access Enterprise Applications
- Log in to the Azure Portal.
- Navigate to All Services ➞ Identity ➞ Enterprise Applications or search for Enterprise Applications.
2. Create an Enterprise Application
- Select Create Your Own Application.
3. Set Up Single Sign-On
- Click on Set Up Single Sign-On.
- Choose SAML as the single sign-on method.
4. Edit Basic SAML Configuration
- Enter the Mendix application URL as the Identifier (Entity ID).
- Provide the Reply URL for authentication: [ApplicationURL]/microsoftgraph/oauth/v2/callback_azure
5. App Registration
- Go to App Registration and locate your registered app.
- Note the following values for Mendix configuration:
- Tenant ID
- Application ID
- Client Secret Value
6. Generate Client Secret
- Go to Certificates & Secrets ➞ New Client Secret.
- Add a description and set an expiration date.
- Important: Save the secret value immediately, as it will be encrypted after creation.
7. Configure API Permissions
Go to Manage ➞ API Permissions and add the following:
- Delegated Permissions:
- File.Read
- File.Read.All
- File.ReadWrite
- File.ReadWrite.All
- Application Permissions:
- File.Read.All
- File.ReadWrite.All
Mendix Application Configuration
1. Download the Microsoft Graph Module
- Add the Microsoft Graph module to your Mendix project.
- Include it in the navigation menu.
1. Graph Authentication Configuration
- In the Graph Authentication overview, add a new configuration:
- Display Name
- Application ID
- Supported Account Type: Sign-in users of a specific organization only.(Depending on your requirement)
- Tenant ID
- Client Secret Value
- Click Import Well-Known Configuration.
- Make the configuration active.
3. Authenticate Users
- Use the Authenticate as a Service option or Authenticate as a user (Based on your use case).
1. Authenticate as a Service: This allows the Mendix application to access OneDrive resources using an application-level token. It is useful for backend processes or when no user interaction is required. Permissions are granted at the application level.
2. Authenticate as a User: This provides user-specific access to OneDrive resources. A user must sign in, and their permissions determine what actions can be performed. It is useful when user-level access is required, such as uploading or managing their files.
4. Implement Entities, Microflows, and Pages
- Add the necessary entities, microflows, nanoflows, and pages for OneDrive file creation, deletion, and upload functionalities.
Note:
- After successful authorization, the access token and token type will be stored in the authorization in the graph module.
- For every request, add Content-Type and Authorization in the headers.
OneDrive Functionalities
1. Get a User’s OneDrive Details
It is used to get the drive owner details, drive size, and file count
- Request Method: GET
- Endpoint:
@MicrosoftGraph.GraphLocation + ‘/users/’ + UserPrincipalName + ‘/drive’
- Headers:
- Authorization: Token_Type space Token (decrypted from the Graph module to get token)
- Content-Type: application/json
2. Create a Folder in OneDrive
Creating a folder in a particular user’s OneDrive.
- Request Method: POST
- Endpoint:
@MicrosoftGraph.GraphLocation + ‘/users/’ + {UserID or MailID} + ‘/drive/items/root/children’
- Request Body:
{
“name”: “‘ + $Folder/Name + ‘”,
“folder”: {},
“@microsoft.graph.conflictBehavior”: “rename”
}
- Headers:
- Authorization
- Content-Type: application/json
- Response: Upon success (HTTP 200), retrieve the Folder ID for later use.
Note:
Folder name will be renamed if already a folder with same name exists.
3. Upload Files to a User’s OneDrive
Creating a folder in a particular users OneDrive.
- Request Method: PUT
- Endpoint:
@MicrosoftGraph.GraphLocation + ‘/users/’ + $UserPrincipalName + ‘/drive/items/’ + $FolderID + ‘:/’+ $FileName + ‘:/content’
- Headers:
- Authorization
- Content-Type: Based on the file type (e.g., PDF: application/pdf, ZIP: application/zip)
- Request: Send the file as binary content.
- Response: Upon success (HTTP 200), retrieve the File ID for later use.
Note:
If the uploading file name already exists in the drive, it will replace the existing file.
4. Download a File from OneDrive
Downloading a folder from a particular user’s OneDrive.
- Request Method: GET
- Endpoint:
@MicrosoftGraph.GraphLocation + ‘/users/’ + {UserID or MailID} + ‘/drive/items/’ + FileNumber + ‘/content’
- Headers:
- Authorization
- Content-Type
- Response: Store the file content as a FileDocument entity.
5. Delete a File in OneDrive
- Request Method: DELETE
- Endpoint:
@MicrosoftGraph.GraphLocation + ‘/users/’ + {UserID or MailID} + ‘/drive/items/’ + FileNumber
- Headers:
- Authorization
- Content-Type
6. Delete a Folder in OneDrive
- Request Method: DELETE
- Endpoint:
@MicrosoftGraph.GraphLocation + ‘/users/’ + $UserPrincipalName + ‘/drive/items/’ + $FolderID
- Headers:
- Authorization
- Content-Type
7. Retrieve Drive Details
Use to get drive details, owner details, and size
- Request Method: GET
- Endpoint:
@MicrosoftGraph.GraphLocation + ‘/users/’ + {UserID or MailID} + ‘/drive’
- Headers:
- Authorization
- Content-Type
- Response:
{
“id”: “b!t18F8ybsHUq1z3LTz8xvZqP8zaSWjkFNhsME-Fepo75dTf9vQKfeRblBZjoSQrd7”,
“driveType”: “business”,
“owner”: {
“user”: {
“id”: “efee1b77-fb3b-4f65-99d6-274c11914d12”,
“displayName”: “Ryan Gregg”
}
},
“quota”: {
“deleted”: 256938,
“fileCount”: 2,
“remaining”: 1099447353539,
“state”: “normal”,
“total”: 1099511627776
}
}
Notes:
- Convert space values (KB) to GB: Divide by (1024 * 1024 * 1024).
8. Retrieve Folder Details
Use it to get folder details, such as name and size.
- Request Method: GET
- Endpoint:
@MicrosoftGraph.GraphLocation+’/users/’+{User-id or Mail id}+’/drive/items/’+{Folder-id or folder name}
- Headers:
- Authorization
- Content-Type
- Response:
This response will return Folder id, name and folder size.
Conclusion
Integrating OneDrive with Mendix unlocks powerful capabilities for file management, synchronization, and collaboration within low-code applications. By leveraging the Microsoft Graph API, developers can efficiently manage OneDrive files and folders, enhancing productivity and user experience. With the help of Indium, this integration can be implemented quickly and easily, delivering maximum value in the shortest possible time.