OneDrive Integration using Microsoft Graph API in SAP CPI
2023-11-15 17:10:53 Author: blogs.sap.com(查看原文) 阅读量:4 收藏

Hi all,

Recently I have got a requirement to integrate SAP CPI with OneDrive.The requirement is the sender system would send an excel file in .xlsx format and I need to add that excel file inside a folder in the OneDrive.

Microsoft Graph is a Microsoft API developer platform that connects multiple services and devices.

Prerequisites:

  • OneDrive Service Account(Personnel/Business) with application Developer role.
  • Create application in Microsoft Application Registration Portal.
  • Create a client secret.
  • Add API permissions to authorize our app to access OneDrive.

Set Up in OneDrive

Step-1

Step-1

Step-2

Step-3

Step-4

Step-5

Step-6

Step-7

Step-8

Step-9

Step-10

Set Up in Integration Flow

I need to send the excel files to this folder

In my flow the excel file is coming to me as a base64 encoded format from the sender through process direct adapter.

Step-1

Create a header to set Content-Type as application/x-www-form-urlencoded

Step-2

Create a property to store the incoming payload.

Step-3

Set Client ID,Client Secret and grant-type =client_credentials for basic auth.

Step-4

Create a property for storing the base url-https://login.microsoftonline.com

Step-5

Add a request reply and in address put the OAuth url generated in Graph api it looks like baseurl/dqjscbejhcbe2hbcbehdbqhjvcewvceecwvh/oauth2/v2.0/token

Step-6

The response would be in JSON format so we require to convert it to XML for further processing.So , here we add a JSON to XML Converter.

Step-7

After this add a Content modifier to store the bearer token in a property.

Step-8

Then again add a content-modifier with setting headers and setting the original payload that we stored in a property.

Step-9 

Now we will send the data to OneDrive using the api in the format

https://graph.microsoft.com/v1.0/sites/{baseurlofonedrive}/drives/root:/{Folder_Name}/{filename}.xlsx:/content

And also pass the Bearer header that we created in the request reply.

SUMMARY

Finally after deploying the artifact and giving input as the excel file via postman the file is uploaded to sharepoint.


文章来源: https://blogs.sap.com/2023/11/15/onedrive-integration-using-microsoft-graph-api-in-sap-cpi/
如有侵权请联系:admin#unsafe.sh