SharePoint Integration With MuleSoft

What Is SharePoint?

Microsoft SharePoint is used to create websites and it's a secure place to store, organize, share, and access information from any device.

Anypoint SharePoint Connector

SharePoint connector supports both SharePoint 2013 and SharePoint Online for use in the cloud and on-premises. This connector enables you to manage content and document management within your organization. This connector supports a number of operations and you can find more details on this page

I will first cover the Folder Create and File Edd operations. Following this, I will cover the Folder Query, Folder Delete, List Create, List Get, and List Get All operations. 

Prerequisite

Before getting started, the prerequisite is to have SharePoint online account. You can create a trial account by following the steps mentioned in the link. Also, make sure to add a SharePoint connector in Anypoint Studio from Anypoint Exchange. In this walkthrough, I have used SharePoint connector version 3.3.2.

Let's Get Started With Integration

Let's create a global SharePoint online element. In SharePoint, I have created a POC site as a teams site and configured POC site URL in the site URL. You can follow this article to create a SharePoint site. Now, refer to the below snapshot for configuration. 

SharePoint online global configuration


Let's configure the  Folder Create  operation. This operation allows us to create a folder in the SharePoint document library. You have to provide the  Server relative URL  of the folder to create in the URL field. I saved the output of this operation into the target variable createFolderResponse.

Folder Create configuration


Now, read a file using the file connector read operation. Let's, configure SharePoint connector File Add operation to add a file to the newly created SharePoint folder. Provide the details for the below two fields in the File Add configuration

  1. File Server Relative URL = Where to add the new file. 
  2. File Content Stream = The content that this new file should contain. 

You can refer to the below snapshot for File Add configuration.

File Add configuration


The final Mule flow will look like below once completed. I have provided the code at the end.

Final Mule Flow

Let's Test a Mule Application 

Postman snapshot


For the above postman request, the Mule application has created a SharePoint folder with the name xyz-docs and added sharepoint-test1.text file in it.  

SharePoint snapshot


Mule Flow Code

XML
 
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:file="http://www.mulesoft.org/schema/mule/file"
      xmlns:http="http://www.mulesoft.org/schema/mule/http"
      xmlns:sharepoint="http://www.mulesoft.org/schema/mule/sharepoint"
      xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/sharepoint http://www.mulesoft.org/schema/mule/sharepoint/current/mule-sharepoint.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
	<sharepoint:sharepoint-online-config name="Sharepoint_Sharepoint_online"
	                                     doc:name="Sharepoint Sharepoint online"
	                                     doc:id="03c666f9-bc7e-4848-b969-aba494f4cae9">
		<sharepoint:online-connection onlineUsername="*************@*****************.onmicrosoft.com"
		                              onlinePassword="*****************************"
		                              siteUrl="https://******************.sharepoint.com/teams/POC"/>
	</sharepoint:sharepoint-online-config>
	<http:listener-config name="HTTP_Listener_config"
	                      doc:name="HTTP Listener config"
	                      doc:id="c468f318-0920-426b-82d6-e41186dd786e">
		<http:listener-connection host="0.0.0.0"
		                          port="8081"/>
	</http:listener-config>
	<file:config name="File_Config"
	             doc:name="File Config"
	             doc:id="b54c5ea3-d94b-43e2-b723-b383ef6a4f46">
		<file:connection workingDir="C:\luffy\Desktop\test\sharepoint-poc"/>
	</file:config>
	<flow name="sharepoint-poc-create-folder"
	      doc:id="eed8ec3d-48f5-4500-b6eb-404982540f2e">
		<http:listener doc:name="listener"
		               doc:id="ae2d4983-d00c-4e19-b80b-c1ce57bc9459"
		               config-ref="HTTP_Listener_config"
		               path="sharepoint/create-folder"/>
		<sharepoint:folder-create doc:name="create-folder"
		                          doc:id="7f26ceac-bb63-48c1-9e92-1b7f5d9aef5e"
		                          config-ref="Sharepoint_Sharepoint_online"
		                          url='#["Shared Documents/" ++ (attributes.queryParams.newFolderName default "")]'
		                          target="createFolderResponse"/>
		<file:read doc:name="read-file"
		           doc:id="102e73c6-0ca3-40a9-8b85-9f54ce912d3d"
		           config-ref="File_Config"
		           path="sharepoint-test1.txt"/>
		<sharepoint:file-add doc:name="add-file"
		                     doc:id="3509ec2b-6135-4ed6-bf70-c98320a7ad64"
		                     config-ref="Sharepoint_Sharepoint_online"
		                     fileServerRelativeUrl='#[vars.createFolderResponse.serverRelativeUrl default "" ++ "/" ++ attributes.fileName]'>
			<sharepoint:file-content-stream><![CDATA[#[payload]]]></sharepoint:file-content-stream>
		</sharepoint:file-add>
		<set-payload value="#[%dw 2.0

output application/json

---

payload]"
		             doc:name="response"
		             doc:id="8cb2cc38-cfee-43ef-ab93-08bd7c6e3852"/>
	</flow>
</mule>


Now we will explore the Folder Query, Folder Delete, List Create, List Get, and List Get All operations.

Folder Query

This operation retrieves all folders that match the specified criteria. As a use case, we will retrieve folder details under the test folder. Here, Mule is a document library. 

SharePoint test folder snapshot

SharePoint test folder snapshot

We have to provide the below 2 parameters to configure the Folder Query operation

Folder Query operation configuration


Folder Query response snapshot

Folder Delete

It deletes a folder from a document library. We will delete the xyz-docs folder under the test folder. We have to provide the server-relative URL of the folder to delete in the URL field.

Folder Delete operation configuration


If the folder is successfully deleted, then the Folder Delete operation will return a null payload.

SharePoint test folder snapshot after deletion


List Create

It creates a new SharePoint list. We have to provide a SharePoint list reference in the list parameter.

List parameter value snapshot


In the case that you are using a lower version of the SharePoint connector, you may have to explicitly typecast the list parameter to SharePointList class. You can refer to this article for that. 

Employee list created in SharePoint

List Create operation response snapshot

List Get

It retrieves SharePoint list details of the provided list ID. We will provide the list ID of the employee list.  

List Get operation configuration


List Get operation response


List Get All: It retrieves all (custom and system) SharePoint lists present on the site.

Wrapping Up

That will be all. I hope this article helps you with integrating your SharePoint projects with MuleSoft.

 

 

 

 

Top