Downloading Files from SharePoint Using Microsoft Graph API in Oracle Integration Cloud (OIC)
Use Case
In an Oracle Integration Cloud (OIC) implementation, there may be a requirement to download files stored in a SharePoint document library for further processing. Microsoft Graph API provides a secure and efficient way to fetch files from SharePoint Online.
Solution Steps
Prerequisites
- A registered Azure AD application with permissions to access SharePoint
- Client ID, Tenant ID, and Client Secret for authentication
- A SharePoint site with files stored in a document library
- Oracle Integration Cloud (OIC) with REST Adapter
Step 1: Configure Microsoft Azure App
- Go to Azure Portal.
- Register a new application under Azure Active Directory (AAD).
- Assign API permissions:
- Sites.Read.All or Sites.FullControl.All (Application permissions)
- Files.Read.All for file access
- Generate a Client Secret for authentication.
Step 2: Obtain an Access Token
Use OIC to fetch an access token from Microsoft Identity Platform using the following API:
Request:
POST https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials
&client_id={client_id}
&client_secret={client_secret}
&scope=https://graph.microsoft.com/.default
Response:
{
"access_token": "eyJ0eXAiOiJKV..."
}
Step 3: Download a File from SharePoint
Use Microsoft Graph API to fetch the file from the document library.
API Request:
GET https://graph.microsoft.com/v1.0/sites/{site-id}/drives/{drive-id}/items/{file-id}/content
Authorization: Bearer {access_token}
{site-id}
: Retrieve usinghttps://graph.microsoft.com/v1.0/sites/{tenant-name}.sharepoint.com:/sites/{site-name}
{drive-id}
: Retrieve usinghttps://graph.microsoft.com/v1.0/sites/{site-id}/drives
{file-id}
: Retrieve usinghttps://graph.microsoft.com/v1.0/sites/{site-id}/drives/{drive-id}/root/children
Step 4: Implement in OIC
- Create an OIC Integration
- Use the REST Adapter to invoke the Microsoft Graph API.
- Configure Authentication
- Use OIC REST connections to pass the access token dynamically.
- Download and Store File
- Store the response content in an FTP/SFTP location or pass it to another service.
- User will feed site name, drivename, file name pattern to download the file from sharepoint
- Get site id from site name
- Get drives under the site id
- Select the drive id for the drive name provided.
- List the children files or folders under the drive id
- Exclude the folders and select the file id for the file pattern
- Download content stream reference for the file id.
- Upload file content to object storage or other oprion as per requirement.
Detailed screenshots:
Create rest connection:
Connection url: https://graph.microsoft.com/v1.0
Provide client id , client secret, access token, scope and client authentication
Scope: https://graph.microsoft.com/.default
Configure trigger:
Request payload
{
"ProcessingId": "",
"SiteName": "",
"DriveName": "",
"FileNamePattern": "",
"bucketName": "",
"NameSpace": ""
}
Response payload:
{
"Status": "WARNING/ERROR/SUCCESS",
"File": [
{
"Names": "",
"Message": "actual error"
}
]
}
Get site id for site name
GET /{tenant}.sharepoint.com:/sites/{site-name}
Get drives under the site
/sites/{siteId}/drives
Add $filter query param and assign
concat("name eq '",<driveName>,"'")
Assign drive id for the drive name
List drive files
/sites/{siteId}/drives/{driveId}/root/children
For each item
Exclude folders and select the file which match the pattern
Get content stream reference for the file:
/drives/{driveId}/items/{itemId}/content
Testing:
No comments:
Post a Comment