How to use SharePoint files and folders in MuleSoft

Zoran Đukić
Another Integration Blog
6 min readJan 18, 2023

Welcome to our tutorial on using MuleSoft to manipulate SharePoint files and folders. In this article, we will specifically focus on working with files, with the understanding that the same principles can also be applied to manipulating folders. If you haven’t yet, be sure to check out our previous article on using SharePoint lists as well. Let’s dive in!

SharePoint and MuleSoft integration

Table of content:

  1. Configure SharePoint minor versions
  2. Add files
  3. Get file’s content
  4. Delete files
  5. Publish/Unpublish files
  6. Move files
  7. Check in/Check out files
  8. File query

Before we start, we need to configure SharePoint with MuleSoft. If you don’t know how to do that here, you can see how to configure SharePoint in MuleSoft.

Also, we need to enable minor versions before we start working on the SharePoint files. If we don’t do that, we won’t be able to use some of the features because they only use minor versions, for example 2.1, 2.2, etc.

Configure SharePoint minor versions:

First, find “All Documents” in your top right corner. Click “Edit current view”.

Edit current view in SharePoint

Find Version on the list and enable it.

List of enabled items

Click save. After that, we need to enable minor versions. Click on the “Settings” icon in the top right corner. Click on “Library settings”.

Library settings

Click “More library settings”.

More library settings

Click “Versioning settings”.

Versioning settings

Click “Create major and minor (draft) versions”

Version control

This is it. Let’s start by creating a file on SharePoint.

Add files:

Add file to SharePoint

The flow is pretty straightforward. You create a listener, and after that, you create a Transform Message based on the type file you are going to create. In this example, we are going to create a .xlsx file.

Add file to SharePoint

Keep an eye on the URL we gave to the file. We did this so it’s easier to find it later on. You can create new folders, new files, etc. but for simplicity’s sake, we won’t do that in this tutorial.
Ok, so now we created a file called MulesoftAccounts.xslx. You can go to your SharePoint account and see it in the “Shared Documents” folder. Add some data to that file.
Note: Keep in mind you can only use files supported by MS. For example, you can create a .csv file but you won’t be able to open it.

Source: Add file

Get file’s content:

Get file content from SharePoint
Get file content from SharePoint

Using the same URL get the content. After that, you can transform data from your file.

Source: File get content

Delete files:

Delete file from SharePoint
Delete file from SharePoint

You can also delete the file by using the same URL.

Source: Delete files

Publish/Unpublish files:

When a file is published, it is made available to all users who have access to the SharePoint site or library where the file is located. When a file is unpublished, it is removed from view and is no longer accessible to users, but it still exists in the SharePoint site or library. This feature allows users to control the visibility and accessibility of files on the SharePoint site.

Publish file to SharePoint
Publish file to SharePoint

The same logic applies to unpublishing a file.

Source: Publish file

Move file:

The “Move File” option in the MuleSoft and SharePoint connector allows you to move a file from one location to another within the SharePoint site or library. This feature allows you to reorganize and reorganize the files in your SharePoint site or library, making them easier to find and access.

The Move File option can be used to move a file from one folder to another or to move a file from one library to another library. This feature can also be used to change the name of a file. The file is physically moved to the new location and the old file is deleted. This feature can be useful for managing and organizing your files, as well as for maintaining version control.

Move file to SharePoint
Move file to SharePoint

“File server relative URL” is the old location of the file.

“New file server relative URL” is the new location of the file.

“Flag” is what will MuleSoft do if the file exists. These are the options:

  • 8 — Completes the move operation even if supporting files are separated from the file
  • 0 — No move operation specified
  • 1 — Overwrites a file with the same name if it exists.

Source: Move file

Check in/Check out files:

The “File Check In” and “File Check Out” options in the MuleSoft and SharePoint connector refer to the ability to lock a file for editing by a specific user. When a user checks out a file, they have exclusive editing rights to that file and other users are unable to make changes to it. When the user is finished making their changes, they can check the file back in, which makes it available for editing by other users. This feature allows for version control and prevents multiple users from accidentally overwriting each other’s changes.

Check out files
Check out files

Now you are the only one who can access the file.

Check In works the same way.

Check In version

However, you can pick what users can do with it. The three options available are:

  • MINOR_CHECK_IN: This option indicates that the changes made to the file are minor and do not affect the overall functionality of the file. This type of check in increments the minor version number of the file.
  • MAJOR_CHECK_IN: This option indicates that the changes made to the file are significant and do affect the overall functionality of the file. This type of check in increments the major version number of the file.
  • OVERWRITE_CHECK_IN: This option is used to overwrite the file with the changes made to it. This option does not increment the version number of the file and will overwrite the previous version of the file.

Source: Check in files

Source 2: Check out files

File query:

To write a query you need to use OData. You can find more OData here: https://www.odata.org/getting-started/basic-tutorial/

In this example, we are going to search Shared Documents and retrieve all the files that are inside that folder.

File query
File query

Source: File query

In conclusion, MuleSoft’s connectors for SharePoint offer a powerful and flexible solution for integrating SharePoint with other systems and applications. Hope you enjoyed this blog post. If you have any questions or an idea about how to improve the article feel free to contact me.

--

--