Mulesoft & Google Drive integration
Francesco Suraci
? Presales Senior Specialist Solution Engineer - 1st and only Italian to write for the Mulesoft Official Blog ?
About Google Drive connector
Google Drive is a file storage and synchronization service created by Google. It allows users to store files in the cloud, share files, and edit documents, spreadsheets, and presentations with collaborators.
The Anypoint connector for Google Drive enables you to simplify repetitive tasks by automating how you convert, sync and share folders and files across all of your cloud storage services. Now you can automate file processing, transfers and sharing, ranging from very simple tasks to the most complex and challenging workflows.
Associated Use Cases
Automate common business operations by integrating Google Drive with other business applications such as CRM, ERP, DocuSign, and so on. Possibilities include:
url : https://docs.mulesoft.com/google-drive-connector/1.0/
Prerequisites
Scenario
In this scenario we will see how to configure and use Mulesoft's Google Drive connector to upload and create a file in Google Drive.
Anypoint Studio
This is the connector that you need to include in your project:
And this is the project:
First of all,there is a Listener /gdrive/{op}/{type} that is our endpoint.
Then a check is performed on the uri paramer 'op':
- if it is 'upload', then the flow continues to create and upload the file to Google Drive
- if it is 'delete', then it will follow the steps to delete the file from Google Drive.
- in other cases it will do nothing.
UPLOAD case:
it is important to pass in the body of the request the content of the information that will then be written into the file.
For example:
<? xml version = "1.0"?
<Item PartNumber = "872-AA">
????<ProductName> Lawnmower </ProductName>
????<Quantity> 1 </Quantity>
????<USPrice> 148.95 </USPrice>
????<Comment> Confirm this is electric </Comment>
</Item>>
the file format is specified in the uri parameter 'type'.
Example: type = ' xml' and it will be transformed in 'application/xml' by the Transform Message component.
And Response is:
Postman Request example:
Postman Response example:
DELETE case:
here in the body of the request you pass the id of the file you want to delete from Google Drive.
For example:
{
"fileID": "1eyQLniqcW88S_mhaP4CbFraHruufcgHv"
}
Postman Request example:
Postman Response example:
Google Drive
Google Drive before upload:
Google Drive after upload:
Please,notify that the 'Untitled' name for file just uploaded depends not on Mulesoft but on the Google Drive API (https://developers.google.com/drive/api/guides/create-file).
When creating a file, these are the properties associated with it:
The file is given a kind of drive.file, an id, a name of "Untitled," and a mimeType of application / octet-stream
Documents
project (jar) :
https://drive.google.com/file/d/1bDSM3mHr25Yb569VXyPmAjaYtQYlMxsC/view?usp=sharing
Postman collection:
https://drive.google.com/file/d/1_7zoaOmzxOZj-S9alDr00AQmQG3tJ1i0/view?usp=sharing
I did it without using MULESOFT ?? https://www.dhirubhai.net/posts/sherbazkhan148_share-linkedinfam-linkedin-activity-6958289005087973376-R3T7?utm_source=linkedin_share&utm_medium=android_app But will surely learn about Mulesoft as I've heard a lot of great things about it.