Technical Articles
OpenConnectors-GoogleDrive Integration made simple with SAP CPI & SAP CP-OCN
In below blog would like to share how we can integrate Google Drive with SAP CPI using SAP Cloud Platform Open Connectors service.
Scenarios:
Will explain end to end scenarios of get and post file using POSTMAN http client.
Google Application Creation:
In order to consume Rest APIs of Google Apps we need to create application that communicates securely with SAP CP Open Connectors.
Step 1:
Login to https://console.developers.google.com and follow below steps
Step 2:
Create new project with valid logical name.
Step 3:
Click on the created project and navigate to APIs & Services dashboard.
Step 4:
Enable to Google Drive API to consume it in the application.
Step 5:
Once you enable the required API navigate back to Credentials tab of APIs & services to create credentials that can be used in OpenConnectors.
Once done save it.
Step 6:
Open Connectors Configuration:
Step 1:
Login to your Open Connectors account and search for Google Drive connector.Click on Authenticate
Step 2:
Click on view Optional Fields and enter API key and Secret copied from Google Application.
Step 3:
Once you click on Create Instance button in previous step it will open new window to authenticate with your Google Credentials.Proceed with the same and click on allow application to access your google drive data.
Step 4:
Now you have successfully established the connectivity.Now click on Test in the API docs to make sure you are able to perform smoke test and able to copy the Authorization header & end point url which can be used in your SAP CPI iflow.
now fill the required details and click on execute button.
its time to see the result and copy the credentials.
Creation of IFlow [ get call from SAP CPI ]:
Create an IFlow like below to query the file from POSTMAN and get the file content back.
Step 1:
Add communication channel of type HTTPS and give address like below.
Step 2:
Add content modifier to delete all unwanted headers and set property containing file name with path which can be used in your receiver communication channel.
Step 3:
Add content modifier to set authorization header ( value copied from Open Connectors Step # 4 last screen ).
Step 4:
Add HTTP communication channel with below configuration ( url copied from your Open Connectors Step# 4 config ).
Time to Test your scenario:
Open POSTMAN and copy of the endpoint url of your IFlow ending with /getFile and copy paste the below XML in body.
<Root>
<FilePath>/OpenConnectors/EDI_SAMPLE.txt</FilePath>
</Root>
Creation of IFlow [ Post call from SAP CPI ]:
Create an IFlow like below to post file from Postman and store it in Google Drive.
Note: As highlighted below Allowed Headers needs to updated with value content-type|fileName
Step 1:
Add communication channel of type HTTPS and give address like below.
Step 2:
Add content modifier to set property containing file name with path which can be used in your receiver communication channel.
Step 3:
Add content modifier to set authorization header ( value copied from Open Connectors Step # 4 last screen ).
Step 4:
Add HTTP communication channel with below configuration ( url copied from your Open Connectors Step# 4 config ).
Time to Test your scenario:
Open POSTMAN and copy of the endpoint url of your IFlow ending with /posttFile and follow below screen in order to set header containing file name with path & upload the file in form-data format with key “File”.
And when you click on send ,you are done with posting file to Google Drive with below response with a file in Google Drive folder.
Reference:
[ 1 ] – Open Connector Blog series
Hope this helps!
Regards,
Sriprasad Shivaram Bhat
Hi Sri,
Thanks for the detailed blog. A great way to kick start 2019 ?
Regards,
Karthik
Thanks Sri..
Good start of 2019 🙂 Keep blogging .
Regards,
Ashwini
Thank you so much for this blog Sriprasad. I followed the steps and with few trial I was able to do it. Your blogs are great help to us. Thanks and keep blogging. 🙂
Regards,
Binod
Hi Sriprasad,
When providing the API key and API secret , I am getting the below error. Also i am not sure what is this auth.cloudelements.io url please help me to understand .
https://auth.cloudelements.io/oauth, does not match the ones authorized for the OAuth client. To update the authorized redirect URIs, visit:
Thanks and Regards,
Vijay
Hello Vijay,
Please check the OAuth Consent application whether you have properly given the url,
Also images you have added in the above comment is not visible.
Regards,
Sriprasad Shivaram Bhat
Hi Vijay,
It would probably the reason of authorization domain issue. Please check step 5 from Google app setup in this blog. I faced same issue and it resolved once updated properly
Hello Sri,
Its a very nice blog. I have followed your steps and able to get the file from the open connectors but after i have configured the IFlow in CPI while triggering from postman i’m getting the error as 401 this means unauthorized my doubt is in the below URL(which we have copied from the cloud connectors get operation) upto where i have to give in the Authorization variable is it like from User to before Organization or else from User to end of the line means upto the end of the Organization …
If i gave till the end of the Organization getting the error as HTTP 400 otherwise if i gave intermediate URL getting the error as http 401…in the postman apart from URL , Credentials , Body do we need to send any header parameters ?
Plz help me i’m end of this scenario
Thanks,
Satish.
Hi Sriprasad,
while giving domain as auth.cloudelements.io I'm getting "Invalid domain: must be a top private domain" error and it's not allowing me to save. Could you pls help with this?
Hello Shashank,
Below url in domain should work.
Redirect Url should be below.
Regards,
sriprasad Shivaram Bhat
Hi Sriprasad,
Thanks for your helping out.
Hello Sriprasad,
thank you very much for your blog, it was very helpful!
Do you have any suggestions regarding posting files to a Google Team Drive?
Checking for the documentation I can see that the option "teamDriveId" is available for Getting files from Drive, but we don't have the same option for the POST.
Do you know how it is possible to do it?
Thanks
Andrea
Hi
Im getting 502 error when following iflow1 via postman
Hi Sriprasad,
I need to send a CSV file from SFTP to Google drive.
If I follow this approach this works ?
Or
Should i convert the CSV file data to Form data in CPI ?
Can you suggest me a good way to do this?
Thanks
Shiva
Hi Sriprasad S Bhat
Hi Sriprasad,
Is it possible to post PDF file to GDrive?
Thanks,
Dinesh
Hi Sriprasad,
Very good post.
I have one question. If we use directly the open connectors adapter for gdrive , then why we cant use path=${property.name} . We need to give the path as hardcoded path=/homework/file1.txt
In that case if we se uopenconnectors adapter, it does not take path=${property.name} gives error