Skip to main content

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

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

A flow can create a folder in a document library with one REST request to _api/web/folders. Paired with a quick check that the folder isn't there yet, the flow can run any number of times and still leave exactly one folder.

Syntax​

Both requests go through Send an HTTP request to SharePoint (How to Use Send an HTTP Request to SharePoint).

Look for the folder​

FieldValue
MethodGET
Uri_api/web/lists/getbytitle('<library name>')/rootfolder/folders?$filter=Name eq '<folder name>'&$select=Name
HeadersAccept: application/json;odata=nometadata
  • <library name>: the library's title, as in Site contents.
  • rootfolder/folders: the folders at the top of the library.
  • $filter=Name eq '<folder name>': only the folder with that name. $select=Name keeps the answer short.

The answer has a value array: one folder when it exists, empty when it doesn't.

Create the folder​

FieldValue
MethodPOST
Uri_api/web/folders
HeadersAccept: application/json;odata=nometadata
Content-Type: application/json;odata=verbose
Body: general form
{
"__metadata": { "type": "SP.Folder" },
"ServerRelativeUrl": "<address of the new folder>"
}

This is the request in Microsoft's Working with folders and files with REST.

  • <address of the new folder>: the folder's address from the server's root: the site's path, the library's web address, then the folder's name. On the root site, a folder 2026 in the library at /Contracts is /Contracts/2026. On a site at /sites/Finance, it would be /sites/Finance/Contracts/2026.

The Example​

A document library called Contracts, on the root site, gets a folder called 2026. The flow, Create a Folder, has four parts:

  1. Manually trigger a flow.
  2. Find the folder, the GET.
  3. If the folder is missing, a condition.
  4. Create the folder, the POST, in the condition's True branch.

Prerequisites​

  • Permission to add to the library, such as Edit or Contribute, for the account the flow's SharePoint connection uses.

Step 1: Look for the Folder​

Add Send an HTTP request to SharePoint and rename it Find the folder:

FieldValue
Site AddressYour site
MethodGET
Uri_api/web/lists/getbytitle('Contracts')/rootfolder/folders?$filter=Name eq '2026'&$select=Name
HeadersAccept: application/json;odata=nometadata

The Find the folder action with Method GET, the Uri _api/web/lists/getbytitle('Contracts')/rootfolder/folders?$filter=Name eq '2026'&$select=Name and the Accept header application/json;odata=nometadata

Step 2: Create It Only When It's Missing​

Add a Condition and rename it If the folder is missing (How to Add a Condition in Power Automate). On the left, add this expression; choose is equal to; on the right, add the expression true:

If the folder is missing → left value
empty(body('Find_the_folder')?['value'])

empty() is true when the value array has no folders in it (How to Check If an Array Is Empty in Power Automate). Find_the_folder is the action's name with underscores for spaces.

Step 3: Create the Folder​

In the condition's True branch, add Send an HTTP request to SharePoint and rename it Create the folder:

FieldValue
Site AddressYour site
MethodPOST
Uri_api/web/folders
HeadersAccept: application/json;odata=nometadata
Content-Type: application/json;odata=verbose
Create the folder → Body
{
"__metadata": { "type": "SP.Folder" },
"ServerRelativeUrl": "/Contracts/2026"
}

The Create the folder action with Method POST, Uri _api/web/folders, the Accept and Content-Type headers, and the Body with __metadata type SP.Folder and ServerRelativeUrl /Contracts/2026

Step 4: Run the Flow Twice​

Save the flow and test it manually (How to Test a Cloud Flow Manually in Power Automate). On the first run, Find the folder found nothing, and Create the folder created it.

Then I ran it again with Test > Automatically > With a recently used trigger (How to Rerun a Cloud Flow with the Same Inputs in Power Automate). This time Find the folder found 2026, the condition was false, and Create the folder was skipped, shown by its grey sign:

The second run, with green ticks on Manually trigger a flow, Find the folder at 0.1s and If the folder is missing, and a grey skipped sign on Create the folder in the True branch, with 0 Actions in the False branch

The Result​

The Contracts library has one 2026 folder, after two runs:

The Contracts library with one folder, 2026, modified 22 minutes ago by Admin User

Common Mistakes​

MistakeWhat happensDo this instead
Leaving out the site's path on a site under /sites/The address points at the root siteStart with the site's path, such as /sites/Finance/Contracts/2026
Creating without looking firstA second run tries to create it againLook for the folder and create it only when it's missing
The library's address in getbytitle('…')No list has that titleUse the library's title there, and its address in ServerRelativeUrl

Troubleshooting​

SymptomLikely causeFix
Find the folder fails with status 404No library with that titleCheck the title in Site contents
Create the folder fails with status 404 or 400The address in ServerRelativeUrl is wrongCheck the site's path and the library's web address
The condition is always falseThe expression names another actionMatch the action's name, with underscores for spaces

FAQ​

Isn't there an action for this?​

Yes. The SharePoint connector has Create new folder, which Microsoft describes as creates a new folder or folder path (Microsoft SharePoint Connector in Power Automate). The REST request fits a flow that already talks to SharePoint through REST, and takes the address as plain text.

How do I put the site's path in the address?​

Read it from the site. On a site under /sites/, a GET to _api/web?$select=ServerRelativeUrl returns its path, such as /sites/Finance, and the folder's address is that path followed by /Contracts/2026. The Overtime Timesheet setup flow builds its folder's address this way.

Does this need a premium licence?​

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

Conclusion​

Look for the folder with a GET on rootfolder/folders?$filter=Name eq '<folder name>', and when the value array is empty, POST an SP.Folder with its ServerRelativeUrl to _api/web/folders. The flow then creates the folder once, however often it runs.

Additional Resources​