Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Merge PDF email attachments with Merge PDF API in logic apps

Explorer ,
May 27, 2024 May 27, 2024

I have a Logic App that monitors incoming emails.  Some have multiple PDF attachments that I want to merge and save to Dropbox.  I have it working with the Encodian API but I want to switch it over to the Adobe API.Screenshot 2024-05-27 165751.png

I then use the array as input for the Encodian API.  When I try this with the Adobe API, I get an error, 

"bad value for parameter 'files'; invalid type".  Doing some reasearch I read somewhere that I should change the fileName line to 

 

"$content-type": "application/pdf"

 

This still returns the same error.  

Even though the files were already PDF's I thought maybe they still needed to be converted to Base64 so I tried that.

Screenshot 2024-05-27 171149.png

 

The Append array action generates this result: 

 

[
	{
		"$content-type":"application/pdf",
		"fileContent":"SlZCRVJ..."
	},
	{
		"$content-type":"application/pdf",
		"fileContent":"SlZCRVJ..."
	}
]

 

The error again is:

 

"bad value for parameter 'files'; invalid type".

 

 the full code for the action is:

 

{
    "inputs": {
        "host": {
            "connection": {
                "name": "@parameters('$connections')['adobepdftools']['connectionId']"
            }
        },
        "method": "post",
        "body": {
            "files": "@variables('FileToMerge')",
            "outputFileName": "Temp.pdf"
        },
        "headers": {
            "x-api-key": "PowerAutomate",
            "x-region-value": "-ue1"
        },
        "path": "/operation/v1/combinePDF"
    }
}

 

 

Why does this have to be so difficult?  Where am I going wrong? 

TOPICS
How to , PDF Embed API , PDF Services API , Power Automate
3.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , May 30, 2024 May 30, 2024

For anyone looking for the same answer, I was finally able to get this sorted out. 

 

If you are using the 'When a new email arrives' trigger, you need to append to the array variable (mine is named 'FilesToMerge' ) using a 'For each' loop based on the trigger body output:

 

triggerBody()?['attachments']

 

 

Then append the contentBytes alone to the array: 

 

 items('For_each')?['contentBytes']

 

 

The json in the code view will look like this:

 

