Adding multiple attachments to an approval flow in Power Automate is a common requirement. The method is slightly different between the Create an Approval action and the Send an email(V2) action. I will demonstrate both methods in one flow, using a SharePoint list as an example:
First, create the trigger action and initialize two array variables. There are separate arrays for the email action and the approval action:
Next, use the Get attachments action and provide the same site and list address as before. Use the ID from the trigger action.
Now use the Get attachment Content action and again supply the site and list name. For the ID field use the ID from When an Item is created. Finally, for the File identifier, use the Id from the Get attachments step:
This action will now change to be inside an Apply to Each action.
Fill the arrays with the attachment content
The next step is to populate the arrays with the contents of the attachments. Use the append to Append to array variable action. Here is how to build the approvals attachment array.
The code for the approval attachment array is:
{ "content": { "$content-type": "@{body('Get_attachment_content')['$content-type']}", "$content": "@{body('Get_attachment_content')['$content']}" }, "Name": "@{items('Build_Attachment_array')?['DisplayName']}" }
Now populate the email attachment array:
The code for the email attachment array is:
{ "ContentBytes": { "$content-type": "@{body('Get_attachment_content')['$content-type']}", "$content": "@{body('Get_attachment_content')['$content']}" }, "Name": "@{items('Build_attachment_array')?['DisplayName']}" }
Notice how the required code is slightly different on line two.
Use the arrays as the attachment content
Now you can simply insert these arrays into the “Create an Approval” or “Send an email(V2)” actions.
Here is an image of my entire flow that shows how to send multiple attachments in approvals in a flow from a SharePoint list (click to expand).
Corrupt attachments
Slightly different solutions to this problem have been discussed in the Power Automate forums but for me, they resulted in corrupted attachments. Adding the correct content type for each of the file attachments fixes the corruption.
I also found that sometimes the file size would increase dramatically.
I’d like to understand why the different array format works for some people and generates corrupt attachments for others.
Jenna R. says
I’ve been struggling for weeks to get SP list item attachments to successfully attach to a power automate approvals flow email notification. I kept creeping closer and closer via other blog posts and forum threads, but still ran into the corrupted file issue. This post was the final piece of the puzzle by adding the content-type component to the appended array. THANK YOU — my entire household celebrated with me (I think my vocal frustrations had been bleeding into others’ work and learn from home experiences). Thanks again!
Paulie says
Thanks for your comment – appreciated as I also spent a long time figuring this out (even though the solution is quite simple) and got very frustrated to the point of almost giving up. Other solutions I’ve seen were on the right scent but didn’t provide a working solution.
Harry Teguh says
Wow! Your solution works great! I’ve been tearing up my hair for days just to solve this issue. Thank you!
Paulie says
Welcome to the hair loss club! I experienced the same and exactly the reason I wrote it up!
Silvia says
Thank you so much! I was going crazy with this!!
Gillian Eastwood says
I followed your instructions to a tee….. and I am getting “Flow save failed with code ‘InvalidTemplate’ and message ‘The template validation failed: ‘The reprtition actions(s) ‘Build_attachment_array referenced by ‘inputs’ in action ‘Append to array variable’ are not defined in the template”.
I have literally spend probably 40 hours trying to figure this out….so any help would be GREALT appreciated 🙂
Dan says
YEAH!!! Thanks for the detailed guide.
Premalatha says
@Gillian Eastwood Im getting the same error. Got any resolution?
Premalatha says
Got resolved finally after spending around 40 hours in dealing with corrupted attachments—
Now. Append Array code looks like :
{
“inputs”: {
“name”: “AttachmentArray”,
“value”: {
“name”: “@items(‘Apply_to_each’)?[‘DisplayName’]”,
“content”: “@body(‘Get_attachment_content’)?[‘body’]”
}
}
}
Chris says
I followed this exactly for approvals and the attachment arrives with the approval but it is corrupt and can’t be opened. Same as every other method.
Paulie says
Chris, would love to do a quick remote session with you to have a look at why it’s not working for you. Let me know if you’re up for it
Chris says
I’m the same “Chris” from December 22nd – Not sure what I screwed up the first time around but I can confirm that this does work for approvals (I spent almost 8 hours trying to figure this out before finding this blog). What I think I was doing wrong, when I thought this didn’t work, was saving and “Testing” it using old Flow runs over and over and each would fail. When I tried adding a new item to my SharePoint test list, it worked.
Paulie says
Glad you got it sorted and it worked for you. One lady that arrived here had literally spent 20 hours!
Farhaan says
This has been a great help – Thank you Paulie! – Can i add one more complexity? What if i wanted to build a name for each file in the array?
e.g.
for each file
– uses the InvoiceNo. field from the list
– uses the vendorname field from the list
– adds a _n at the end of the file – starting with 1 for the first file
e.g. of file name built
5555_XYZ_1
5555_XYZ_2
would i have have to append the file extension at the end of the built file name?
any help is appreciated!
Thanks
Bron says
I am stuck on the same approval error as Gillian.
Gillian Eastwood says
December 4, 2020 at 6:05 am
I followed your instructions to a tee….. and I am getting “Flow save failed with code ‘InvalidTemplate’ and message ‘The template validation failed: ‘The reprtition actions(s) ‘Build_attachment_array referenced by ‘inputs’ in action ‘Append to array variable’ are not defined in the template”.
I tried this (below) but i am getting an invalid JSON error. Can anyone help?
{
“inputs”: {
“name”: “AttachmentArray”,
“value”: {
“name”: “@items(‘Apply_to_each’)?[‘DisplayName’]”,
“content”: “@body(‘Get_attachment_content’)?[‘body’]”
}
}
}
Paulie says
I believe it is because you are using @items(‘Apply_to_each’) when the each loop I created was called Build Attachment array, which would mean your code would need to be @items(‘Build_Attachment_array’)
Bron says
that is exactly what I was doing. thanks
yannis belouris says
thanks for the tip! Suddenly I started getting problems. I only changed the Build_Attachment_array to my apply_to_each loop.
{
“content”: {
“$content-type”: “@{body(‘Get_attachment_content’)[‘$content-type’]}”,
“$content”: “@{body(‘Get_attachment_content’)[‘$content’]}”
},
“Name”: “@{items(‘Build_Attachment_array’)?[‘DisplayName’]}”
}
David McMurtry says
Thanks so much! I have burned so much time with this issue until I found this post.
Antonio Barros says
My Man, you are a star !!!!!!!!! I was struggling with that for 2 days in a raw, I read so many articles that got to a point I was even correcting how badly other bloggers, stckflow and youtubers,etc.. wrote the content type or content syntex. Thank you so very much, you are a star.
Manuel says
HI, thank you very much for this solution.
I’m struggling, however, because attachments doesn’t show up in TEAMS APPROVALS app (it works ok with power automate, actions, approvals)… do you know how can I have the attachments available in the approval request in TEAMS app?
Thanks in advance!
Manuel Moreno
jaina says
hi tried this, but when I run the flow with multiple attachments, the number of attachments is same number approval notification i received.
i followed step by step and successfully run the flow but the expectation is that 1 approval notification only with multiple attached files..
jaina says
Ohhhh looks like it worked already!!!
I just created new item with multiple attachments to capture the new update in my workflow via PowerAutomate
Paulie says
Well done Jains!
jaina says
I just tried again, I tried to attached 2 sample files, and when the flow runs, approval routes 3 times? First approval has 1 attachments, same with the second approval email, and the last has 2 attachments???
Can you help why? I haven’t encountered error in my flows.
Paulie says
I can help you. (It’s because you’re using an apply to each loop). Use the get in touch form on the site.
jaina says
Hi @Paulie I’ve already figured this out.
Big thanks to this blog! More powers!
Omolola Alfred says
Hello @Paulie I tried using the approval attachment array code but I keep getting
Flow save failed with code ‘InvalidTemplate’ and message ‘The template validation failed: ‘The repetition action(s) ‘Build_Attachment_array’ referenced by ‘inputs’ in action ‘Append_to_array_variable’ are not defined in the template.’.’.
please Help
Omolola Alfred says
hello @ paulie, yannis belouris and everyone! i have solve this error, i am so excited, i have been trying to add attachment to approval for so long.
This is how I solved it
{
“content”: {
“$content-type”: “@{body(‘Get_attachment_content’)[‘$content-type’]}”,
“$content”: “@{body(‘Get_attachment_content’)[‘$content’]}”
},
“Name”: “@{items(‘Apply_to_each’)?[‘DisplayName’]}””
}
Syed Rizwan Raza Rizvi says
How about getting the files from a document library rather than a list?
Can someone please share code and process for that?
Paulie says
I don’t think it would make any difference, did you try it?
ImkeF says
Just a quick heads if it’s not working for you with this method: Your flow might be corrupt.
At least this was the case for me. After hours of searching and trial and error I just set up a new flow, rebuilt everything from my previous flow and then it worked with this method.
tonia says
Any idea why it would work most of the time, but for some users, even though they have attachments saved on the list and there are no flow errors, the approval emails arrive with no attachments?
Tonie says
Hi, my Attachment Array throws the following error when I populate the value field as you suggest:
The template validation failed: ‘The repetition action(s) ‘Build_Attachment_array’ referenced by ‘inputs’ in action ‘Append_to_Approval_Attachment_Array’ are not defined in the template.’.
Thanks.
Tonie says
To my earlier question . . . it is that the Apply to each are not shown in the article so one cannot see that they are named Build Attachment Array. Mine are named Apply to each. So just make sure you use the actual name of your apply to each container, whatever that is.
Irfan Nasruddin says
Hello everyone, I managed to solve the “Invalid Template” error message that appears when you try to save the flow.
You just need to move your “Append to array variables” actions into your “Apply to each” action. You should be able to save your flow once you have done this.
CORY TAYLOR says
Like so may others here, I found you after many hours of trying to figure this out, and you nailed it! I also had the template error issue, but it was due to the naming of the “Build Attachment array” that you also solved!
Kudos to you my man!
ej says
Hi it looks great and I tried to rebuild it – many thanks for that – however i do exactly as you shown, but the approval attachment does not show up in teams (also does not give an error). Does it still work for you?
Sergey says
Hi!
in SMTP connector,
error occurrit :
Input parametrs (“inputs.parametrs”) workflow operationes “Send email(version 3)” de “OpenApiConnection” type non licet. Error information: requiritur bona “EmailMessage/Attachments/0/ContentData” deest in API operatio “SendEmailV3”.
“inputs”: {
“name”: “Array Attachment”,
“value”: {
“ContentBytes”: {
“$content-type”: “@{body(‘Get_attachment_content’)[‘$content-type’]}”,
“$content”: “@{body(‘Get_attachment_content’)[‘$content’]}”
},
“Name”: “@{item()?[‘DisplayName’]}”
}
}
Kat says
Hi! Thank you so much for this, it’s helped immensely! However I’m getting an error at the Start and Wait for Approval step so I don’t actually know if I’m getting my attachments through correctly because we don’t make it to that point in the flow.
My flow is pulling an attachment that’s been submitted through Forms and I’ve updated my Append to Array variables accordingly (I think, it’s was giving me errors at that step but no longer), but now I can’t get the start and wait for approval step to work, it’s giving me an ‘InternalServerError’ with a tracking Id.
Any ideas?
Gbenga says
Hi Paulie, thank you for this wonderful insight. I have been on it for 2 weeks but your writeup did the magic. I almost gave up. God bless you and give you more wisdom
The problem is that the content key for the array when used with email is different than the key used for approvals.
For approvals the key is “content”: but for email the key is “ContentBytes”:
You’ll need to use two different arrays if you want to do both approvals and email attachments.
Here’s what the array looks like in one of my working email flows.
{
“inputs”: {
“name”: “approvalsAttachmentsArray”,
{
“content”: {
“$content-type”: “@{body(‘Get_attachment_content’)[‘$content-type’]}”,
“$content”: “@{body(‘Get_attachment_content’)[‘$content’]}”
},
“Name”: “@{item()?[‘DisplayName’]}”
}
===============================================================================
{
“inputs”: {
“name”: “emailAttachmentsArray”,
{
“ContentBytes”: {
“$content-type”: “@{body(‘Get_attachment_content’)[‘$content-type’]}”,
“$content”: “@{body(‘Get_attachment_content’)[‘$content’]}”
},
“Name”: “@{item()?[‘DisplayName’]}”
}
paul p says
hi, i want to do a similar thing , but the images i want to attach are in a SQL Azure image field?
How can i get those to attach to an approval?
kerr says
Hi, I struggled in the below error message, please help me.
Flow save failed with code ‘InvalidTemplate’ and message ‘The template validation failed: ‘The repetition action(s) ‘Build_Attachment_array’ referenced by ‘inputs’ in action ‘Append_to_Email_Attachment_Array_’ are not defined in the template.’.’
Ajai Govind says
This blog article was a life saviour.
After so much googling came up on this. Sounds so easy – add an attachment in email & also approval – huh! easier said than done!
If only I had found this 6 hours back!
Eric says
THANK YOU! I had problems even trying to copy the directions; part of the problem was I had no dynamic option to get the content type. I tried manually typing everything, but that failed. I finally just copied your code for approvals and changed the display name to use the dynamic content from my flow. My question is, how am I supposed to figure out some of this obscure (to me, more than tech capable) nuances like attaching files differently to emails vs approvals? Should I be utilizing the Microsoft doucmentation better? Anyway, THANK YOU!
Kunga says
Microsoft really needs to get serious about this feature. Nintex allows such an easy method of attaching multiple documents in approvals. We shouldn’t need to be doing all these redundant steps and it is worse if we are using Switch actions. You have to do this X number of times depending on how many Switch clauses want an email approval sent out with attachments.
Tasha mack says
Hello!
I am trying to use this, but I do not have the option to “Initialize Array to Store Attachment Content (Email)” or “Initialize Array to Store Attachment Content (Approvals)”. Was this a Variable that you set or is this no longer an option?
Do you know if this flow would work when an Item status is changed or does it only work when an Item is created?
Paulie says
You could trigger it however you please. If you struggle with the attachments use the contact form and I will see if I can help you out.
Victor says
Well done. This is the first time to comment on a solution. I was going crazy over this. Thanks a lot
pharmaprojeng says
Four years later and this post is still helping people! Even works for non-standard file types like .nwd and .step.
Thank you!