DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Migrating MuleSoft System API to AWS Lambda (Part 1)
  • NetSuite Integration Using Mulesoft
  • Kafka Connect: Strategies To Handle Updates and Deletes
  • MuleSoft Integration With RabbitMQ

Trending

  • Advanced Error Handling and Retry Patterns in Enterprise REST Integrations
  • Observability for Agents and Workflows: Tracing Prompts, Tool Calls, and Business Outcomes End-to-End
  • Building Threat Intelligence Pipelines Using Python, APIs, and Elasticsearch
  • 7 Technology Waves I’ve Seen in 30 Years of Software — Will AI Be the Next Real Transformation?
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. SharePoint Integration With MuleSoft

SharePoint Integration With MuleSoft

This post discusses how to integrate SharePoint online with the MuleSoft series. Today, I will be covering several of the folder and list operations.

By 
Saddam Shaikh user avatar
Saddam Shaikh
·
Updated Feb. 07, 22 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
14.8K Views

Join the DZone community and get the full member experience.

Join For Free

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

  • Query: OData query.
  • Starting folder path (optional): The starting path of the folder from where to begin the query, relative to the document library selected as part of the query. For example, /test searches for folders inside /Mule/test.  

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.

SharePoint Database Integration MuleSoft Connector (mathematics) Snapshot (computer storage)

Opinions expressed by DZone contributors are their own.

Related

  • Migrating MuleSoft System API to AWS Lambda (Part 1)
  • NetSuite Integration Using Mulesoft
  • Kafka Connect: Strategies To Handle Updates and Deletes
  • MuleSoft Integration With RabbitMQ

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook