
Introduction
With the era of digital transformation, smooth integration of various cloud solutions is a must for businesses who aim to achieve maximum efficacy and collaboration. Microsoft SharePoint, as much praised for its robust document management and collaboration features, can be even more effective while integrated with SAP Cloud Platform Integration (CPI).
This blog post is about the integration of SAP CPI with MS SharePoint using the Microsoft Graph API, a multi-purpose utility that facilitates connectivity and automation of file/directory activities. Through the application of the powers of Graph API, organizations can easily implement actions such as reading, downloading, moving, and deleting files and directories from/in SharePoint using SAP CPI capabilities.
Such integration not only streamlines workflows but also ensures data consistency and boosts productivity across platforms. Whether your goal is to optimize document management or optimize collaborative efforts, in this blog tried to equip the reader with the information that were used to make seamless connectivity between MS SharePoint and SAP CPI integration.
While learning about Microsoft Graph API SharePoint and SAP CPI integration, I found some really good blogs mentioned below, that helped in understanding the concepts and were very helpful in shaping my approach. These blogs provided me with the confidence and clarity of thought that were needed to execute this integration process.
Prerequisites
Once the app registration is done ; Click on the Endpoints to get : OAuth 2.0 authorization endpoint (v2), OAuth 2.0 token endpoint (v2). For ClientID and Client Secret can be configured and then, retrieved from
Redirect URI to test from Postman : https://oauth.pstmn.io/v1/browser-callback
2. Permissions: Ensure the app has the necessary permissions to access SharePoint resources. You might need permissions like Files.ReadWrite.All for file operations.
SAP CPI Configuration: Due to constraints associated with using the SharePoint adapter in the current CI-Neo tenant, opted to utilize the HTTP adapter within the CPI flow to execute API calls to the Microsoft Graph API. This approach allowed for effective integration while navigating the limitations of the existing infrastructure.
To retrieve the OAuth2 Authorization Code (Generic) below script can be used :
Note : Make sure the user which has access to the SharePoint App is used to deploy the security material as well, which will be used from CPI.
In order to read/write/modify files below mentioned roles are required and could be granted by the Azure Administrator user.
Used http (receiver) adapter to GET the Download URLs of the files– which could be used later in the process step with another http (receiver) adapter to get the binary content of the files.
Graph API Endpoints:
Definitions
Drive : is the top level object that represents a user's onedrive or a document library in SharePoint
driveId : is the unique identifier of the drive.
itemId : is the unique identifier of the file or folder.
GET SiteID:
https://graph.microsoft.com/v1.0/sites?search=<sitename>
This API call returns the "SiteID"
Search for the drives under the Site
https://graph.microsoft.com/v1.0/sites/<siteid>/drives
Use the SiteID retrieved from the previous step and call the above endpoint;
which will return the DriveID
Retrieve the folder id
https://graph.microsoft.com/v1.0/sites/<siteid>/drives/<driveid>/root:/<DriveName>
Use the above mentioned URL using the <siteid> and the <driveid> retrieved.
Retrieve the files in the folder
https://graph.microsoft.com/v1.0/sites/<siteid>/drives/<driveid>/items/<itemid>/children
Use the siteid, driveid and itemid(folderid)retrieved from the above URL.
subsequently, subfolders' id can be used as "itemid" to retrieve the further files/sub-folders.
Move files between folders
PATCH /drives/<drive-id>/items/<item-id>
Here item-id is the existing folder id
PATCH Request Body
{
"parentReference": {
"id": "<new-parent-folder-id>"
},
"name": "new-item-name.txt"
}
Create Folder
POST https://graph.microsoft.com/v1.0/sites/<SiteId>/drives/<DriveId>/items/<ParentFolderId>/children
{
"name": "foldername",
"folder": {},
"@microsoft.graph.conflictBehavior": "fail"
}
Delete Folder
DELETE https://graph.microsoft.com/v1.0/sites/<SiteId>/drives/<DriveId>/items/<folderid>
In HTTP Header :
Authorization, folder - eTag
Error Handling:
Implement error handling in your integration flow to manage API errors and retries. For example: as shown below for every file processing failure can be written in the DS and retrieve the same from another flow and send mail or any other form of notification.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
7 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 |