Recently, Microsoft Flow team has released a new SharePoint HTTP Request connector which would be extremely useful in automating the business processes.  We could use the HTTP connector to achieve this same results, but with this connector, we don’t need to worry about application registration and authentication token etc.   We can run any SharePoint REST API endpoint.

In this blog, I would try and address a very common scenario for Power Users /SharePoint Admins, i.e. to create multiple document libraries. I will be using a list provided in an Excel document.  I suppose we can also create libraries with the unique permissions, but for this blog, I will keep it simple.  Here is what the full Flow looks like:

MS Flow – Create multiple document libraries

STEPS

  • I have a custom list where admin user will provide a site URL where these libraries will be created.  It will be a manual trigger which will ask user to upload a file. Let’s assume that a template file is provided to the users which they will complete in the given format.  I am also assuming the person creating this request will have access to the site where document libraries would need to be created.

  • I had to copy the file uploaded by the user to my OneDrive as currently, it is not possible to read an Excel file from the SharePoint document library.  I have used the item id as the filename to ensure that it will always be unique.  It will be replaced if the file already exists (below screenshot is for three separate requests, all the multiple libraries details)
  • After the file is uploaded, we will get all the rows from the file which contains three columns i)Title, ii) URL, and iii) Description.

  • We will need a For each loop to read all the rows from the Excel file.  Important to note: Flow doesn’t know yet the details of the file so it won’t show you anything in the ‘Dynamic content’.  To overcome this, I selected the an existing Excel template in my OneDrive and after I got the ‘Dynamic content’ I changed the file name to ID so it gets dynamically created.  You can obviously write the expression.

  • Now the real bit, we will need to make a POST request to SharePoint REST API endpoint/uri.  To create list the URI is “_api/web/lists”.  The body of the request must include:
{
 "__metadata": {
 "type": "SP.List"},
 "BaseTemplate": 101, // 101 is template for document library, full list in the reference below 
 "ContentTypesEnabled": false, // if you want to enable content type, change this to true
 "Description": "Optional Document Library Description",
 "Title": "SharePointer" // This will be part of the url for the library
}

  • We then Parse the response data through Parse JSON connector, in order to get the guid/list id created.  I have initially created the library with the short title without spaces to avoid getting %20 in the URL. After library is created, I have updated the libraries with the longer title (with spaces) this way we will get the nice short URLs.
  • Constructing the URI for this update was slightly challenging as this endpoint must include a single quote with the list guid/id, for example:
/_api/web/lists('b0e48240-4e6f-4ad9-9f47-f4eafc5d1f69')

To achieve this I used concatenate expression to include the list id/guid which is in the response received after a library has been successfully created.

concat('/_api/web/lists(''',body('Parse_JSON')?['d']?['Id'],''')')

Note the extra single quotes at the start of parentheses and before the  second last parentheses

In the update POST request we will need to include the following in the Header:

{ "Accept": "application/json;odata=verbose", 
 "Content-Type": "application/json;odata=verbose", 
 "X-HTTP-Method": "MERGE", 
 "IF-MATCH": "*" 
}
And pass the body with the new longer Title which is in the Excel file ‘Display Name’
{
 "__metadata": {"type": "SP.List"},
 "Title": "New Document Library Title"
}

Final results – multiple document libraries created within few seconds and no ugly URLs.  More more clicking UI to create libraries..!.

Reference:

Please follow and like us:
error

2 Comments

Beth · December 16, 2019 at 21:23

I have a Flow that is very similar to yours except that the trigger is set as a manual trigger with the following inputs:
Document Library (type: text)
Site Owner1 Email: (type: text)
Site Owner2 Email: (type: text)

In my Send an HTTP request to SharePoint its creating the document library and doing all the permissions breaking/reassign. The question I have is in my last step, I’d like to send an email to site owners with a link to the newly created document library. But I don’t know what action to create and how to format the expression to get the site URL. Would you be able to advise?

    SharePointer · May 25, 2020 at 22:20

    I know this is late but might help someone. I need more details for specific guidance but assuming you have owners details (if not you will have to make another http call to get it). Also, since we have the excel document with details we can build the links for libraries e.g. /sites/{siteid}/{library title}/ or you can send the owner link for the site content page which would list all the libraries/lists. The link for site content is : sites/{siteid}/_layouts/15/viewlsts.aspx?view=14. Let me know if this doesn’t help.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.