Technical Articles
Google Drive integration using Custom Adapter via SAP Integration Suite
Introduction
This Blog demonstrates a custom Google Drive adapter for SAP Integration Suite, designed to facilitate seamless integration between SAP systems and Google Drive. Go through the adapter source code to understand the logic and implementation. Standard Google Adapters will be delivered via Google Workspace adapter and planned for Q3 2024. This is just a fun project to understand the basics behind Google APIs and implementing the same through an adapter. Not recommended for productive use but if you are trying to create a adapter for your project then surely take a reference of the source code.
Features
-
Bi-Directional Integration: This adapter supports both inbound and outbound data transfer between SAP and Google Drive, allowing you to push data from SAP to Google Drive and pull data from Google Drive into SAP.
-
Secure Authentication: The adapter provides secure authentication mechanisms to ensure that your data remains protected during the integration process.
-
Customizable Configuration: You can easily configure the adapter to suit your specific integration needs, including specifying folders and document types within Google Drive.
-
Real-time and Batch Processing: The adapter supports real-time and batch processing, giving you flexibility in how you exchange data between SAP and Google Drive.
-
Sender and Receiver Adapter: This adapter support both Sender and Receiver type configuration.
-
Scheduler Support: Sender adapter can be configured to run as per the schedule.
-
Externalized Parameters: All the parameters of the adapter can be externalized.
-
Simple Camel Expression Support: Simple Camel expressions are supported as input variables.
-
Archive and Delete Support: Archiving with or without added timestamp supported.
-
Huge File Upload Support: A resumable upload method is used to upload huge data in chunks.
Table of Contents
- Creating Client ID and Secret for Google Drive API
- Deploying a Custom Google Drive Adapter in SAP Integration Suite
- Prerequisites
- Configure the Google Drive Sender Adapter
- Configure the Google Drive Receiver Adapter
- Deploy iFlow
- Test
- Conclusion
Creating Client ID and Secret for Google Drive API
In order to access Google Drive API v3, you need to create OAuth 2.0 credentials, which include a client ID and secret. Follow these steps to obtain your credentials:
1. Set Up a Project in Google Cloud Console
- Go to the Google Cloud Console.
- Click the project drop-down and select or create the project you want to use for the Google Drive API.
2. Enable the Google Drive API
- In the Google Cloud Console, navigate to “APIs & Services” > “Library.”
- Search for “Google Drive API” and select it.
- Click the “Enable” button to enable the API for your project.
3. Create OAuth 2.0 Credentials
- In the Google Cloud Console, navigate to “APIs & Services” > “Credentials.”
- Click the “Create Credentials” dropdown and select “OAuth client ID.”
- Choose “Web application” as the application type.
4. Configure the OAuth Consent Screen
- Click “Configure consent screen.”
- Fill in the required fields such as “App Name” and “User Support Email.”
- Add the authorized domains for your application.
- Add the scope for your application.
5. Create OAuth Client ID
- After configuring the consent screen, you will be redirected to the OAuth client creation form.
- Enter a name for your OAuth client.
- Under “Authorized redirect URIs,” add the redirect URLs where users will be redirected after granting permission (e.g.,
https://client.com/callback
andhttps://<cf-domain>.integrationsuite.cfapps.jp10.hana.ondemand.com/itspaces/odata/api/v1/OAuthTokenFromCode
). - Click “Create” to create your OAuth client.
- Your client ID and secret will be displayed. Save them securely.
6. Download Credentials JSON
- Click the download icon next to your OAuth client ID to download the credentials JSON file.
- Keep this file secure, as it contains sensitive information.
7. Create Security Material
- Navigate to Security material tiles in the Monitoring Overview page.
- Create an Oauth2 Authorization Code artifact.
- Enter a name and description for your artifact.
- Choose Provider as Generic.
- Under Authorization URL and Token Service URL add
https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force
andhttps://oauth2.googleapis.com/token
respectively. - Copy client ID and secret from the JSON downloaded in section 6.
- Select Send As Body Parameter radio button.
- Add
https://www.googleapis.com/auth/drive
in the Scope input box. - Click on Deploy button.
8. Authorize Security Material
- Click on Authorize button.
- New tab will open with Google sign in page. Login with the user added in section 4.
- If your consent app is still in testing then you might get the below screen. Click on continue to proceed.
- You will be redirected to this page. Please note you should receive below response otherwise the security material is not setup correctly.
<response>Authorization was successful: Refresh Token was added to the OAuth2 Authorization Code Credential 'GoogleAPI'.</response>
Now you have successfully created OAuth 2.0 credentials (client ID and secret) for the Google Drive. You can use this security material in your iFlow to authenticate and access Google Drive resources.
Make sure to handle your credentials securely and never expose them in publicly accessible code or repositories.
Deploying a Custom Google Drive Adapter in SAP Integration Suite
In this guide, we will explore two methods for deploying a Custom Google Drive Adapter in SAP Integration Suite:
- Direct Upload using Web UI
- Upload using API
Method 1: Direct Upload using Web UI
Note: This method may take long time to upload.
Step 1: Log in to SAP Integration Suite
- Navigate to the SAP Integration Suite Web UI.
- Log in to your SAP Integration Suite account.
Step 2: Access the Integration Package
- In the SAP Integration Suite Web UI, go to the “Design” section.
- Locate and select the integration package where you want to deploy the Custom Google Drive Adapter.
Step 3: Download the Adapter File
- Download the
asutosh.drive.esa
file from the build path. - Save it locally.
Step 4: Upload the Custom Adapter
- Inside the integration package, click “Edit,” then navigate to the “Artifacts” tab.
- Click the “Add” button and select “Integration Adapter” to create a new custom integration adapter.
- Click the “Browse” button to select the
asutosh.drive.esa
file for the adapter. - Click “Ok.”
Step 5: Deploy the Integration Flow
- Navigate to the “Action” button and select the “Deploy” option.
- Monitor the deployment to ensure it’s successful.
Method 2: Upload using API
Step 1: Obtain Service Keys
- Navigate to the BTP Cockpit.
- Go to your respective Sub-account and click on “Instances and Subscriptions” to check for the service instance.
- Check for the Service
Process Integration Runtime
and Planapi
. If not found, quickly navigate toService Marketplace
and search forProcess Integration Runtime
service. - Create a new instance and choose Plan as
api
. - Provide an appropriate Instance Name and click on the next button. Select
AuthGroup_IntegrationDeveloper
andWorkspacePackagesEdit
roles. Then click on the “Create” button. - Now navigate to the instance and create a Service Key for the instance by providing an appropriate
Service Key Name
. - Copy the JSON file to a secure location.
Step 2: Postman Setup
- Navigate to the SAP Business Accelerator Hub.
- Download the API Specification as JSON.
- Go to the Postman application and click on the
import
button. Drag and drop the JSON specification and click on theimport
button to create the collection. - Navigate to the
Integration Content
collection. - Go to the
Authorization
tab. SelectOAuth 2.0
as theType
andClient Credentials
as theGrant Type
. - Add the
Access Token URL
,Client ID
, andClient Secret
as per the Service Key JSON file created in Step 1. - Now navigate to the
Variables
tab and give your Cloud Integration API URL (e.g.,https://<cf name>.it-<cf id>.cfapps.jp10.hana.ondemand.com/api/v1
. You can get the same URL from the Service Key JSONurl
field +/api/v1
). - Now navigate to the
Integration Content/IntegrationPackages/Get all integration packages.
request and Add the headerx-csrf-token
with the valuefetch
. Click on theSend
button and copy thex-csrf-token
header value and packageId
from the response.
Step 3: Import the Adapter
- Clone GitHub repo to your local PC either using
git clone https://github.com/Asutosh-Integration/asutosh.drive.git
command (if you havegit
installed) or else you can directly Download ZIP from GitHub. - Now Open the Project in any IDE of your choice and run
src/main/java/asutosh/google/FileToBase64AndSaveToFile.java
file. - Now navigate to
target/build/asutosh.drive-Base64.txt
path and copy the file content (Base64 encoded string ofasutosh.drive.esa
file). - Navigate to the Postman tool and
Integration Content/IntegrationAdapterDesigntimeArtifacts/Import integration adapter artifact
request. - Go to the body and add below JSON (After replacing
Base64Content
andpackageID
with the copied file content and Integration package ID).{ "PackageId": "packageID", "ArtifactContent": "Base64Content" }
- Add the header
X-CSRF-Token
with the value received in the previous request. - Use the Send button to import the custom adapter into the SAP Integration Suite tenant.
Step 4: Deployment
- Navigate to the SAP Integration Suite Web UI and deploy the adapter.
- Ensure that the Custom Google Drive Adapter is successfully deployed.
Congratulations! You have successfully deployed a Custom Google Drive Adapter in SAP Integration Suite using either of the above two different methods. Please refer the Documentation for step-by-step guide on adapter configuration in the iFlow.
Note: For more detailed instructions and troubleshooting tips, refer to SAP Integration Suite documentation or consult your SAP support resources.
Prerequisites
Before proceeding, ensure you have the following prerequisites in place:
- Security Material for Google OAuth 2.0 Authorization Code created.
- Custom Google Drive adapter deployed in the tenant.
- Download and import sample iFlow to your SAP Integration Suite tenant.
Configure Custom Google Drive Sender Adapter
Once you have created a sender channel and selected the Google Drive sender adapter, you can configure the following attributes.
General
Parameter | Description |
---|---|
Name | Enter the name of the Google Drive channel. |
Settings
Parameter | Description |
---|---|
Choose Operation | Only Download operation is supported in Sender Channel. |
File Path | Name of the file to Download. Use of Simple Camel expression is also supported. ⚠️Caution: Multiple filenames are not supported. Please always mention absolute path from the root ( / ).While using both Simple Expression and constant, Please always mention extension of the file separated by . .ℹ️Note: Example of supported file paths are below. /<rootFolder>/<subFolder>/<filename>.<ext> , /<filename>.<ext> , ${header.filepathwithext} , /<rootFolder>/${property.filenamewithext} Example of file paths not supported are below. <rootFolder>/<filename>.<ext> (should start with / or ${<expression>} ), /<rootFolder>/<filename> (extension should be there in the filename) |
Credential Name | Name of the Oauth2 Authorization Code artifact. |
Archive (Optional) | Allow you to specify if you want to Archive the file. Choosing only archive (without Delete) will not delete the original file (only make a copy of file in the archive path). |
Delete (Optional) | Allow you to specify if you want to Delete the file. Choosing only Delete (without Archive) will move the file to trash. |
Archive File Path (Mandatory if Archive selected) | Specifies the target directory where to move the file. ⚠️Caution: Target folder creation is not supported as of now so always mention the folders which are present in the drive. |
Add Timestamp (Optional) | Allow you to specify if you want to add timestamp to the archive file name. e.g. archiveFilename2023-09-14 17:15:20.217.pdf |
Scheduler
Scheduler Option | Field | Description |
---|---|---|
Run Once | Specify if you want to run only once. | |
Schedule on Day | On Date | Specify the date on which you want the operation to be executed. |
On Time | Specify the time at which you want the operation to be executed. | |
Every | Specify a time period (e.g., every hour) in a dedicated time window. | |
Time Zone | Select the time zone that you want the scheduler to use as a reference for the date and time. | |
Schedule to Recur | Daily | Select the time or interval and time zone for the schedule to recur. |
Weekly | Select the checkboxes to indicate the days of the week on which the operation has to be executed. Also, specify the time or interval for the schedule to recur. | |
Monthly | Select the day of the month on which the operation has to be executed. Also, indicate the time or the interval for the schedule to recur. |
Configure Custom Google Drive Receiver Adapter
Once you have created a sender channel and selected the Google Drive receiver adapter, you can configure the following attributes.
General
Parameter | Description |
---|---|
Name | Enter the name of the Google Drive channel. |
Settings
Parameter | Description |
---|---|
Choose Operation | Select the type of operation you want to perform. 1. Download: Export the file from the Google Drive. 2. Upload: Import the file to the Google Drive. |
File Path | Name of the filepath to Download/Upload. Use of Simple Camel expression is also supported. ⚠️Caution: Multiple filenames are not supported. Please always mention absolute path from the root ( / ).While using both Simple Expression and constant, Please always mention extension of the file separated by . .ℹ️Note: Example of supported file paths are below. /<rootFolder>/<subFolder>/<filename>.<ext> , /<filename>.<ext> , ${header.filepathwithext} , /<rootFolder>/${property.filenamewithext} Example of file paths not supported are below. <rootFolder>/<filename>.<ext> (should start with / or ${<expression>} ), /<rootFolder>/<filename> (extension should be there in the filename) |
Credential Name | Name of the Oauth2 Authorization Code artifact. |
Archive (Optional) | Allow you to specify if you want to Archive the file. Choosing only archive (without Delete) will not delete the original file (only make a copy of file in the archive path). |
Delete (Optional) | Allow you to specify if you want to Delete the file. Choosing only Delete (without Archive) will move the file to trash. |
Archive File Path (Mandatory if Archive selected) | Specifies the target directory where to move the file. ⚠️Caution: Target folder creation is not supported as of now so always mention the folders which are present in the drive. |
Add Timestamp (Optional) | Allow you to specify if you want to add timestamp to the archive file name. e.g. archiveFilename2023-09-14 17:15:20.217.pdf |
Deploy iFlow
- Save your iFlow configuration.
- Deploy the iFlow to your SAP Integration Suite tenant.
- Monitor the iFlow for any issues or errors during execution.
Test
Test Configuration:
Sender Adapter
The sender adapter is configured to download the file and scheduled to run once. The Archive, Delete and Add Timestamp is also added.
Content Modifier
A content modifier is added to define the file name as a property and assign a string “x” as the body to be uploaded by the receiver adapter.
Receiver Adapter
The receiver adapter is configured to upload the file to google drive with simple camel expression in the file path.
Result
Expected Result
The iFlow run will Download the TestFile.pdf
file from TestFolder
and archive the same with added timestamp in TestFolder
. This will also upload a file named as TestFile1.pdf
in TestFolder
as per the file path configuration /TestFolder/${property.x}
.
Before Deployment
There is only one file named TestFile.pdf
in TestFolder
.
Result
There are 2 files in the TestFolder
.
TestFile1.pdf
contain “x” which was configured in the content modifier body.
Conclusion
You have successfully configured and deployed a SAP Integration Suite iFlow with a custom Google Drive adapter, enabling scheduled runs, file downloads, archiving, timestamping, and handling large files. Make sure to test the adapter thoroughly in your tenant to ensure it meets your integration requirements.
If not then you can always clone the repo and change the code as per the requirement and then use maven mvn clean install
command to build the adapter again.