{
    "inputs": {
        "name": "FilesToMerge",
        "valu
...
Translate
Adobe Employee ,
May 28, 2024 May 28, 2024

You showed how you created the array, but not how you are calling the API. Are you using the official Acrobat Services connector?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 28, 2024 May 28, 2024

Yes, I am using the official connector, thank you, I should have said that.  The code for the action is the last block of code in my question.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 28, 2024 May 28, 2024

I don't use the code view often for PA, can you share a screenshot of the UI of the action?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 28, 2024 May 28, 2024

Screenshot 2024-05-28 095745.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 28, 2024 May 28, 2024

From what I can see, the expection is that the array input is an array of files. You are using an array of objects containing a content-type and fileContent, but I believe it needs to be raw binary.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 28, 2024 May 28, 2024

The trigger is the Office 365 Outlook - When a new email arrives (V3)

What output from the trigger do I need to use and how should the append to array be formated? or the Adobe Merge be constructed?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 28, 2024 May 28, 2024

Well you need to iterate over the attachments, and get the binary data for each, and append to the array. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 28, 2024 May 28, 2024

As far as I know, that's what I am doing. What output from the trigger contains binary data and how is that supposed to be added to the array so that it is not an object?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 28, 2024 May 28, 2024

Eh....  I don't know. I'd have to look at your Logic App - that may be something you need to bring up on Microsoft's support forums.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 28, 2024 May 28, 2024

I have to wonder if employees who are monitoring a forum for a product such as you are, are trained to be vague and to provide as little help as possible?  The fact that I am on forum asking questions indicates that I am looking for help. From my questions you should have realized that I was not understanding something about raw binary vs Base64.  You know full well that PDF data bought into a flow is in Base64 format and that it needs to be converted to Binary.  I just figured that out myself but you could have been helpful and saved me hours of frustration.  You should be ashamed of yourself Raymond. 

 

Now that I have figured out that I need to, and how to, convert the data to Binary, you still haven't provided me with information on the proper formating of the array that I will use as input for the Merge PDF.  

 

Raymond, if you can't provide a helpful answer then I will have to report you to your supervisor.  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 28, 2024 May 28, 2024

Hi, first off, I'm sorr you feel I'm being vague, it is not my intent. What I was trying to say is that I don't have access to, or my own example, of a flow getting email attachments. I was vague because that portion is outside our pervue and we can't really support that. You said I should have known it came in via Base64. No, I don't know how the email trigger for PowerAutomate supports attachments. I don't know everything about that service that is run by Microsoft. I also stated earlier that you needed the *binary* data. I just couldn't tell you _how_ to do that without knowing what your input is.

 

Now, I'm glad you got that part working, you said: "you still haven't provided me with information on the proper formating of the array that I will use as input for the Merge PDF", per my earlier message: 

"From what I can see, the expection is that the array input is an array of files. You are using an array of objects containing a content-type and fileContent, but I believe it needs to be raw binary."

 

That is how you create the array. For each set of binary data for each attachment, you append it to the array. There isn't a 'shape', it's just an array of binary blogs essentially.

 

"Raymond, if you can't provide a helpful answer then I will have to report you to your supervisor." Ok!

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 29, 2024 May 29, 2024

I understand that I need to append the binary to the array, but is it just the binary? Does it need to be formatted as json or a key/value combination?  Is there a content type key value that needs to be included?  If you know how the data needs to be recieved by the Merge PDF in array format, you could be more specific on the structure required, perhaps showing an example.  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 29, 2024 May 29, 2024

Man, I don't know how else to say it. Just. An. Array. Of. Binary. It isn't JSON, there are no keys. So in PowerAutomate, you initialize a new array variable. As you loop over the attachments, I believe PA has an 'append to array' action, and you would pass the binary data to the array. That should literally be it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 29, 2024 May 29, 2024

It won't save the flow because it says invalid JSON.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 29, 2024 May 29, 2024

Hmpth, PowerAutomate can be a pain sometimes. Does it specifically say what step has invalid JSON? Also, would you be able to share the flow with raycamde@adobe.com, and then I can take a look?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 29, 2024 May 29, 2024

Sorry, got it to save.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 30, 2024 May 30, 2024

For anyone looking for the same answer, I was finally able to get this sorted out. 

 

If you are using the 'When a new email arrives' trigger, you need to append to the array variable (mine is named 'FilesToMerge' ) using a 'For each' loop based on the trigger body output:

 

triggerBody()?['attachments']

 

 

Then append the contentBytes alone to the array: 

 

 items('For_each')?['contentBytes']

 

 

The json in the code view will look like this:

 

{
    "inputs": {
        "name": "FilesToMerge",
        "value": "@items('For_each')?['contentBytes']"
    }
}

 

 

If you veiw the output of the Array variable with a compose Action, You see a sincle line of code like this:

 

["---Code from first attachment---","---Second---","---etc---"] 

 

 

The Adobe Merge PDFs action then will look like this:Screenshot 2024-05-30 103608.png

 

Be sure to click this button to change the input mode first: 

Screenshot 2024-05-30 103857.png

 

You can then use the output from the Merge PDFs as the content for whatever action you use to create the new file.

 

I really hope this is of benefit to someone else searching for the same answer.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 30, 2024 May 30, 2024

Very happy you got it, and thank you for sharing your solution!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 03, 2025 Jun 03, 2025

I have a virtually identical flow to yours, including a compose step for debugging, but I'm receiving the same error you encountered. I've verified that I'm using the "array" view in the Merge step, but nothing I do seems to work.

The only thing I can think of is that the code view for my "Append to Array Variable" step also includes some metadata in the JSON automatically, but this isn't something that can be changed as it's auto-generated by Microsoft (see image)

taylor_0370_0-1748960155544.png

Here's the non-code view:

taylor_0370_1-1748960434947.png

 

When I check the ouput of "Append to Array" using a "Compose" step ouside of the loop, it looks just like what you've posted. I've also verified that the JSON code view of the "Merge PDF" step is accurate.

taylor_0370_2-1748960498808.png

taylor_0370_3-1748960517522.png


This seems like such a simple task, but I'm driving myself up the wall trying to debug this. Is there anything obvious you can see in my flow that might be causing me to still get the same error you did?

 

 




Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 03, 2025 Jun 03, 2025

The first thing I notice is that your file content is not a PDF, a pdf's base64 will start with JVBER. At least in all of my work.  If the file is not a PDF then you need to convert it to a PDF first.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 03, 2025 Jun 03, 2025

The Base64 bytes of the files I'm passing aren't visible in any of these image; they're just code view of the flow steps. I've verified in my tests that I'm using PDFs, and there's a conditional step displayed in one of the images to verify that only pdf attachements are passed to the array.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 03, 2025 Jun 03, 2025

To clarify, here's the input view for the Adobe Merge step that's failing; I've verified via a "compose" step and by manually reviewing the output of "Append to Array" that both file objects are in fact valid PDFs.

taylor_0370_0-1748963569158.png

and the second file (for obvious reasons I've truncated the full view of the input)

taylor_0370_1-1748963621694.png

When I check the output of both the "compose" and "append to array" steps from a failed run, they appear to match the structure in your working example (the below images are truncated for clarity)

 

taylor_0370_3-1748963974732.png

I'm wondering if something about the "Append" step is missing the final "==" intended for signaling "end of file" now that I look at it.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 03, 2025 Jun 03, 2025

In base64 the string must be divisible by 4 from what I understand, and the == at the end are used to fill in emply spaces to make it the correct length.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 03, 2025 Jun 03, 2025

Right, i did see that. then as I was looking back at nmy own question I saw the wrong base64.  My bad.

I have been having some issues with item()?['contentBytes'] at times. sometime you include the name of the for each and other times you don't. but this is what I have found:

 

  • Use item() inside the body of a For each loop — this refers to the current item being iterated over in that loop.
  • Use items('For_each_-_Attachments') outside the loop body (e.g., in an If action following the loop, or in an expression not nested in the loop scope) to reference a specific item from the loop by name.

 

I have been using ChatGPT to help me out and it has been quite useful.  

I would try removing the For_each reference in your Append to array variable.

DRYBSMT_0-1748964948460.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources