Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
643

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.

https://community.sap.com/t5/technology-blogs-by-sap/cloud-integration-call-microsoft-graph-api-with...

https://community.sap.com/t5/technology-blogs-by-members/integrating-sap-btp-cpi-with-microsoft-shar...

https://community.sap.com/t5/technology-blogs-by-members/integrate-sharepoint-using-sap-pi/ba-p/1335...

https://community.sap.com/t5/technology-blogs-by-members/sap-to-sharepoint-integration-via-microsoft...

Prerequisites

  1. Azure AD App Registration: Register an application in Azure Active Directory to get the necessary credentials (Client ID, Tenant ID, and Client Secret) for authentication.

        santanu_singharoy_0-1742736708936.png

Once the app registration is done ; Click on the Endpointssantanu_singharoy_1-1742736731781.png 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 santanu_singharoy_2-1742736731782.png

Redirect URI to test from Postman : https://oauth.pstmn.io/v1/browser-callback

santanu_singharoy_3-1742736762160.png
santanu_singharoy_4-1742736766817.png

2. Permissions: Ensure the app has the necessary permissions to access SharePoint resources. You might need permissions like Files.ReadWrite.All for file operations.

santanu_singharoy_5-1742736798020.png

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.

santanu_singharoy_6-1742736832660.png

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.

santanu_singharoy_7-1742736846470.png

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.

santanu_singharoy_8-1742736938221.png

 

 

Labels in this area