Merge SharePoint documents using Microsoft Flow or Azure Logic Apps

In one of my previous blog post, I created a Flow to Merge Multiple documents into Single PDF. So the question may arise in your mind as to why am I writing another blog post on Merge? 

This post shows how to use the Muhimbi REST API and the Microsoft Flow HTTP action which will help you Merge all documents within a SharePoint Online document library to a single PDF. If the document is not already in PDF Format it will convert the file as part of the merging process.

The main reason for using the above approach is better performance, as we are going to send all the Merge files – by their URL – in a single HTTP request, rather than looping through the documents one at a time. An additional benefit is that this request only takes up a single Muhimbi Operation, so is a lot more economical, and it gets around the file size limitations in Flow.

A prerequisite is that both the source files and destination file will need to be located in SharePoint Online. Also, Muhimbi’s SharePoint Online App must be installed in the SharePoint Online Site Collection, AND be linked to the same subscription as the Muhimbi (Flow) subscription.


Before you begin, please make sure the following prerequisites are in place:

From a High level our Flow will look like:

Let’s have some fun and build a Flow!

Step 1:

  • For this demo, we will use “Recurrence” Flow Trigger and configure it to run once a day. Note: For testing purposes, I have used this trigger, but in real-world situations, any other SharePoint Online trigger can be used.

Step 2:

  • Add the SharePoint Online Get files (properties only) action and select
    the path to the SharePoint Online folder.
  • This action will retrieve the list of files to merge

Using “Get files (properties only)” you can also filter down to the items that match a condition. For e.g. You can use ODATA orderBy query for specifying the order of entries or specify the total number of entries to retrieve. For more details see.

Step 3:

  • Initialize the variables with reference to the screenshot below:

Note: I have used this convoluted approach with 3 variables as – at the time of writing – Flow does not allow ‘self-referencing’ when setting the value of a variable. Please vote for this Flow Idea

Step 4:

  • Add the Apply to each loop and set it to the “value” field, output of the SharePoint Online Get files (properties only) action.

Note: Steps 5, 6 and 7 all need to be inserted inside the ‘Apply to each’ loop.

Step 5:

Set variable(Server relative URL).

We will build the path to the file to merge or URL of web page to convert. (e.g. /sites/Finance/Shared Documents/Some Folder/Some file.docx). 

  • To keep it simple let’s hardcode the first half of the file URL. /sites/<Site-collection-name>/
  • Use the “Folder path” variable output of the SharePoint Online Get files (properties only) action.
  • “File name with extension” output of the SharePoint Online Get files (properties only) action.

The Next variables ;true;”Name” are optional. They are used to create the Bookmark.

For more details see below:

  • Include bookmarks (‘true’ in the example above): The source file may already include PDF Bookmarks, or may be able to generate such bookmarks as part of the conversion process, e.g. an MS-Word file. Specify true to copy these bookmarks to the merged PDF file, or false to strip out any bookmarks. This value is optional
  • Bookmark name: The name of the PDF bookmark to use for the specified file. This is typically used to specify the file name, as we do in this demo, but you can specify any text such as the Title field of the SharePoint file.

Step 6:

  • In this Step, we will create the Merge String. i.e. on each loop it will concatenate the Temporary String with Server relative URL.
  • Set variables Merge String variable with reference to the screenshot below.

Step 7:

  • Set the variable Tempory Sting to Merge String with reference to the screenshot below.

Step 8:

  • Add the HTTP action outside the apply each loop.

Method: POST

URI: (Muhimbi Merge Endpoint)


  • API_key: Your Muhimbi API Key.
  • Content-Type: application/json.


  "fail_on_error": true,
  "use_async_pattern": true,
  "sharepoint_file": {
    "site_url": "",  
    "source_file_url": "@{variables('Merge String')}",
    "destination_file_url": "/sites/site-collection-name/Librarname/filename.pdf"
  "document_start_page": "Starts on the default page"

To better understand the JSON Body see Muhimbi Github Merge sample code.

Your Merge Flow is now ready. Thanks for reading…


2 thoughts on “Merge SharePoint documents using Microsoft Flow or Azure Logic Apps

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s