Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Outlook
    • Planner
    • Power Apps
    • SharePoint
    • Teams
  • Triggers
  • Ready to use solutions
    • Approval Process Template
    • Task Delegation App
    • The Ultimate Power Automate expressions cheat sheet
    • Power Automate HTTP requests to SharePoint cheat sheet
    • Power Automate HTTP requests to Graph API cheat sheet
  • ABOUT ME
  • Get help with your flow
  • POWER PLATFORM SERVICES
Menu

How to copy a SP document library with Power Automate

Posted on May 26, 2024June 2, 2024 by Tom

“I’d like to duplicate structure of an existing SP document library, how can I create its copy on another site, e.g. with Power Automate?”


If you use SharePoint as a data storage, there’re two data types you can use – items and documents. Items are stored in lists, documents in document libraries. But often you need more columns for all the data than the default list/library gives you, so you keep adding more. And then you realise you need the same on another SP site. You already spent some time adding all the columns, it would be a shame to keep it only on a single SP site. Why not copy it to multiple sites, to reuse it?

I already explained how to copy existing lists, this article is about libraries. To make it a bit more interesting, it’ll use also a different approach.

Create a new document library

It’s a more old school approach, but at the same time maybe a more reliable one. This one doesn’t rely on complex functions, it creates the library step by step – library first, columns later. It can be also used to copy lists with only a cosmetic change.

Firstly, create the new library using an HTTP request to SharePoint to the target site.

Method: POST

Uri: _api/web/lists/

Headers:
{
  "accept": "application/json;odata=verbose",
  "content-type": "application/json;odata=verbose"
}

Body:
{    "__metadata": {
        "type": "SP.List"
    },
    "Title": "<LibraryName>",
    "Description": "",
    "BaseTemplate": 101
}

Note: this is the step where you differentiate whether it should be a list (BaseTemplate 100) or a document library (BaseTemplate 101).

It’ll create a new blank library with only the basic columns.

List columns in both libraries

As the columns in the original library can change, you don’t want to hard code them in the flow. You want to take the columns that exist right now, when the library is copied. Let’s do it by comparing the columns in those libraries and identifying the missing ones.

List all the columns in the original library with another HTTP request.

Method: GET

Uri: _api/web/lists/getByTitle('<originalLibraryName>')/fields

Do the same for the new library. Here I’m referencing the new list title with an expression, using the output from the creation HTTP request.

body('Send_an_HTTP_request_to_SharePoint_-_create_new_library')?['d']?['title']

Compare the columns and find the differences

Now you have columns from both the libraries for comparison. But before you do that, there’s a need for a small “cleanup”. The reason is that the libraries contain a lot of hidden columns, something you’re not interested in. You want only the columns you created, not the ones that are added automatically by SharePoint.

Filter from the original library columns only the ones whose ‘Group’ is equal to ‘Custom Columns’.

body('Send_an_HTTP_request_to_SharePoint_-_get_original_lib_columns')?['d']?['results']

item()?['Group']

Select only the ‘Title’ from the remaining columns in both the libraries, and find the differences as explained in the previous article.

Power Automate copy document library

The output of this ‘Filter array’ will be only the columns that exist in the original library but not in the new one – the columns to add.

Get the columns XML schema and create them in the new library

Once you have the column names, all you that’s left is to get their XML schema and recreate them in the new library.

Add an ‘Apply to each’ and for each column get its XML schema.

Power Automate copy document library

Extract the schema from the HTTP request, and use it to create the column in the new library. The library name is again extracted directly from the creation HTTP request as shown above.

body('Send_an_HTTP_request_to_SharePoint_-_get_OG_column_schema')?['d']?['SchemaXml']
Power Automate copy document library

And that’s it, you just copied a structure of an existing document library. Now you can add the columns to the views, or even copy content from the original library.

Summary

As you can see, it’s not that complicated to copy a document library with a Power Automate flow. This approach is a bit different from the one copying SP lists, but it’s also a bit less of a ‘black box’. Here you know exactly what’s going on in every step. Firstly, create the new, blank library. Secondly, identify the columns to add. Thirdly, get their XML schema and use it to recreate the columns. No complex functions that can change in time, just a bunch of good, old REST API calls.

And with a cosmetic change it can be used also to create lists, just use BaseTemplate 100 instead of 101.


πŸš€ Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

1 thought on “How to copy a SP document library with Power Automate”

  1. Pingback: From the Microsoft Power Platform blogs: Copy a document library; Power Pages licensing dashboard; List solution details; Cancel an approval - Cloudproz

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

πŸš€ Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

Still exchanging emails to get things approved?

Use the Approval Process Template and the Task Delegation App to skip the hard part and deploy an automated, fully functional approval solution on a SharePoint list in minutes! And then the next one, and the next one...

Approval Template Preview ✨ Learn more ✨

Turn ideas into flows with ease!

Grab the complete Power Automate Cheat Sheet Bundleβ€”everything you need to master expressions, SharePoint HTTP calls, and Graph API in Power Automate.

Cheat Sheet Bundle Preview ✨ Get the Cheat Sheets

Didn't find what you were looking for?
Need to adjust a solution to fit your needs?
Or would you just like to get an assistance from somebody with thousands of hours of experience with Power Automate?

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2025 Let's POWER Automate | Theme by SuperbThemes