SharePoint Integration with MuleSoft - Part 1
source link: https://dzone.com/articles/sharepoint-integration-with-mulesoft-part-1-1
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
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.
Now, read a file using the File connector read operation. Let's, configure SharePoint connector File add operationto add a file to the newly created SharePoint folder. Provide the details for the below two fields in the File add configuration
- File Server Relative Url = Where to add the new file.
- File Content Stream = The content that this new file should contain.
You can refer to the below snapshot for 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
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.
Mule Flow Code
<?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>
That will be all. I hope this article helps you with integrating your SharePoint projects with Mulesoft.
Stay tuned for the next part!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK