In this post, I will explain how to create a Zip file in Power Automate without the use of any third party connectors or premium actions.
Table of contents
New Zip File Creation Method Available!
I’ve developed a new, low-cost method to create Zip Files in Power Automate. The free method described in this post still works for creating Zip files for free.
Introduction
Power Automate includes functionality to extract data from Zip files. The Zip file contents can be extracted to a OneDrive or SharePoint folder:
It’s strange that there is not a matching create archive action. An idea was posted on the community forum in 2017, but it has not been added, nor received many votes. Encodian provide this function, but many people prefer not to use external connectors.
SharePoint provides this functionality through the user interface, and I wondered if this API endpoint could be accessed from directly from Power Automate.
I quickly found that it is possible to create Zip files directly from Power Automate!
The key to unlocking this functionality is in the SharePoint API action RenderListDataAsStream. I used this API action in a previous post, easy way of getting Totals from SharePoint lists. This API action can return some useful information, such as:
- The Access Token required to access the items.
- The size of each file.
- The full item URL.
- The media URL – which is used for converting and manipulating files.
By collecting this information it is possible to formulate a new request to the media conversion enpoint which can generate a Zip File.
Flow Detail
Before we get into the details, here is a screenshot of a flow which zips an entire folder:
Although not as convenient as a built-in action, this flow isn’t very complicated. At the end of the flow, the zip file is written to a SharePoint Document Library and a OneDrive folder.
Flow Code and Implementation
To implement this flow for yourself, you need to do the following:
- Copy and paste the Scope Code below into one of your own flows.
- Update the references to SharePoint and OneDrive to match your own environment.
- Change the values in the compose action called settings
- libraryPath is the path to the root of the SharePoint site.
- zipFolderPath is the relative path of the folder that you want to Zip.
- Update or delete the final storage actions appropriately for your implementation.
Scope Code:
{ "id": "b7af8f36-c669-4d9f-bb7d-bf14-63edb83a", "brandColor": "#8C3900", "connectionReferences": { "shared_onedriveforbusiness": { "connection": { "id": "/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness/connections/shared-onedriveforbu-05f1da5e-297d-4a80-8df7-cb78-b654b8a3" } }, "shared_sharepointonline": { "connection": { "id": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline/connections/de645f5680b74c47bbce762c8e2d06ac" } } }, "connectorDisplayName": "Control", "icon": "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=", "isTrigger": false, "operationName": "CreateZip", "operationDefinition": { "type": "Scope", "actions": { "accessToken": { "type": "Compose", "inputs": "@outputs('SharePointHTTP')?['body']['ListSchema']['.driveAccessToken']", "runAfter": { "SharePointHTTP": [ "Succeeded" ] }, "description": "Collects the Access Token required to access the files" }, "Select": { "type": "Select", "inputs": { "from": "@body('SharePointHTTP')['ListData']['Row']", "select": { "name": "@item()['FileLeafRef']", "size": "@item()['SMTotalSize']", "docId": "@{item()['.spItemUrl']}&@{outputs('accessToken')}", "isFolder": "@if(equals(item()['FSObjType'],'1'), true, false)" } }, "runAfter": { "accessToken": [ "Succeeded" ] }, "description": "Reformats the output of SharePoint HTTP action ready for submission to the Zip endpoint" }, "Attachment_Items": { "type": "Compose", "inputs": { "items": "@body('Select')" }, "runAfter": { "Select": [ "Succeeded" ] }, "description": "Additional formatting of the Select array" }, "downloadZip": { "type": "OpenApiConnection", "inputs": { "host": { "connectionName": "shared_sharepointonline", "operationId": "HttpRequest", "apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline" }, "parameters": { "dataset": "@body('SharePointHTTP')['ListSchema']['.mediaBaseUrl']", "parameters/method": "POST", "parameters/uri": "/transform/zip?cs=@{body('SharePointHTTP')['ListSchema']['.callerStack']}", "parameters/headers": { "Content-Type": "application/x-www-form-urlencoded" }, "parameters/body": "zipFileName=test.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": "Submits the request to the media server and downloads the Zip file" }, "StoreZip": { "type": "OpenApiConnection", "inputs": { "host": { "connectionName": "shared_onedriveforbusiness", "operationId": "CreateFile", "apiId": "/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness" }, "parameters": { "folderPath": "/__PA_Test/Filled Word Docs", "name": "testFile.zip", "body": "@base64ToBinary(body('downloadZip')['$content'])" }, "authentication": { "type": "Raw", "value": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']" } }, "runAfter": { "downloadZip": [ "Succeeded" ] }, "description": "Stores the received Zip file in OneDrive", "runtimeConfiguration": { "contentTransfer": { "transferMode": "Chunked" } } }, "settings": { "type": "Compose", "inputs": { "libraryPath": "/sites/PowerAutomateText/Shared Documents", "zipFolderPath": "/DeclarationTemplateFilled" }, "runAfter": {}, "description": "Set library path to the location of the SharePoint document library that contains the documents for compression. Set zipFolderPath to the relative path of the Folder that you want to archive." }, "SharePointHTTP": { "type": "OpenApiConnection", "inputs": { "host": { "connectionName": "shared_sharepointonline", "operationId": "HttpRequest", "apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline" }, "parameters": { "dataset": "https://accendo1.sharepoint.com/sites/PowerAutomateText", "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": "Retrieves the file and folder information required to create a Zip file" }, "Create_file": { "type": "OpenApiConnection", "inputs": { "host": { "connectionName": "shared_sharepointonline", "operationId": "CreateFile", "apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline" }, "parameters": { "dataset": "https://accendo1.sharepoint.com/sites/PowerAutomateText", "folderPath": "/Shared Documents", "name": "testWordFile.docx", "body": "@base64ToBinary(body('downloadZip')['$content'])" }, "authentication": { "type": "Raw", "value": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']" } }, "runAfter": { "StoreZip": [ "Succeeded" ] }, "description": "Stores the received Zip file in a SharePoint document library", "runtimeConfiguration": { "contentTransfer": { "transferMode": "Chunked" } } } }, "runAfter": {}, "description": "A scope to create a Zip file in Power Automate without the use of 3rd Party Connectors or Premium Actions" } }
Additional Information
This flow works by sending an array of files or folder names to the media conversion endpoint as form data. A sample array looks like this:
{ "items": [ { "name": "_rels", "size": "1168", "docId": "https://accendo1.sharepoint.com:443/_api/v2.0/drives/b!wGO-FC/items/01KW24YP...?version=Published&access_token=eyJ0eXAi...", "isFolder": true }, { "name": "docProps", "size": "2861", "docId": "https://accendo1.sharepoint.com:443/_api/v2.0/drives/b!wGO-FC/items/01KW24YP...?version=Published&access_token=eyJ0eXAi...", "isFolder": true }, { "name": "word", "size": "477746", "docId": "https://accendo1.sharepoint.com:443/_api/v2.0/drives/b!wGO-FC/items/01KW24YP...?version=Published&access_token=eyJ0eXAi...", "isFolder": true }, { "name": "[Content_Types].xml", "size": "2703", "docId": "https://accendo1.sharepoint.com:443/_api/v2.0/drives/b!wGO-FC.../items/01KW24YP...?version=Published&access_token=eyJ0eXAi...", "isFolder": false } ] }
This array is created in the Select action based on the output of the SharePointHTTP action. This example flow is designed to zip an entire folder but you might have more specific requirements.
If you want to filter this array you have a choice of two places in which to do it:
- By modifying the URI in the SharepointHTTP action to filter what it returns in the request (Examples here).
- By adding a filter array action after the Select action and then using that filter as the input for the Compose action called Attachment Items.
Filtering the Select action is the easiest option, but less efficient.
Conclusion
I’ve been looking for a way to a create Zip file in Power Automate for a while (in order to be able to modify Word documents) so it is great to get this done.
Although this solution works well, It’s clear that a native function to do this wouldn’t be much work, so please vote the idea up if you would like to see this.
Support This Website
Thank you for visiting. It’s because of readers like you that I continue to write on this blog.
If you found value in what I share, I’ve set up a ‘Buy Me a Coffee’ page as a way to show your support.
John From Ireland says
Awesome!
Riste says
Paul seems like it downloads whole SharePoint directory, not looking only in the subfolder
Greg says
Seems to be limited to 30 items per the default Rowlimit = 30. Is there a way to get around this?
Drew says
@Greg, just commenting to answer your question.
In the SharePointHTTP step, change the Body to:
{
“parameters”: {
“RenderOptions”: 4103,
“OverrideViewXml”: “1000”
}
}
Barend says
Tx for your help Drew, unfortunately I know have an issue with the Dowload_zip action. It throws the following error: ‘The template language function ‘encodeUriComponent’ was invoked with invalid parameters. The parameter at index ‘0’ cannot be converted to URI component.’. Any suggestions?
Tx in advance.
Paulie says
Hi Barend,
If you use the get in touch form, I will setup a teams session and have a look at your flow for you.
Paulie
Kiran Chauhan says
Hi Paul, I am getting following error on downloadZip step.
{
“status”: 400,
“message”: “Unexpected response from the service\r\nclientRequestId: 1059e7e2-df8f-457f-96b7-ffd7782607a2”,
“error”: {
“message”: “Unexpected response from the service”
},
“source”: “sharepointonline-wi.azconn-wi.p.azurewebsites.net”
}
Thanks in Advance!
Kiran Chauhan says
Hi Paul, Issue was with input data constructed wrongly. It is fixed now. Thanks.
Paulie says
Well done! Glad you got it working.
Daniel says
Thank you for this, really helpful!
I used an additional parameter in the Body for the SharePointHTTP to specify an exact folder of contents I want to Zip, otherwise it returns the whole Library into the Zip file:
{“parameters”: {
“RenderOptions”: 4103,
“FolderServerRelativeUrl”: “/sites/yoursharepointsite/yourlibrary/yourfolder/anotherfolder”
}
}
Paulie says
Nice one Daniel! Glad you found it useful.
Anuradha Pandrangi says
Hi Paul,
Thank you for this article which saved me lot of time.
However, it is failing at download zip file when files are over 100 MB which is limit of power automation. Is there a way i can download large size files.
What i noticed is that, when you use download functionality in SharePoint to download multiple files into zip file it is not compressing the file size. I think this is causing the issue downloading large files.
Any suggestion are very much appreciated.
Thanks,
Anu
Paulie says
Sorry, I do not know of a way to make it work for Zip files greater than 100Mb.
BeyondTheBox says
Excellent code sample!
I do have a question regarding the DownloadZip. While I see you specified a file name in the body I presume this file is not actually created but used by the transform service to properly create the zip content. Is that correct?
I plan to alter this flow slightly in that I want to be able to point it at a folder, zip the files in the folder and then remove the files from the folder leaving just the zip. Your sample will save me a lot of time so I thank you!!
BeyondTheBox says
@Daniel
I am not clear why you needed to adjust the code in the way you mentioned just above. Couldn’t you simply change the Settings action to target the specific folder and use the filter action suggested in the video skip subfolders? You presented your comment as if there is a problem flow and I just want to be sure I understand if the is or is not an actual issue.
BeyondTheBox says
@Paul & Anu
I am sure the limit is based on the max size of an actions content (compose). It is possible to ask the transform service to deliver the zip file to a specific location bypassing the need to bring all of that content into the flow? In other words, point the flow at a folder, tell the HTTP Transform service to zip the files in that folder and to also create the zip file itself.
Olli says
Hi Paulie,
thanks for sharing. this opens a lot of new possibilities.
I get an error when opening the created .docx, both on SharePoint and OneDrive. Open still works but footer and header are not copied from the template. Any idea what this could be due to?
cheers,
olli
Avik says
Hi Paulie,
Thank you for the wonderful way of creating zips.
However, I see that the file size as well as the zip size is the same.
Can you suggest some way to enable “compression” that zip file size is less than the original one.
Regards,
Avik
Paulie says
Hi Avik, I do not know of a way to enable compression. But please let me know if you find a way!
Paul
Beyond the Box says
Quite a shock to find out that this code does not compress. You might want to make note of that in the article.
Jesus Reyna says
Interestingly, I’ve tried using your provided code, and am able to obtain a zip file, but the zip file is invalid and cannot be opened, any idea why this might be?
vaishali says
I am using this. I have one main folder under that we have different subfolders and each subfolder has files. When I am converting the main folder to zip I noticed only 30 subfolders are getting created inside that/ Is this limitation or I am missing something?
Doug says
I’m sure I’m doing something stupid but I get “401 UNAUTHORIZED” error at the downloadZip point. I am using an admin account.
EM says
Hi Doug, I had the same issue
In downloadZip step, put this as site address: @body(‘SharePointHTTP’)[‘ListSchema’][‘.mediaBaseUrl’]
Gabo says
in downloadZip in body try zipFileName=test.zip&guid=@{guid()}&provider=spo&files={“items”:@{encodeUriComponent(outputs(‘AttachmentItems’))}}&oAuthToken=
Francis says
Hi Paulie, Thanks for this!
Unfortunately I haven’t been able to run the flow as the downloadZip action keeps failing.
Here is the error that I encountered:
– IIS 10.0 Detailed Error – 503.2 – Service Unavailable
– The serverRuntime@appConcurrentRequestLimit setting is being exceeded.
The action retries but it ultimately fails. Hope you can help me with this.
Tim says
@BeyondTheBox
How does one request the transform service to deliver the zip file to destination?
Amir Zareei says
Hi Paulie,
Hope you are doing well.
I’m having the same issue that Greg was experiencing. I tried using
n the SharePointHTTP step, change the Body to:
{
“parameters”: {
“RenderOptions”: 4103,
“OverrideViewXml”: “1000”
}
}
but it still doesn’t return more than 30 items
Any idea what could be the problem?
Thanks a lot
Amir
Angela Bean says
I have a OneDrive business account but do not have Sharepoint. Is there still a way to make this work?
Thanks
Paulie says
I bet there is a way. I haven’t looked myself but I can look into it for you.
Shiva says
Hi Paulie ,
InvalidTemplate. Unable to process template language expressions in action ‘downloadZip’ inputs at line ‘0’ and column ‘0’: ‘The template language function ‘uriComponent’ was invoked with invalid parameters. The parameter at index ‘0’ cannot be converted to URI component.’.
This was error I am getting could you please help me
Tanoh says
Hi Paulie,
Good Day!
I hope you’re having a great week!
Please advise what if the files are more than a 30.
It appears that the recommendation of Drew doesn’t work.
Thanks,
Tanoh
Charl says
Hi,
I’m hoping somebody still checks these comments and can help me. I get a binary file on DownloadZip, but it’s invalid. Check it in a HEX editor shows the following:
PK………A.T……….
..,…__IApplicationDocu
mentGenerator.cs_Error.t
xtThis file cannot be do
wnloaded. ….ExceptionT
ype: BadArgumentMeTAExce
ption. ….CorrelationId
: f70ce463-05a7-4791-8d5
d-63e753a276bf, ….UTC
DateTime: 7/12/2022 8:13
:57 AMPK…..”……..
Note that with different contect, I error above is always for the first file encountered.
I can’t find any information on badArgumentMeTAException, so I don’t know what I’m doing wrong. I’ve verified my version of each corresponding step in the flow against the example code here, and can’t spot any difference.
Any thoughts on what I can try or where to look for answers?
Kind regards,
Charl Marais
Charl says
Hi,
Found my mistake. I went over all the flow steps again to compare and found that I missed the ‘&’ before the access token on the Select step.
Thanks for this flow Paulie!
Kind regards,
Charl Marais
Bene says
Hi,
i got the following Problem:
Template language expressions in the inputs of the “SharePointHTTP” action in row “0” and column “0” cannot be processed: The template language expression “uriHost(encodeUriComponent(concat(outputs(‘settings’)[‘libraryPath’], outputs(‘settings’)[‘libraryPath’]))” cannot be evaluated because the “libraryPath” property cannot be selected. Array elements can only be selected with an integer index. For more information on usage, see
I connected every Step as you Mention, can you help me
Kind Regards
Ben
Pat says
Hi,
So, this can’t be achieved if the source files are in Onedrive?
Regards,
Pat
Manuela Carreño says
Hi!! I tried out this solution but it creates a Zip file with all the documents of the shared documents folder, what could I do?
Graham says
Great work
Graham says
Restricted to 30 files – no more!
The issue is the Item Limit of the default view – change this to 5000. This may have performance issues on the site.
This gives rise to another issue, after around 46 files in my case, the string becomes too long for the encodeUriComponent function. Split up that into chunks of 1024 characters, encode each of those then join back with an empty string:
Select Encode attachments as chunks
From: @chunk(string(outputs(‘Attachment_Items’)),1024)
Map: @encodeUriComponent(item())
Then in the downloadZip in the Body, after the files= instead of the @encodeUriComponent(outputs(‘Attachment_Items’)), use @join(body(‘Select_Encode_attachments_as_chunks’),”)
Paulie says
Great find Graham, I will check that out and update the post.
Jasper says
Hi Graham,
I followed your steps, but I keep getting ‘Unexpected response from the service’ in the downloadZip action. Any clues?
Graham says
Jasper
Offhand I would think the request is malformed somewhere.
Can you post the Body of downloadZip (from the designer) – there may be a clue there
Moe says
Is there a way to create a repeating table in word xml by using this methos
John says
Thanks for all your help with this, Paulie
My replace functions replaces commented sections in my document.xml in order to display a table or not from:
to
The xml works fine when I do the replacing manually, but somehow gets corrupted when I run the flow.
Any ideas?
The error I receive when trying to open the word document is:
“Word found unreadable content in testWordFile.docx. Do you want to recover…” -> Yes
“Word experienced an error trying to open the file.
Try these suggestions.
* Check the file permissions for the document or drive
*Make sure…
*Open the file with the Text Recovery converter(testWordFile.zip)”
John says
Found a partial solution:
Seems like when uploading the template to Sharepoint, some folders were unpopulated when doing so. Likewise when copying the template and renaming it to “Output”.
I filled in the missing files, and I could then open the document.
However, the document must be downloaded onto oyour computer if you want to “open in app”. I am able to open it in the browser, but the formats are completely off.
Thanks again, Paulie.
Jasper says
Hi Graham,
Apologies for the late reply.
This is my body in the downloadZip:
zipFileName=test.zip&guid=@{guid()}&provider=spo&files=@{join(body(‘Select_Encode_attachments_as_chunks’),”)}&oAuthToken=
graham lattin says
Jasper – sorry its taken me so long to see your reply.
It looks identical to mine. The only thing that looks different – and that might be the web page encoding – is the join:
join(body(‘Select_Encode_attachments_as_chunks’),”)
The quotes should be the same type of quote as those surrounding the action in the body call.
If these are correct in yours, then maybe there is an issue in the Select_Encode)attachments_as_chunks ?
Jan says
hello Johny is there,
Fist Thanks for this topic !
I try figure out because its all time grab whole folders from the root(libraryPath) , its like pathToZip is not working.
have you ideas what can be wrong ?
Jan says
hello, my mistake i replace by accident in variable library string /sites/…
Thank you
Paulie Thanks for thi awesome topic !
Rich Watkins says
Thank you for this! I got working with just a few small tweaks.
Joel says
Hi,
Thanks, this is great.
I’m trying to use it to zip an index.html file and then use the adobe connector to convert a static html to pdf. It requires a zip file. I’m using power automate to convert rich text and other text to build a template html file and create an index.html in sharepoint/onedrive. That all works fine. I was using onedrive’s connector to create a pdf, but it doesn’t always work well with the rich text. So I’m trying to upload this file and then download the zip file and then plug it into the adobe connector using their free api access. The connector works, if I download the index.html and compress it and then upload it, the connector works fine. But if I use your steps and I create the zip file that contains the index.html it makes the zip file just fine but the adobe connect failed and I get a bad gateway. Which doesn’t make much sense. The zip file looks ok. The content string looks different, when I check it, it doesn’t have the breaks in it that my created file has and it displays differently. I’m not sure if that’s an issue or not.
Any advice?
Joe says
Thanks for this and all of your other amazing content!
I am seeing the same “Bad Gateway” issue when trying to use a zip generated from this method with the Adobe connector (Convert Static HTML to PDF). If I create the zip manually (using 7-zip), no issues with Adobe.
Any thoughts?
Thanks!
Graham says
You should note that the zip functionality does not compress the file, it is included as is – while being a valid zip format. I suspect this is why you see a difference between this and a manually generated file using 7-zip.
shelly says
Hello, not sure if this will be helpful to anyone or if it is for sure the case, but it seems that if a user places an “&” in any of the replacement text fields it is causing the created file to not be able to open. When I replace the ampersand with “and” my file can then open just fine. Maybe I made a mistake somewhere in my coding that has lead to this and if anyone knows please let me know, but for those that are having the issue with opening, maybe its a special character of some sort giving you the problem.
shelly says
I finished checking the special characters and in the end the 3 that would corrupt my file are:&,. I just ran the test for the with both of them listed, so maybe one or the other is doing it but I’ll just avoid using both, but none of the others seemed to bother the file ( / \ [] {} # % * ? @ + ‘ | )
shelly says
Cont of the above, the other 2 special characters were removed when I posted, they are the left angle bracket and right angle bracket
Bernard McNamee says
Thank you – works a treat!
J.M. says
Good Day All!
I found this video in an attempt to dynamically populate documents from a SharePoint list. I have been having a sever amount of trouble even getting past the SharePointHTTP action. I always get the below error; I’ve checked the path and it is pointing to a folder that I know exists. Can anyone help troubleshoot?
V/r
Gopi says
Hi Pauli,
After I compress the files. It is showing Ratio as 0% for both the files and Compressed size and Size are same.
How to fix this one?
Thanks,
Gopi
graham lattin says
Hi Gopi
There is no ‘fix’, thats how it works, it literally assembles the files in a zip container and does no compression.
As Paulie states earlier in the comments, if you find out how to enable compression, let him know.
Graham
Josh says
Good Morning,
I have built this flow as specified but when i get to the downloadZip connector it gives me a 401 Unauthorized error and states that the Access Token was not found. I am passing the the token provided from the previous step and its seemingly not seeing it. Has anyone experienced this and have they found a fix?
Chuck says
For posterity, the /transform endpoint is no longer hosted by your SharePoint web application. This is why you get a 401, as there is no longer an API endpoint available to you there.
You can still access it and request it via the same connector, but you’ll need to discover a valid host URI for your tenant. Use your browser’s Dev Tools to uncover the domain it’s hosted under by manually downloading a folder/files in SharePoint and taking note of the request to the /zip URL. Replace the site collection URI in the flow action with the new URI and you should be good to go.
Note, this is unsupported and that host domain could change at any time for any reason.
Sagar M says
Everything is working fine as explained, but the only issue is that it is limited to 30 items per the default Rowlimit = 30. Is there a way to get all records from a folder?
In the SharePointHTTP step, I changed the Body to {“parameters”: {“RenderOptions”: 4103,”OverrideViewXml”: “1000”}}, but it’s also not working.
Can someone please help me to resolve this?
graham says
See my post of 12 Oct 22 – it is dependent on the Item Limit of the default view – default value is 30, change it to a larger figure
Graham
Sagar M says
I have tried increasing the limit and it works until 45 files only. When I set the limit to higher than 45, it gives me errors like
InvalidTemplate. Unable to process template language expressions in action ‘downloadZip_2’ inputs at line ‘0’ and column ‘0’: ‘The template language function ‘encodeUriComponent’ was invoked with invalid parameters. The parameter at index ‘0’ cannot be converted to URI component.’
graham says
Sagar
That is most likely because there are now too many files to process, to solve it, chunk it up as I suggested:
Split up that into chunks of 1024 characters, encode each of those then join back with an empty string:
Select Encode attachments as chunks
From: @chunk(string(outputs(‘Attachment_Items’)),1024)
Map: @encodeUriComponent(item())
Then in the downloadZip in the Body, after the files= instead of the @encodeUriComponent(outputs(‘Attachment_Items’)), use @join(body(‘Select_Encode_attachments_as_chunks’),”)
Sagar M says
Hi Graham,
Thank you for your quick response.
But I am unable to get where and how should I use this,
Select Encode attachments as chunks
From: @chunk(string(outputs(‘Attachment_Items’)),1024)
Map: @encodeUriComponent(item())
Can you please help me to explain this process in details
graham says
Sagar
Yes, simple – insert a Select action after Attachment Items action, name it
Select Encode attachments as chunks
In the From, paste in the formula
chunk(string(outputs(‘Attachment_Items’)),1024)
then in the map, insert this function in the first cell
encodeUriComponent(item())
then click the little icon next to the map its either a [T] or something that looks like a twisted rope.
This gives you a view of the JSON object for the map, delete everything except the expression you put in:
That is
{
“[YourExpression]”:””,
“”:””
}
to
[YourExpression]
Now in the body of the downloadZip action, after files=, delete the expression and substitute this one
join(body(‘Select_Encode_attachments_as_chunks’),”), so it looks like this
zipFileName=test.zip&guid=@{guid()}&provider=spo&files=@{join(body(‘Encode_attachments_as_chunks’),”)}&oAuthToken=
Good luck!
beyondthebox says
I am not sure the effort to use this zip process is worth it given that the zip file is not compressed.
Sure it will let you combine many files into one….but its just as easy to have multiple attachments.
has anything changed?
Paulie says
It’s still not compressed and for many it isn’t the right tool to use. However it is immensely useful for creating Word files dynamically without using premium actions.
Max PowerAuto says
Great post and thanks much for the workaround solution. I can’t believe MSFT hasn’t added an action to zip out of the box yet. This is such as common scenario and would be nice if it’s supported OTB.
I’ve used this solution to zip CSV files. Unfortunately, the zip file operation strips the “CR” (carriage return) from the input/original files. I can’t figure out how to add it back in. Do you have an idea how to fix this?
thanks!
Paulie says
I don’t know why it would do that, one option would be to change the file extension of the CSV files so it does not infer the content type. But I am not sure it would do that anyway. Strange.
Max PowerAuto says
Hi Paulie
I figured out the issue and it was caused by my own mistake. Sorry for the false alarm and sorry to muddy up the comments with this. Feel free to delete them if you want. Appreciate the work you did! Keep up the good work.
Roman says
Hi,
Thank you for this solution, It saved my day.
I was also searching for your video on modifying Word Documents. I’m sure that I have seen it a while ago, but can’t find it now. Though I have figured it out myself, of course using code from this article, I still wonder if you had used any different approaches in the original video.
Ben says
Hi all,
I’m struggling with the 30 item limt, could anyone confirm where I need to update the the Item Limit of the default view?
Many thanks,
Ben
graham says
Hi Ben
Simple – edit the default view
scroll to the bottom, second from bottom is the item limit section, change the value in the box; save the view and you are ready
Graham
Ben says
Ahhh on Sharepoint!
Thank you Graham – I’d been pulling my hair out trying to find the setting on PA.
Ben says
Getting there, but having a ” “statusCode”: 400″ at the downloadZip stage.
I’ve added in Encode and Chunks and updated the downloadzip code, but no joy.
Any ideas?
graham says
Ben
Looking back through the posts a couple of years ago, someone had the same issue and it turned out they had malformed the request in the download zip action.
I can only suggest you compare Paulies original with the changes I suggested and ensure all is accurate.
Good luck
Adrian says
I tried this to zip an HTML file in SharePoint the I used this in Convert static HTML to PDF connector in Power Automate. It cannot process the generating of PDF. What seems to be missing in the solution provided in zipping a file in SharePoint?
Thanks,
Adrian
Neale Bassford says
I have used this scope successfully. (Really useful bit of code by the way! )
I have copied the scope to another SharePoint environment that I am working with. Exactly the same flow just connected to different locations in sahrepoint etc but when it runs I get the following error :-
InvalidTemplate. Unable to process template language expressions in action ‘downloadZip’ inputs at line ‘0’ and column ‘0’: ‘The template language function ‘encodeUriComponent’ was invoked with invalid parameters. The parameter at index ‘0’ cannot be converted to URI component.’.
The encodeUriComponent expression is the same as my working version ?
encodeUriComponent(outputs(‘Attachment_Items’))
Nothing else has been changed… any suggestions as to why this happens and a resolution ?
Paulie says
I would check the outputs of outputs(‘Attachment_Items’) and see what that is producing. My blog is being attacked by bots at the moment so quite hard to respond!
Steven Rae says
Thank you for creating this functionality.
I have got the flow working however when I try to open the word file I get an error message saying the file is corrupted. Any ideas why this might be the case and how I could rectify it?
Thanks
Steven Rae says
I think I solved it, if anyone is having the same issue – I noticed it was zipping all the contents of the document library I was using, despite specifying the folder in the “settings” action of the “CreateZip” scope.
I followed the steps Daniel posted November 3, 2021 and its working now!
Thank you Paulie and Daniel!
Navneet says
When I Copy this code to my clipboard , flow is not able to detect Scope Action. Does anybody has face the same probelm? Can anybody share the flow with me as a package
graham lattin says
Hi Navneet
I havent seen this problem – when you copy this to your clipboard, you should Add an action, select from clipboard, then press Control-V to paste the saved actions into the selection pane, you can then select the scope to add to your flow
Harjot Singh Bagga says
I am getting the following error on ‘downloadZIP’ step.
According to the error, my files size should not exceed 104MB, but upon checking I found that the file size was mere 38MB, keeping in eye on the limit.
@Paulie or anyone who faced similar issue, if you could help me with this, it would be hepful.
Thanks in advanced.
Http request failed as there is an error: ‘Cannot write more bytes to the buffer than the configured maximum buffer size: 104857600.’.
And great work @Paulie, a really helpful piece of code.
Alex Wilkins says
Thanks for this, is there anyway to add a password to the archive?
Timo Migchielsen says
Please edit the form to allow more than 100 MB in files by using chunks or something like that. We would all really appreciate it!
Vega says
Hi Paulie,
Thx for this solution. It works perfectly. However, I would like to join Alex Wilkins’ question: how could I create a password protected zip file? Is there a way to complement your code with this option?
Paulie says
There is not. It’s a very basic solution – you would need to use a 3rd party connector.
Engin says
Hi Paul,
thank you for this tutorial. I have a problem with more than 1 outputs. How can i handle this in the flow?
Yasir says
I’m getting this error when running the flow, please help, I have done everything as in the video.
File Not Found.
clientRequestId: d88290e2-41ec-4157-b3f4-f72afdc808de
serviceRequestId: 667d16a1-f0fb-8000-50e5-f442ed2762f0
File not found error.
JohnPe says
Joining the doubt already mentioned above. Would it be possible to generate the zip file with a password?
Paulie says
Impossible with this method, but I will be shortly releasing another method which makes this possible
Chris says
“Impossible with this method, but I will be shortly releasing another method which makes this possible” Any updates ?
Billy-Ray says
Hi Paulie,
Thanks for this article – although I seem to be stumbling at the first step, I get a 401 unauthorised at the SharepointHTTP point.
{“error_description”:”Exception of type ‘Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException’ was thrown.”}
clientRequestId: 2073dd92-cb36-48e3-96e5-cc7e46692789
serviceRequestId: b7cd1ba1-90b4-8000-63c1-c5283ff1384b
I’ve added my connectors and made sure the folder paths in settings point are correct.
Any ideas?
Metti says
Great article. I am looking forward for the updated approach where passwords can be setup on the zip file.
Chris says
For those struggling with the 30 item limit, this worked for me:
Replace the body in the SharePointHTTP api request with the following
{“parameters”: {“RenderOptions”: 4103, “OverrideViewXml”: “3000”}}
Nick says
I need to zip up 200 PDF files, and of course, It’s over the 100MB limit by 4 MB. I did the chunk thing but now I get the following error:
‘Cannot write more bytes to the buffer than the configured maximum buffer size: 104857600.’
Any way around this? My other thought is to divide the items by 4 or something and build 4 different Zip files.
sean says
I’m seeing this error on the code and wondering if anyone else has seen it before/has been able to correct this?
InvalidTemplate. Unable to process template language expressions in action ‘accessToken’ inputs at line ‘0’ and column ‘0’: ‘The template language expression ‘outputs(‘SharePointHTTP’)?[‘body’][‘ListSchema’][‘.driveAccessToken’]’ cannot be evaluated because property ‘ListSchema’ cannot be selected. Property selection is not supported on values of type ‘String’. Please see https://aka.ms/logicexpressions for usage details.’.
Sean Hodkinson says
Hi Paulie,
thanks for this great flow. I am getting an error when the sharepoint folder has an apostrophe in the name.
I get a “The query string “DecodedUrl” is missing or invalid.” error on the Uri generated in the SharePoint HTTP action.
I have tried all sorts of combinations of %2527 and %27 and %22 but to no avail. Can you advise a workaround.
Thanks a million,
Seán
Emile Tongunga says
I am able to generate the Zip file.
For some reasons, the files in the zip file are text files (extension is .txt) and the content of each file contains something like:
This file cannot be downloaded.
ExceptionType: BadArgumentMeTAException.
CorrelationId: a09cc7f0-8eb9-4f57-9d99-58d84327a1c0,
UTC DateTime: 06/06/2024 04:10:30
Any idea?
Emile Tongunga says
Actually, I found the culprit to issue from earlier. The post from JULY 15, 2022 AT 9:43 AM above helped.
Nick says
RE my post on MAY 20, 2024 AT 4:26 PM about large zip files. I ended up writing a loop that would split up the files into the max allowed size that System File can process and then use Chunk to break up the file packages and the Append to file to build larger zip files if needed. It takes about 6 minutes to copy 220 files down instead of the 10-15. So it’s a bit faster. If I ignore all the files size checks or know that my files are always going to be a set size, the options above only takes a few seconds which is great!
When I get some time, I will post my solution to the file sorting here.
https://powerusers.microsoft.com/t5/Building-Flows/Group-Files-so-Total-Size-is-less-than-30-mb/td-p/2778032
Paulie says
Hi Everyone,
I have created a new method for creating Zip files in Power Automate which supports compression.
Please check it out here:
http://tachytelic.net/2024/06/create-zip-file-power-automate/
Alberto says
Hello Paulie
Thanks for your work.
When the flow is executed, in the DownloadZip step I get a GatewayTimeout and the flow stops.
Would you know what is causing the error?
Thank you very much.
Michelle Ho says
This is great! Thank you. I’ve used this successfully in the past but am getting an error now: “Access token not found”. Do you know what could be causing this?
Paulie says
I do not know, I haven’t looked at it since I wrote the post. Have you seen my new method?
Michelle Ho says
I have, but am unable to use a premium connection.
Philippe C. says
Hello,
I’m sorry to disturb you, but I have a problem with the “DownloadZip” step.
This step only worked once.
And now I have this message “Unexpected response from the service
clientRequestId: 3d2cxxxx-9999-9999-9999-xxxxxxxxa24d”
Have you got a explanation ?
Thank you for your help.
Philippe
Paulie says
I do not have an explanation- it’s not an ideal solution. I would consider using my Zip component instead.
EAB says
Hello, can anybody test this? Since a few days ago is not working on my side…
Dockey says
Hello,
“error”: {
“message”: “SharePoint Site Address ‘https://westeurope1-mediap.svc.ms/’ is not valid”
}
Since a few days ago is not working on my side too…
Paulie says
I will look into it, in the mean time, this is a much better solution for creating Zip files.
Dockey says
I analyzed the problem, I found that even if I copy the POST elements of the original sharepoint download into the downloadZIP block, the error remains the same.
I think microsoft has eliminated this workaround to allow API requests to technical addresses in the “Send an HTTP request to SharePoint” block.
(Example: https://contoso.sharepoint.com/sites/sitename)
Not the ZIP compressor price is the problem, if it would be enough to buy one copy, but premium Power Automate subscription for 500 person is a serious cost.
Help says
I also have the sharepoint site address not valid issue, can some please help?Very urgent