Sunday, July 6, 2025

OIC - How to upload file to sharepoint using Microsoft graph API

📌 Use Case

In this use case, we are building an integration in Oracle Integration Cloud (OIC) that:

  1. Downloads a file from a File Server.
  2. Uploads that file to a specific SharePoint folder using Microsoft Graph API.

This is especially helpful in scenarios where enterprises manage data exports on file servers and want to automate data archival or sharing via SharePoint.


⚙️ Solution Design Overview

The integration follows these main steps:

  1. Trigger – A scheduled or REST-based trigger initiates the process.
  2. Fetch Site ID – Retrieves SharePoint Site ID using the server-relative path.
  3. Fetch Drive ID – Retrieves the Drive ID associated with the Site.
  4. Download File – Reads the file from the file server.
  5. Upload File – Uploads the file to SharePoint using Microsoft Graph API PUT call.

🔍 Step-by-Step Solution


✅ Step 1: Get SharePoint Site ID

  • REST Endpoint Name: GetSiteID
  • Method: GET
  • Relative URI:
    /sites/{tenant}.sharepoint.com%3A/sites/{server-relative-path}
    
  • Response Sample:
    {
      "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites/$entity",
      "createdDateTime": "2022-09-26T07:22:04.923Z",
      "description": "sp_org_app_DWCSSystemIntegration_qa",
      "id": "yourtenant.sharepoint.com,c87b311d-f1f0-4576-9f43-256b0366ccd4,315734c4-892c-486f-8901-5c8827144a16",
      "lastModifiedDateTime": "2024-08-23T11:25:16Z",
      "name": "sp_org_app_DWCSSystemIntegration_qa"
    }

✅ Step 2: Get SharePoint Drive ID

  • REST Endpoint Name: GetDriveID
  • Method: GET
  • Relative URI:
    /sites/{siteId}/drives
    
  • Query Parameter:
    $filter = name eq '<folder_name>'
    
  • Site ID is dynamically extracted from the previous response using an XSL mapping.

🧠 Conditionally Construct Filter Query:

  • Use substring-before() if parentpath has /
  • Else use as is

Sample response:

{

  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives",

  "value": [

    {

      "id": "b!0mFabc12345def6789ghiJKLmnopQRSTuvwxYZaBCDE",

      "driveType": "documentLibrary",

      "name": "Documents",

      "webUrl": "https://yourtenant.sharepoint.com/sites/testsite/Shared%20Documents",

      "createdDateTime": "2023-04-20T10:30:00Z",

      "lastModifiedDateTime": "2024-03-15T08:45:00Z",

      "createdBy": {

        "user": {

          "displayName": "Admin User",

          "id": "admin-user-id"

        }

      },

      "lastModifiedBy": {

        "user": {

          "displayName": "Admin User",

          "id": "admin-user-id"

        }

      }

    },

    {

      "id": "b!9xYz321klmn456uvwXYZabcDEfghiJKLMNoPQrsTUv",

      "driveType": "documentLibrary",

      "name": "Shared Documents",

      "webUrl": "https://yourtenant.sharepoint.com/sites/testsite/Shared%20Documents"

    }

  ]

}



✅ Step 3: Download File from File Server

  • Action: Use File Adapter with Native File System (FS)
  • Read Mode: Binary
  • Output: Stream Reference

✅ Step 4: Upload File to SharePoint

  • REST Endpoint Name: UploadFileToSharepoint
  • Method: PUT
  • Relative URI:
    /drives/{driveid}/root:/{filename}:/content
    
  • Payload Format: Binary
  • Content-Type: Set as dynamic or static depending on file type
    Example: text/csv or application/octet-stream

🧩 Key Integration Design Elements

Component Description
Trigger REST or Schedule Trigger
File Server Native File Adapter
SharePoint Microsoft Graph API
Mapping Used to extract siteId, build filter, and construct headers
Headers Content-Type (optional but recommended)
Payload Binary Stream from File Adapter

🛠️ Pre-requisites

  • Microsoft Graph OAuth 2.0 Authentication configured in OIC
  • SharePoint API permissions:
    • Sites.Read.All
    • Files.ReadWrite.All
  • File server connection configured
  • OIC connectivity agent if on-prem file server

📌 Conclusion

With this approach, you can automate file transfers between a File Server and SharePoint seamlessly using OIC. This design is scalable and allows for dynamic path and filename handling, making it robust for real-world enterprise use cases.


Implementation screenshots:

Trigger:



Get file from file server



Get site id




Get drive id






Upload file to sharepoint







No comments:

Post a Comment

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...