OneDrive Integration using Microsoft Graph API in SAP CPI
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.
- 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
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.
Create a property to store the incoming payload.
Set Client ID,Client Secret and grant-type =client_credentials for basic auth.
Create a property for storing the base url-https://login.microsoftonline.com
Add a request reply and in address put the OAuth url generated in Graph api it looks like baseurl/dqjscbejhcbe2hbcbehdbqhjvcewvceecwvh/oauth2/v2.0/token
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.
After this add a Content modifier to store the bearer token in a property.
Then again add a content-modifier with setting headers and setting the original payload that we stored in a property.
Now we will send the data to OneDrive using the api in the format
And also pass the Bearer header that we created in the request reply.
Finally after deploying the artifact and giving input as the excel file via postman the file is uploaded to sharepoint.