May 25, 2022

Blog @ Munaf Sheikh

Latest news from tech-feeds around the world.

SharePoint Integration with MuleSoft – Part 1

Great post from our friends at Source link

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

In part 1, I will be covering the Folder create and File add operation.

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





” data-lang=”application/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:luffyDesktoptestsharepoint-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 "" ++ "https://dzone.com/" ++ 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>

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

Stay tuned for the next part!

#SharePoint #Integration #MuleSoft #Part