Menu Close

Create SharePoint list using Flow

(ESTIMATION TIME: 5 MINUTES)

Microsoft Flow is a great automation tool. It integrates with over 230 services using connectors where each of them contains multiple triggers and actions. One of those connectors is a SharePoint Online connector with a set of 10 triggers and 47 actions(!). Such big set allows to create many scenarios. Starting from managing simple resource list to invoice approvals along with permissions on different levels. Even though, SharePoint Online connector does not contains actions like “Create list”. Such actionmay be useful if you want to create those elements dynamically. Before you think “what a bummer” and turn your eyes on custom code solutions please read this article. I’ll show you how you can create SharePoint List or SharePoint Library using Microsoft Flow.

Create list from list template

Before I’ll show you how I did that let me explain why I need this kind of solution.

Last week I’ve publishing Delegation Learning App. The app was an extension to what has been described in article How to overcome 500 items limit in PowerApps. Using my app a user is walkthrough different integration scenarios – static data, excel from onedrive and SharePoint Online. To make all steps easy I wanted the data sources to be already prepared for the user. With static and excel data there was no problem – I’ve simply attached them to app package. But how to prepare SharePoint Online list? I had 2 options:

  1. Give access to my environment – however I didn’t want to add external access for anyone who want to use an app. I didn’t want to create an account which I would be shared to others too.
  2. Prepare an excel that a user can import to his SharePoint Online – however this option has some import column limitations and I my aim was to create an universal solution.
  3. Create a list dynamically using Microsoft Flow – for me this method was perfect. I could defined any list definition and add items to this list. The only thing that the user had to do is import import flow (which is done automatically if you import PowerApps package) and run it.

Now you know why I decided to go with this option. Now let me explain what I’ve used and how it works.

Create SharePoint list using Flow

To achieve my goal I need use “Send as HTTP request to SharePoint” action which allows to execute any action that is available through SPO REST API.

SharePoint Online REST API is a special way of sending instructions to SPO using HTTP requests. I.e. by making HTTP GET call to https://<Site ABCD url>/_api/web/lists you can get a list off all lists in ABCD site.

Did you know?
Your browser is constantly using such way of communication. Every time when you open some web site your browser is making an HTTP GET request. Go ahead, open a new browser tab and try it: paste https://<Site ABCD url>/_api/web/lists URL (of course swap <Site ABCD url> with your own SPO site url) to see the XML representation of all lists that exists in the site along with metadata

To create a SharePoint list I need to do what is described in this section. In above section you can find below example:

1. url: "http://<site url>/_api/web/lists"
2. type: "POST"
3. headers:{
            "content-type": "application/json;odata=verbose",
            "accept": "application/json;odata=verbose"
}
4. body: { '__metadata': { 'type': 'SP.List' }, 'AllowContentTypes': true,
 'BaseTemplate': 100, 'ContentTypesEnabled': true, 'Description': 'My list description', 'Title': 'Test' }
           

Let me quickly translate it for you.

1. Hey SharePoint, I'm going to do something with your lists...
2. ...and that'll be a modification (create or update)...
3. ...And in step 4 (that is body) I'll send you the details using JSON notation ("content-type" header). If you want to communicate with me please use the JSON notation ("accept" header)...
4. Ok, so the message is this: <the body>

Normally you would also need to authorize yourself providing an token – OAuth token to be precise – but thanks to MS Flow action, the connector is taking care of it 🙂

The last question you may have now is: “how should I know what to put in the body?”. There is a wonderful resource that explains everything you can do using SharePoint REST API: REST API references and samples (add it to your bookmarks, trust me).

Now, in above knowledge base there is a sub-page where you can find all properties you can use in the body: List Properties. You can find there the definition of all used properties. I.e. Base Template represents a ListTemplateType value (see ListTemplateType reference for template type values).

So the last thing is to…

Bring everything back together

Now let’s convert theoretical knowledge into our Microsoft Flow solution.

Disclaimer: Normally I would paste some image below and describe what it shows + what you need to do to achieve the presented result. But thanks to Clarissa Gillingham I realized that if an image is worth a thousands words, a movie is worth a thousands images (23 images per second to be precise #GeekContent). That’s why I’ll just leave with a movie – I hope it’s self explanatory 🙂

Code used for Send an HTTP request to SharePoint is below:

URI:
_api/web/lists

HEADERS:
content-type = application/json;odata=verbose
accept = application/json;odata=verbose

BODY:
{ '__metadata': { 'type': 'SP.List' }, 'AllowContentTypes': true, 'BaseTemplate': 100, 'Description': 'List with items to work with delegations in PowerApps', 'Title': 'Delegation Playground' }

Ready Flow you can download from here.

PERFECT! Now you can click Flow button, provide ANY SharePoint Site URL you have access to and the defined list will be created there. Is that everything? OF COURSE NOT! A list with the default settings contains only built-in fields which won’t be enough in 99% cases. So now we should add some fields…but this part I’ll cover next week 🙂

Stay tuned!

Related Posts

Leave a Reply

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