Errors processing Document Arrays

December 4th 2019
Back to all blogs

Errors processing document arrays in Power Automate can be a bugger. Let’s face it! But we provide several actions which operate on an array of documents, such as merging and adding to a ZIP file.

As per the articles on our support site and this blog; to perform an action on a collection of documents, you need to build an array of documents in JSON format, for example:

NOTE: We have highlighted the following expression inside the ‘Append to array variable‘ action: base64(body(‘Get_file_content_using_path’))

What is this expression doing?

Let’s start by explaining the schema of the ‘File Content‘ parameter provided by most Microsoft actions used to ‘Get a file’.

The Microsoft ‘File Content‘ parameter contains two properties:

  • $content-type = Media Type (also known as a MIME type)
    • type/subtype
    • application/vnd.openxmlformats-officedocument.wordprocessingml.document
  • $content = Base64 string (The actual file)

Most actions / APIs (like Encodian’s) are expecting to receive a file as a Base64 string, so the following expression ensures that only the $content property is added to the array and not the complete value of the ‘File Content‘ parameter: base64(body(‘Get_file_content_using_path’))

But processing the array fails…

Power Automate has some very clever post-processing capabilities which attempt to ensure that the correct data (Base64) is sent when required… however, sometimes, this just doesn’t work as expected.

We have crafted two almost identical Flows. The only difference is that one trigger action differs from the other. One Flow works, and the other (triggered from SharePoint) fails with the following error:

So the Encodian action doesn’t work! Well, not quite… The Encodian action is receiving insufficient data from Power Automate!

This is the input to the failed Flow action:

The data is correctly formatted and is the same as the data sent to the working merge action (below)!

There are, however, apparent differences in these two payloads; the first failing action’s properties contain the following prefixes ‘operation/<value>‘:

This indicates that Power Automate will post-process the data before sending it to the target endpoint, the Encodian action in this instance. In these scenarios, the post-processing assumes that the ‘fileContent’ property is the full ‘File Content’and processes it as such… this corrupts the Base64 string sent to the endpoint!!! Which is why the action fails.

How do I fix it?

The fix is pretty simple. Rather than use the base64() expression, pass the full ‘File Contents‘ property (the example shows an attachment):

The data is now formatted to contain the complete ‘File Content’s property, and Power Automate’s post-processing engine will ensure only the $content (Base64 string) is sent to the endpoint:

The previously broken flow is now working!

NOTE: If we apply the exact change to the other Flow that still uses the Base64() expression, it will fail as Power Automate does not always perform this post-processing.

Finally…

We are working with Microsoft to determine when this post-processing will happen and when it will not occur and whether there is a more consistent solution that will work in all scenarios. Together, we haven’t yet been able to define this… once we have, we will update the document and guidance.

For now, this hopefully helps to resolve your issue. If you still require help, please email support@encodian.com.

Author
Jay Goodison

Managing Director

Back to all blogs

You might also be interested in...