Google DRIVE API - Upload a Microsoft Excel file to Google DRIVE and convert to a Google Sheet

Andrew_239256
Andrew_239256 Posts: 16 admin
edited January 12 in API Actions

The following guide utilizes the Google DRIVE API to upload a Microsoft Excel file to Google DRIVE and convert it to a Google Sheet.

While native actions in Catalytic allow builders to interact with Google DRIVE in several ways, builders can further leverage the standard Google DRIVE integration using the existing GET, POST, PUT, PATCH, and DELETE API actions to access a broader set of endpoints within the Google DRIVE API library.

With Catalytic managing API authentication, this functionality allows builders a quick and simple way of extending Catalytic’s Google DRIVE integration to accomplish custom Google DRIVE actions within a workflow.

To get started, please follow the instructions below:

Step 1: Set up Google DRIVE integration

Note: If a Google DRIVE integration has already been set up, move to step 2.

For detailed instructions on how to set up a Google DRIVE integration, reference the following help article within the Catalytic knowledgebase:
https://help.catalytic.com/docs/google-drive-integration-setup-guide/

Step 2: Configure Instance Fields

Create one new Instance Field for reference within the workflow.
Field name: Excel File
Type: File
Default value:

Step 3: Configure Catalytic action to upload an Excel spreadsheet to Google DRIVE

In a new or existing workflow, add a new action of type ‘Web API: Send POST Request’. Configure as follows:

Integration:
API endpoint:
https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart

Headers:
Content-Type: multipart/related; boundary=foo_bar_baz

Request body:

--foo_bar_baz
Content-Type: application/json; charset=UTF-8

{
 "name": "Sample Sheet.xlsx",
  "parents":["Add Parent ID Here - Only if file should go in specific folder"],
'mimeType': 'application/vnd.google-apps.spreadsheet'
}
--foo_bar_baz
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Content-Transfer-Encoding: base64

{{excel-file}}
--foo_bar_baz--

Note: name is the new file name displayed in Google DRIVE after the file is uploaded. Replace 'Sample Sheet.xlsx' with a file name of your choice.

*IMPORTANT: The file must be sent to Google encoded as a base64 file. Change 'File encoding format' in the POST API options to 'Base64'. Screen shot below:

Full customization of the request body is beyond the scope of this guide. For more information about uploading files to Google DRIVE, please reference the Google DRIVE API documentation:
https://developers.google.com/drive/api/v3/manage-uploads

Step 4: Test your workflow

By clicking on the test button, the selected Excel file will be uploaded to Google DRIVE and converted into a Google Sheet.

Please reference the sample workflow attached for testing purposes. To customize for your building needs, update the spreadsheet ID and sheet name.