Free Create Zip File Using Power Automate Without Third Party Connector

Free Create Zip File Using Power Automate Without Third Party Connector

No comments

Loading

In this create zip file using Power Automate tutorial, we will learn how to create a zip file or download files as zip from the SharePoint Online document library. In the previous article, we learned how to extract or unzip files from the SharePoint Online document library or OneDrive.

Create a Zip File Using Power Automate: A Business Use Case

Let’s say we have many files in the SharePoint Online Document Library and we want to download files from the given path as a zip file. With the SharePoint Online document library out-of-the box feature, if we select more than one file from the document library and click on the download button from the document library ribbon menu, the file will be downloaded as a Zip file.

The same functionality can be achieved using the SharePoint Online out-of-the box REST API and Power Automate flow without using any paid premium connectors. Below, we will learn how to create a zip file or download a zip file from the SharePoint Online document library.

Download files as Zip from SharePoint Online Document Library
Download files as Zip from SharePoint Online Document Library

Let’s have a look at the above screenshot, where we have selected multiple files from the document library, and if we click on the download button, these files will be downloaded as zip files, the same functionality we will implement using the Power Automate flow.

Create Zip File Using Power Automate Without a Third Party Connector

Below is the screenshot of the Create Zip File using Power Automate flow:

Create Zip File using Power Automate
Create Zip File using Power Automate

Once the above flow gets executed, one zip file will be created inside the OneDrive, and another copy will be created inside the SharePoint Online document library. This is just a proof of concept; in reality, it should be as per your actual needs.

Create Zip File using Power Automate in OneDrive
Create Zip File using Power Automate in OneDrive

Create Zip File using Power Automate in SharePoint Online Document Library

Create Zip File using Power Automate in SharePoint Online Document Library

Note:

  • Both zip files have the same documents; they are located in the root directory of the SharePoint Online document library.

Create Zip File Using Power Automate: Complete Flow Code

Below is the scope code of the Create Zip File using Power Automate flow:


{
"id": "1d1c81de-ccf3-4b09-b1ba-dcd10032c78b",
"brandColor": "#8C3900",
"connectionReferences": {
"shared_sharepointonline_1": {
"connection": {
"id": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline/connections/shared-sharepointonl-19e53d5d-5eda-4486-b937-f79f2b27a442"
}
},
"shared_onedriveforbusiness_2": {
"connection": {
"id": "/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness/connections/shared-onedriveforbu-b1c77c61-ef17-4034-bd1b-c9307e36fcca"
}
},
"shared_sharepointonline_2": {
"connection": {
"id": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline/connections/f7fd726da76e4463bbe70d9027c66ce7"
}
}
},
"connectorDisplayName": "Control",
"icon": "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=",
"isTrigger": false,
"operationName": "Scope_|_Create_Zip_File_Using_Power_Automate",
"operationDefinition": {
"type": "Scope",
"actions": {
"Access_Token_to_Access_the_File": {
"type": "Compose",
"inputs": "@outputs('Send_and_HTTP_Request_to_SharePoint_for_File_Info')?['body']['ListSchema']['.driveAccessToken']",
"runAfter": {
"Send_and_HTTP_Request_to_SharePoint_for_File_Info": [
"Succeeded"
]
},
"description": "This collects the Access Token required to access the files.",
"metadata": {
"operationMetadataId": "e4163912-3c58-4f3e-b983-7d4661af4811"
}
},
"Select": {
"type": "Select",
"inputs": {
"from": "@body('Send_and_HTTP_Request_to_SharePoint_for_File_Info')['ListData']['Row']",
"select": {
"name": "@item()['FileLeafRef']",
"size": "@item()['SMTotalSize']",
"docId": "@{item()['.spItemUrl']}&@{outputs('Access_Token_to_Access_the_File')}",
"isFolder": "@if(equals(item()['FSObjType'], '1'), true, false)"
}
},
"runAfter": {
"Access_Token_to_Access_the_File": [
"Succeeded"
]
},
"description": "The below code formats the output of Send an HTTP request to SharePoint action ready for submission to the Zip endpoint.",
"metadata": {
"operationMetadataId": "4a8525cc-e890-42f0-8345-7aba1b35ea54"
}
},
"Attachment_Items": {
"type": "Compose",
"inputs": {
"items": "@body('Select')"
},
"runAfter": {
"Select": [
"Succeeded"
]
},
"description": "This code additionally formats the Select Array",
"metadata": {
"operationMetadataId": "1a7f1d86-b0e4-4b43-9e89-817c908ce3a8"
}
},
"Send_and_HTTP_Request_action_to_Download_as_a_Zip_File": {
"type": "OpenApiConnection",
"inputs": {
"host": {
"connectionName": "shared_sharepointonline_2",
"operationId": "HttpRequest",
"apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline"
},
"parameters": {
"dataset": "@body('Send_and_HTTP_Request_to_SharePoint_for_File_Info')['ListSchema']['.mediaBaseUrl']",
"parameters/method": "POST",
"parameters/uri": "/transform/zip?cs=@{body('Send_and_HTTP_Request_to_SharePoint_for_File_Info')['ListSchema']['.callerStack']}",
"parameters/headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"parameters/body": "ZipFileName=MyTestZipFile.zip&guid=@{guid()}&provider=spo&files=@{encodeUriComponent(outputs('Attachment_Items'))}&oAuthToken="
},
"authentication": {
"type": "Raw",
"value": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"
}
},
"runAfter": {
"Attachment_Items": [
"Succeeded"
]
},
"description": "This HTTP request action submits the request to the media server and downloads Zip file",
"metadata": {
"operationMetadataId": "a25a21c6-83fd-40ef-931d-063dcd13754a"
}
},
"Create_Zip_File_in_OneDrive_to_store_the_zip_file": {
"type": "OpenApiConnection",
"inputs": {
"host": {
"connectionName": "shared_onedriveforbusiness_2",
"operationId": "CreateFile",
"apiId": "/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness"
},
"parameters": {
"folderPath": "/Download Files from SPO as Zip",
"name": "MyTestZipFile.zip",
"body": "@base64ToBinary(body('Send_and_HTTP_Request_action_to_Download_as_a_Zip_File')['$content'])"
},
"authentication": {
"type": "Raw",
"value": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"
}
},
"runAfter": {
"Send_and_HTTP_Request_action_to_Download_as_a_Zip_File": [
"Succeeded"
]
},
"description": "This stores the received Zip file created in the previous step in OneDrive",
"runtimeConfiguration": {
"contentTransfer": {
"transferMode": "Chunked"
}
},
"metadata": {
"operationMetadataId": "76de54a6-8ef3-44e5-848c-ba4dae9d25ee"
}
},
"Settings": {
"type": "Compose",
"inputs": {
"LibraryPath": "/Shared Documents",
"ZipFolderPath": "/"
},
"runAfter": {},
"description": "Library Path and Zip Folder Path are the relative path of SharePoint Online document library and folder.",
"metadata": {
"operationMetadataId": "9d134543-2086-4c8d-b4e3-3980ada92c01"
}
},
"Send_and_HTTP_Request_to_SharePoint_for_File_Info": {
"type": "OpenApiConnection",
"inputs": {
"host": {
"connectionName": "shared_sharepointonline_1",
"operationId": "HttpRequest",
"apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline"
},
"parameters": {
"dataset": "https://yourspodomain.sharepoint.com",
"parameters/method": "POST",
"parameters/uri": "_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream?@a1=%27@{encodeUriComponent(outputs('Settings')['LibraryPath'])}%27&RootFolder=@{encodeUriComponent(concat(outputs('Settings')['LibraryPath'], outputs('Settings')['ZipFolderPath']))}",
"parameters/body": "{\"parameters\": {\"RenderOptions\": 4103}}"
},
"authentication": {
"type": "Raw",
"value": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"
}
},
"runAfter": {
"Settings": [
"Succeeded"
]
},
"description": "This action retrieves the file and folder information required to create a Zip file in SharePoint Online site.",
"metadata": {
"operationMetadataId": "66a0af92-20ec-41c6-b498-58fbdd56319b"
}
},
"Create_file_(Zip)_in_SharePoint_Online_Document_Library": {
"type": "OpenApiConnection",
"inputs": {
"host": {
"connectionName": "shared_sharepointonline_2",
"operationId": "CreateFile",
"apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline"
},
"parameters": {
"dataset": "https://yourspodomain.sharepoint.com",
"folderPath": "/Shared Documents/Download Files from SPO as Zip",
"name": "MyTestZipFile.zip",
"body": "@base64ToBinary(body('Send_and_HTTP_Request_action_to_Download_as_a_Zip_File')['$content'])"
},
"authentication": {
"type": "Raw",
"value": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"
}
},
"runAfter": {
"Create_Zip_File_in_OneDrive_to_store_the_zip_file": [
"Succeeded"
]
},
"description": "It stores the received Zip file in a SharePoint Online document library",
"runtimeConfiguration": {
"contentTransfer": {
"transferMode": "Chunked"
}
},
"metadata": {
"operationMetadataId": "58da67a4-7076-4b89-9022-f70f1f7ba219"
}
}
},
"runAfter": {},
"description": "This scope section is used to create a Zip file in Power Automate flow without the use of 3rd Party Connectors or Premium Actions.",
"metadata": {
"operationMetadataId": "5e54f081-fcf8-43e4-8c4c-c2ff0f33a50f"
}
}
}

 

How to deploy this flow code in your environment?

Just copy this flow’s entire code, go to your flow, click on the “+New Step” button, then from the choose an operation menu, click on the my clipboard, then paste the code there. Then you can see the scope action “Scope | Create Zip File Using Power Automate”, then use it, and that’s it.

Post-deployment configuration of the flow

In the settings action, there are two parameters in this flow:

  • Library Path: This is the relative path of your SharePoint Online document library.
  • Zip Folder Path: This is the relative path of your SharePoint Online document library folder for which you want to zip the files.
  • Site Address: The site address configuration is not used in the settings action; however, if you can configure it, use it in your flow. In this flow, update your site address wherever it is needed.
Settings action in Power Automate Flow
Settings action in Power Automate Flow

Note:

  • In this demo, we have used the default document library (Shared Documents) and the root folder of the document library.
  • You need to update the connection reference after configuring the site URL and OneDrive location.

Summary: Create Zip File Using Power Automate Flow

Thus, in this article, we have learned about how to create a zip file in SharePoint Online or download files from the SharePoint Online document library as zip files using the Power Automate flow-free system without using any third-party paid connectors.

See Also: Helpful Power Automate Articles

You may also like the following Power Automate articles:

 

 

About Post Author

Do you have a better solution or question on this topic? Please leave a comment