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

Merge PDF email attachments with Merge PDF API in logic apps

Explorer ,
May 27, 2024 May 27, 2024

Copy link to clipboard

Copied

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.pngexpand image

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.pngexpand image

 

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

Views

1.5K
Translate

Report

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
...

Votes

Translate
Adobe Employee ,
May 28, 2024 May 28, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Report

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

Copy link to clipboard

Copied

Screenshot 2024-05-28 095745.pngexpand image

Votes

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Report

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

Copy link to clipboard

Copied

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?

Votes

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Report

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

Copy link to clipboard

Copied

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?

Votes

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Report

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

Copy link to clipboard

Copied

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.  

Votes

Translate

Report

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

Copy link to clipboard

Copied

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!

 

 

 

Votes

Translate

Report

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

Copy link to clipboard

Copied

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.  

Votes

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Report

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

Copy link to clipboard

Copied

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?

Votes

Translate

Report

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

Copy link to clipboard

Copied

Sorry, got it to save.

Votes

Translate

Report

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

Copy link to clipboard

Copied

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.pngexpand image

 

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

Screenshot 2024-05-30 103857.pngexpand image

 

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.

Votes

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Report

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