Wednesday, March 5, 2025

OIC - How to download file from sharepoint using Microsoft Graph API 1.0

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

  1. Go to Azure Portal.
  2. Register a new application under Azure Active Directory (AAD).
  3. Assign API permissions:
    • Sites.Read.All or Sites.FullControl.All (Application permissions)
    • Files.Read.All for file access
  4. 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 using https://graph.microsoft.com/v1.0/sites/{tenant-name}.sharepoint.com:/sites/{site-name}
  • {drive-id}: Retrieve using https://graph.microsoft.com/v1.0/sites/{site-id}/drives
  • {file-id}: Retrieve using https://graph.microsoft.com/v1.0/sites/{site-id}/drives/{drive-id}/root/children

Step 4: Implement in OIC

  1. Create an OIC Integration
    • Use the REST Adapter to invoke the Microsoft Graph API.
  2. Configure Authentication
    • Use OIC REST connections to pass the access token dynamically.
  3. Download and Store File
    • Store the response content in an FTP/SFTP location or pass it to another service.
Highlevel steps implemented:
  1. User will feed site name, drivename, file name pattern to download the file from sharepoint
  2. Get site id from site name
  3. Get drives under the site id
  4. Select the drive id for the drive name provided.
  5. List the children files or folders under the drive id
  6. Exclude the folders and select the file id for the file pattern
  7. Download content stream reference for the file id.
  8. 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:



How to use Microsoft graph explorer to test graph APIs

Use Case: How to use or test Microsoft 365 graph APIs using Graph Explorer.

Solution Steps:

  1. Access Graph Explorer: Go to Microsoft Graph Explorer.
  2. Sign In: Click "Sign in with Microsoft" and log in using your Microsoft 365 credentials.
  3. Select API: Choose GET https://graph.microsoft.com/v1.0/me to fetch the logged-in user's details.
  4. Run Query: Click "Run Query" to execute the API call and view the response.
  5. Modify & Test: Try different APIs like /users, /groups, or /me/messages by modifying the request.
  6. Check Permissions: If needed, click "Modify Permissions" and consent to required scopes.
  7. Analyze Response: Review the JSON output to validate the API response.

This helps test and understand Microsoft Graph APIs without writing code.

Screenshots:

Login


Checking my user details

Checking my drive id


Testing to see the drive children.



Monday, March 3, 2025

OIC - How to Copy an Integration from One Project to Another in Oracle Integration Cloud (OIC)

How to Copy an Integration from One Project to Another in Oracle Integration Cloud (OIC)

Use Case: Migrating Integrations Between OIC Projects

In large-scale Oracle Integration Cloud (OIC) environments, teams often work on multiple projects simultaneously. When an integration built in one project needs to be reused or enhanced in another, copying it efficiently ensures consistency and reduces development effort.

Solution Steps to Copy an Integration Between Projects in OIC

  1. Enable Cross-Project Availability: While creating the integration in one project, select the option to make it available in other projects.

  2. Navigate to the Target Project: Switch to the project where you want to copy the integration.

  3. Copy the Integration: Click on Copy Integration, then search for the required integration from the available list.

  4. Confirm and Modify if Needed: After copying, update any necessary configurations, such as connections and mappings, to align with the new project’s requirements.

  5. Activate and Test: Once all updates are done, activate the integration and perform testing to ensure it functions as expected.

Detailed Screenshots:






Friday, February 28, 2025

OIC - How to retrieve previous node value using preceding-sibling in OIC XSLT

Retrieving the Previous Node Value in OIC XSLT: Ensuring RT Records Have D1 as the Previous Record

Use Case: RT Record Validation in Oracle Integration Cloud (OIC)

In Oracle Integration Cloud (OIC), performing sequence-based validation in XML transformations is essential to maintain data integrity. One such scenario requires verifying that every RT record is immediately preceded by a D1 record.

Validation Rules:

  • If a record starts with "RT", the immediately preceding record must start with "D1".
  • If an "RT" record does not have a preceding "D1", a structure validation error will be thrown to ensure data correctness.

This validation helps enforce the required sequence before further processing, preventing incorrect or incomplete data from being processed in OIC.

Json used for writing a validation messages using stage:

{

    "Validation" : [{

        "Message" : "XXXXXXXXXXXX"

    }]

}

Solution steps:

  1. For each record
  2. Check if it is record starting with RT.  substring(ns:23FileData, 1,2) = 'RT'
  3. Check the preceding node not starting with D1,  substring ($ReadRawSourceFile/nsmpr0:Read Response/ns23:FileRowSet/ns23:FileRow[(ns23:FileData = current()/ns23:FileData)]/preceding-sibling::ns23:FileRow[1.0]/ns23:FileData, 1, 2) !="D1"
  4. validation error message: dvm:lookupValue("File_Validation", "key","V25","ValidarionMessage","Invalid File")

Detailed screenshots:





Similarly, to get next sibling node. We can use below xslt construct.

"following-sibling::*[1]"


Thursday, February 20, 2025

OIC - How to Retrieve Email Attachments Using Microsoft Graph API: Automating Payment File Processing

Retrieving Email Attachments Using Microsoft Graph API: Automating Payment File Storage in Object Storage

Use Case:
A finance team needs to automate the extraction of payment files from vendor emails in Outlook and securely store them in an object storage solution (e.g., AWS S3, Azure Blob Storage, or Oracle Object Storage). Using Microsoft Graph API, they can programmatically fetch email attachments and upload them to object storage for secure access, processing, and archival.

HighLevel steps:

  1. Create a rest connection using Microsoft Graph APIs.
  2. Get Email unread Messages filtering on Subject.
  3. If no message with attachment found, throw a fault.
  4. For each message, 
    1. check if it has the attachment.
    2. Get list of attachments
    3. For each attachment,
      1. Upload file to Object storage for further processing.
Graph APIs used:

Connection URL: https://graph.microsoft.com/v1.0
Scope: https://graph.microsoft.com/.default
Get messages: /users/{userPrincipalName}/messages
List attachments: /users/{userPrincipalName}/mailFolders/{mailFolderId}/messages/{messageId}/attachments
Upload to object storage: /n/{namespacename}/b/{bucketname}/o/{objectname}

Detailed steps with screenshots:

Create rest connection:



Get Email  unread Messages for a matching subject.




Mapping:



If no message with attachment found:


For each message check if it has attachment



Get list of attachments:





For each attachment, upload content to Object storage




Reference:



Wednesday, February 12, 2025

OIC - Moving a File using FTP connection now throws IO operation failed error

Error usecase:

Moving a File using FTP connection now throws IO operation failed error.

The integration has been working for weeks, with a file move operation from source directory to target directory in SFTP connection, but now has started throwing the below error.

The directory permissions were checked and file owner and all seems correct.

ERROR

The I0 operation failed.

The I0 operation failed.

The "OPER [NOOP] [UseNativeRename (S->R, T->R)]" I0 operation for "<Directory>/<Filename>" failed.

Check the error stack and fix the cause of the error.

Solution:

The file was already present in the system and was not overwritten. 

However, select the overwrite option while configuring the adapter.



Friday, February 7, 2025

OIC - How to Skip OIC Schedule During Public Holidays

Skipping OIC Schedule During Public Holidays

Use Case:

In Oracle Integration Cloud (OIC), scheduled integrations run at predefined intervals. However, organizations may need to prevent these jobs from executing on public holidays to optimize resources and avoid unnecessary processing.

Example Scenario

A company has a daily OIC integration that syncs employee attendance data from an external system to Oracle HCM. Since no employees work on public holidays, the integration should be skipped on those days.

Solution Approach: Using an OIC Lookup Table

Steps to Implement:

  1. Create a Lookup Table in OIC:

    • Go to Lookups in OIC and create a new lookup table.
    • Define two columns: HolidayDate and Flag
    • Populate the lookup with public holidays for the year.
  2. Modify the Scheduled Integration:

    • Retrieve the current date in the integration.
    • Check the lookup table to see if today’s date exists.
    • If today is a holiday:
      • Log a message: "Skipping execution due to public holiday."
      • Exit the integration.
    • If today is not a holiday, proceed with execution.
  3. Update the Lookup Table Annually:

    • At the start of each year, update the lookup table with the new list of public holidays.

Detailed screenshots:




If there is a need to run the integration ad hoc on a public holiday in certain cases, we can introduce a schedule parameter IsReprocess. If IsReprocess is set to "Y", the integration will run regardless of the holiday. Otherwise, it will check the lookup table and skip execution if today is a public holiday.

Conclusion

By using an OIC lookup table, scheduled integrations can dynamically check for public holidays and skip execution when necessary. This approach ensures efficient resource utilization and prevents unnecessary API calls.

Featured Post

OIC - OIC Utility to Reprocess Failed Real-Time Integration JSON Payloads

📌 Use Case In real-time OIC integrations, JSON payloads are exchanged with external systems via REST APIs. When such integrations fail (du...