Skip to main content

How to Create a SharePoint Document Library with the REST API in Power Automate

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

A flow can create a document library with one request to SharePoint's REST API. Sending it to lists/add lets you give the library a friendly name, such as Team Invoices, and a separate web address without spaces, such as /TeamInvoices.

Syntax​

The request goes through Send an HTTP request to SharePoint (How to Use Send an HTTP Request to SharePoint):

FieldValue
MethodPOST
Uri_api/web/lists/add
HeadersAccept: application/json;odata=nometadata
Content-Type: application/json;odata=verbose
Body: general form
{
"parameters": {
"__metadata": { "type": "SP.ListCreationInformation" },
"Title": "<name>",
"Url": "<web address>",
"TemplateType": <template number>,
"Description": "<description>"
}
}
  • parameters: lists/add is the REST form of the Add method of a site's lists, and parameters is the name of its one argument (ListCollection.Add).
  • __metadata: says the object is an SP.ListCreationInformation. The verbose Content-Type header is what lets SharePoint read it.
  • <name>: the name people see, in Site contents and at the top of the library. Spaces are fine.
  • <web address>: the part of the library's address after the site's. Use letters and numbers without spaces. Renaming the library later doesn't change it.
  • <template number>: the kind of list to create, a number without quotes. 101 is a document library and 100 is a blank list, from Microsoft's ListTemplateType list.
  • <description> (optional): the text under the library's name in its settings.

The properties come from Microsoft's ListCreationInformation class. lists/add exists because the plainer request in Microsoft's REST examples, a POST to _api/web/lists with an SP.List, has no property for the address. The address then comes from the title (How to Create a SharePoint List with the REST API).

The Example​

The example creates a library called Team Invoices, at the address /TeamInvoices, with the description Invoices from our suppliers., on a communication site. The flow has two steps: the trigger Manually trigger a flow and one Send an HTTP request to SharePoint called Create the library.

Prerequisites​

  • Permission to create libraries on the site, such as Edit or Full Control, for the account the flow's SharePoint connection uses.

Step 1: Add the Request​

In a flow with Manually trigger a flow, add Send an HTTP request to SharePoint and rename it Create the library. Fill in its fields:

FieldValue
Site AddressYour site, from the drop-down
MethodPOST
Uri_api/web/lists/add

The two headers are under Advanced parameters: pick Headers there, then add Accept and Content-Type.

Step 2: Write the Body​

In Body, type:

Create the library → Body
{
"parameters": {
"__metadata": { "type": "SP.ListCreationInformation" },
"Title": "Team Invoices",
"Url": "TeamInvoices",
"TemplateType": 101,
"Description": "Invoices from our suppliers."
}
}

The action now looks like this:

The Create the library action with Site Address Communication site - https://contoso.sharepoint.com, Method POST, Uri _api/web/lists/add, the headers Accept application/json;odata=nometadata and Content-Type application/json;odata=verbose, and the Body with parameters, __metadata type SP.ListCreationInformation, Title Team Invoices, Url TeamInvoices, TemplateType 101 and Description Invoices from our suppliers.

Step 3: Run the Flow​

Save the flow and test it manually (How to Test a Cloud Flow Manually in Power Automate). Create the library took 0.6 seconds:

The run of the flow, with green ticks on Manually trigger a flow, 0s, and Create the library, 0.6s

The Result​

The site now has a Team Invoices library. Its settings page (Settings > Library settings > More library settings) shows the three values from the body, with the address the flow chose:

The Team Invoices Settings page with Name Team Invoices, Web Address https://contoso.sharepoint.com/TeamInvoices/Forms/AllItems.aspx and Description Invoices from our suppliers.

Create a List the Same Way​

The same request creates a list with TemplateType 100. Put Lists/ in front of the address, where SharePoint keeps the lists you create in the browser: "Url": "Lists/Departments" puts a list at /Lists/Departments. The Overtime Timesheet setup flow creates its lists and its library this way.

Common Mistakes​

MistakeWhat happensDo this instead
Using _api/web/lists when the address mattersThe address comes from the titleUse _api/web/lists/add with Url
TemplateType 100 for a libraryYou get a listUse 101
Quotes around the template numberIt's text, not a numberWrite 101 without quotes
Creating without checking firstA second run tries to create it againCheck that it's missing first

Troubleshooting​

SymptomLikely causeFix
The action fails with status 403The connection's account can't create libraries on the siteGive it Edit or Full Control, or use another connection
The action fails with status 400The body isn't what lists/add expectsCheck the parameters wrapper, the Content-Type header and the commas
The library has a different addressThe Url value had spaces or a typoDelete the library and create it again with the right Url

FAQ​

Can I change the library's address later?​

Not by renaming it: a new name keeps the old address (How to Rename a SharePoint Library Without Changing Its URL). That's why the address is worth choosing when you create the library.

How do I stop the flow creating it twice?​

Look for it first and create it only when it's missing (How to Check Whether a SharePoint List Exists in Power Automate). Libraries are lists, so the same check works.

Does this need a premium licence?​

No. Send an HTTP request to SharePoint is part of the standard SharePoint connector.

Conclusion​

POST to _api/web/lists/add with a body whose parameters hold __metadata SP.ListCreationInformation, the Title, the Url, TemplateType 101 and an optional Description. The library gets the name you chose and the address you chose, and a list works the same way with 100 and a Lists/ address.

Additional Resources​