This post will show how to create or add new instance of a Document Set (like adding a new folder) to a SharePoint Document Library using the power automate action 'Send HTTP Request to SharePoint' as a POST request with the URI using the ListItem update method AddValidateUpdateItemUsingPath
Below is code text that shows headers and body format of the http request that will add a new Document Set to a Document Library as a ListItem using AddValidateUpdateItemUsingPath:
POST https://{site_url}/_api/web/lists/GetbyId('{ListIDofDocumentLibrary}')/AddValidateUpdateItemUsingPath
Accept: "application/json;odata=none"
Content-Type: "application/json"
{
"listItemCreateInfo": {
"FolderPath": {
"DecodedUrl": "{YourSiteDecodedURL&PathofParentFolder}"
},
"UnderlyingObjectType": 1
},
"formValues": [
{
"FieldName": "HTML_x0020_File_x0020_Type",
"FieldValue": "Sharepoint.DocumentSet"
},
{
"FieldName": "ContentTypeId",
"FieldValue": "{TheContentIDofDocumentSetContentTypeforDocumentLibrary}"
},
{
"FieldName": "FileLeafRef",
"FieldValue": "{DesiredNameofNewDocumentSetfolder}"
}
],
"bNewDocumentUpdate": false,
"datesInUTC": true
}
Below are screenshot examples of 2 separate http requests which are the same. However, the examples show what a request would look like if filled manually with text while the other is filled with dynamic content.
Below is a screenshot of the http response output once the Document Set is created. It will include the Id number of the newly created Document Set that can be used in following flow steps to get the item if needed.
Table of Contents for This Post:
I wanted to make personnel folders for each of our employees in a SharePoint document library. I decided to use Document Sets instead of generic folders because it could have additional custom metadata column/fields like Full Name and EmployeeID that would be put on any of the files added into the personnel folder (document set).
From what I have searched and attempted in PA; it seems like there were two $free methods for creating a document set.
This method requires that a generic folder be made within the document library and then convert the folder to a content type of a document set by changing the property contentID of the folder.
I don't use this Method 1 of converting a folder to a document set because it appears to have underlying issues and I do not want those causing problems later.
This method uses a http REST request that has a uri and header that put's a lot of identification data together and creates a new document set. The uri will be /_vti_bin/listdata.svc/{DocumentLibraryName} and a header "Slug" with a value of Path/{DesiredNameofNewDocumentSetFolder}|{contenttypeID}. This method is consistent and probably the most commonly used from what I can tell.
I have been making document sets using Method 2 and has been working for me. However, I do not like the method because I could not add metadata to the initial creation. Also, I don't know how long the method will be stable and the "Slug" is not very clear what is happening as an action and has the possibility of changing the name of the document set.
I'm sure I'm not the first to figure this out, but I never found an exact write up, so I'm making this post. Through trial and error I have made an HTTP Request POST to add a new Document Set to a SharePoint Document Library by treating it as a list item instead of a folder by using AddValidateUpdateItemUsingPath.
Usually when you try to create a document set as a folder Microsoft Working with Folders and Files Using REST SharePoint would block the action since it has to treat some of the properties of a document set as a list item instead of a folder. However, using the AddValidateUpdateItemUsingPath for a list item on the list of the document library is a way to work around.
The use of AddValidateUpdateItemUsingPath within an HTTP POST request is primarily used as a way to update a list item without changing the version number. However, if the property ‘bNewDocumentUpdate’ is set to false, then it will create a new item.
We can use this to create a new list item in the document library list so long as some key properties are included within the post request. See the Microsoft Learn section Working with list items by using REST - Create List Item in a Folder
Here are some sites that discuss using AddValidateUpdateItemUsingPath:
The Uri within the http request requires getting the list title or listid and then the endpoint /AddValidateUpdateItemUsingPath. I do not use list titles since I prefer using the ListId to avoid any errors. The Id of a list for a document library is a GUID that can be found in the properties of the document library. Within my flow I get the listId of the list of the document library with a prior http request and put it in a variable. However, you should be able to use either Uri to achieve the same result.
URI: _api/web/lists/GetByTitle('{ListTitleOfDocumentLibrary}')/AddValidateUpdateItemUsingPath
URI: _api/web/lists/GetById('{ListId}')/AddValidateUpdateItemUsingPath
The HTTP POST request body to create a new instance of a document set (like adding a new folder) has a format and some key elements that must be included. Beyond the key elements the post request needs to be formatted correctly with JSON spacing between items and any column names for additional metadata must be named correctly to match the SharePoint field internal name.
The body is separated into 3 parts:
{
"listItemCreateInfo": {
"FolderPath": {
"DecodedUrl": "{YourSiteDecodedURL&PathofParentFolder}"
},
"UnderlyingObjectType": 1
},
"formValues": [
{
"FieldName": "HTML_x0020_File_x0020_Type",
"FieldValue": "Sharepoint.DocumentSet"
},
{
"FieldName": "ContentTypeId",
"FieldValue": "{TheContentIDofDocumentSetContentTypeforDocumentLibrary}"
},
{
"FieldName": "FileLeafRef",
"FieldValue": "{DesiredNameofNewDocumentSetfolder}"
}
],
"bNewDocumentUpdate": false,
"datesInUTC": true
}
There are some key items that have to be included within the request for it to function properly. I will list them below and then follow with a description for each.
This is in the section listItemCreateInfo. This is the location where the new documentset will be added. It is basically the decodedUrl of the site and path of the parentfolder.
If you wanted a documentset added in the rootfolder of a documentlibrary named "MyDocLibrary" the decodedUrl should read "https://sunmc.sharepoint.com/sites/CORP/MyDocLibrary" and the new documentset will show in the main folder of MyDocLibrary after it is created.
If you wanted to put a documentset inside of a subfolder "MySubFolder" of the document library then the decoded Url should read "https://sunmc.sharepoint.com/sites/CORP/MyDocLibrary/MySubFolder" and the documentset will be added into MySubFolder.
This is an easy item that must always show a value of 1 (not "1" text, but just the integer number 1). This identifies the documentset as a File System Object Type of 1-Folder. The values of ObjectType are (0-File, 1-Folder, 2-Web). DocumentSets are considered 1-Folder types.
The FieldName "HTML_x0020_File_x0020_Type" and FieldValue "SharePoint.DocumentSet" showing this is a document set is crucial for this http to function properly. This FieldName and FieldValue should not change since it should be the same default for everyone. This must be included when adding a document set as a listitem.
This field contains the ProgId which is described as "Lookup field to the identifier of a client application that can be used to edit this document." It might be possible to use ProgID in place of this field but I have not tested it. I suspect it would be more difficult since ProgID is a lookup type field and this one is a text.
Surprisingly, the actual column name is "HTML_x0020_File_x0020_Type" which is a Generic List Data Fields .
The ContentTypeId of the documentset must be included in the request so sharepoint knows what contenttype to use. To get the contenttypeId of the documentset you must go to the document library settings and view the content types. You will see the documentset content type you added to your document library, and if you click on it you can see the very long contentypeid in the browser webaddress. To use the contenttypeId in this flow it is best to search for the id in a prior http request by searching contenttypes by name and getting the ContentTypeId to put in a variable that can be put in this POST request.
The FileLeafRef is basically the name of the documentset/folder you are creating. You can't use special characters that are Microsoft Folder and File Invalid Characters since the document set is a folder. This is going to be a required column since all folders need names. This is also different than a Title column. BE ADVISED! Duplicate FileLeafRef are not allowed in a document library. If you create a new documentset with the same name as another folder/docset this will error and not create the item. The http request will continue to attempt until eventually time out without a specific error response.
The property "bNewDocumentUpdate" must be set to false. When this is set to false it will create a new list item. If you have it set to true then it is attempting to update a file as opposed to create a new file. It will error if you use true since the request is in the incorrect format.
The property datesInUTC can be set to true or false. Most likely you want this set to true. If this is set to false, then any dates you are posting into a sharepoint date/time column must be in a text format which is done by converting the date to "MM/dd/yyyy". If datesInUTC is set to true, then you can use the full date/time format that comes from power automate and it will go directly into a SharePoint date/time column. You may need to do some timezone adjustments depending on your data.
The additional metadata fields of your document set such as employeeId’s, special dates, or any other custom columns you want to fill must be written in the correct format to be recognized. This requires using the internal column/field name or the EntityPropertyName of a column field. So if you have a custom column with spaces or special characters in the name, you need to find how sharepoint references the column. This can usually be done by going to the column in the list settings and viewing the name in the browser URL. However, this is also found by getting the Fields of the list using an http request that get’s details of each column/field.
Below are some references showing examples of columns or metadata fields.
Below I am going to show an example flow that I used to create a new document set/folder for employees listed in an excel list. This flow has initial settings/selections that will help get values to populate variables which will ultimately be used in the http post to create a new document set for each employee.
These are screenshots of the Document Library view and the Document Library Settings. You can see the full name of the Document Library, Column Names, and the Document Set ContentType that was added to the library in the Settings.
Below is a screenshot of the fake employees Excel list I'm using to create document sets as personnel folders for each employee.
Below is an overall view of the steps used in my example power automate flow.
The majority of the steps are to help get specific Ids and fill in variables; however, this is not required for the http post create a new document set. You could literally have 1 step which is the http request and somehow manually enter data in the http post request to create a new document set.
1. Initialize Variables - These are variables that will hold specific info to be used in the flow such as ListId or ContentTypeId - (None of the variables are set when initialized, they will all be set/filled later in the flow.)
2. Settings to Select Parent Folder and Name of Content Type
3. Scope A - This gets the Site Address and DecodedUrl so it can be used in the flow and the DecodedURL can be used as part of the path to create the new document set.
4. Scope B - This uses the Set1 selected folder to get specific properties which can identify the document library and list of the document library.
5. Scope C - This will get the list of the document library and set the ListId that will be used in the Uri
6. Scope D - This will use the ContentTypeName from Set3 to find the ContentTypeID for the list
7. List Rows Present in Table - This is the source data list of employees that will be used to create document sets for each employee.
8. Apply to Each Excel Row - This is the section where the document set is created and then the response of the http request is parsed to get the new ItemId of the created document set.
Below are detailed screenshots of the example flow steps:
When the flow is run and the http post to create a new document set is completed, it will automatically have a response to the http request within the flow. This response contains the Id of the newly created document set. The Id is the unique interval item number that every item in a list has when it is added (this is not the uniqueId which is a full guid format).
The http response will have all of the fields that were originally included as well as the Id field. This must be parsed out of the JSON response so the Id can be used in following flow steps. The Id is in a text format when it is parsed out and must be converted to a number format to be used correctly.
Below are the results of running the flow and adding document sets to the Document Library:
Below are some select outputs of the example flow to show items that were used in the http request like DecodedUrl, Parent Folder Path, and ContentTypeID:
Below is an output of the http request that created a new document set. All of the fields that were included in the request are returned with the response, and it now includes the additional "Id" field which contains the list item integer Id of the document set.
This method of creating a document set using an http request and AddValidateUpdateItemUsingPath is not a massive change or easy button over the method that uses a "Slug" header. However, there is benefit of being able to add metadata with the initial creation. Also, if someone is clever enough I'm sure they could make some form of batch requests and then prevent the apply to each needed in my example for each row in excel.
If you have any feedback or notice there could be a problem with creating document sets with this method please add a comment to let us know. The convert folder to document set method seemed viable until others left comments about potential issues. So please don't hesitate to add some input.
Thanks 👋
Solved! Go to Solution.
I made the post and consider it solved.
Below is code text that shows headers and body format of the http request that will add a new Document Set to a Document Library as a ListItem using AddValidateUpdateItemUsingPath:
POST https://{site_url}/_api/web/lists/GetbyId('{ListIDofDocumentLibrary}')/AddValidateUpdateItemUsingPath
Accept: "application/json;odata=none"
Content-Type: "application/json"
{
"listItemCreateInfo": {
"FolderPath": {
"DecodedUrl": "{YourSiteDecodedURL&PathofParentFolder}"
},
"UnderlyingObjectType": 1
},
"formValues": [
{
"FieldName": "HTML_x0020_File_x0020_Type",
"FieldValue": "Sharepoint.DocumentSet"
},
{
"FieldName": "ContentTypeId",
"FieldValue": "{TheContentIDofDocumentSetContentTypeforDocumentLibrary}"
},
{
"FieldName": "FileLeafRef",
"FieldValue": "{DesiredNameofNewDocumentSetfolder}"
}
],
"bNewDocumentUpdate": false,
"datesInUTC": true
}
Below are screenshot examples of 2 separate http requests which are the same. However, the examples show what a request would look like if filled manually with text while the other is filled with dynamic content.
I made the post and consider it solved.
Below is code text that shows headers and body format of the http request that will add a new Document Set to a Document Library as a ListItem using AddValidateUpdateItemUsingPath:
POST https://{site_url}/_api/web/lists/GetbyId('{ListIDofDocumentLibrary}')/AddValidateUpdateItemUsingPath
Accept: "application/json;odata=none"
Content-Type: "application/json"
{
"listItemCreateInfo": {
"FolderPath": {
"DecodedUrl": "{YourSiteDecodedURL&PathofParentFolder}"
},
"UnderlyingObjectType": 1
},
"formValues": [
{
"FieldName": "HTML_x0020_File_x0020_Type",
"FieldValue": "Sharepoint.DocumentSet"
},
{
"FieldName": "ContentTypeId",
"FieldValue": "{TheContentIDofDocumentSetContentTypeforDocumentLibrary}"
},
{
"FieldName": "FileLeafRef",
"FieldValue": "{DesiredNameofNewDocumentSetfolder}"
}
],
"bNewDocumentUpdate": false,
"datesInUTC": true
}
Below are screenshot examples of 2 separate http requests which are the same. However, the examples show what a request would look like if filled manually with text while the other is filled with dynamic content.
What about action 'Create new document set' in SharePoint Connector ?
https://learn.microsoft.com/en-us/connectors/sharepointonline/#create-new-document-set
https://learn.microsoft.com/en-us/connectors/sharepointonline/#create-new-document-set
Thanks for showing that. It is a new connector that was added sometime after January 20, 2023. I don't know when it was added since I can't see any kind of history like that, but I know it wasn't available in January from checking the learn site history.
It had to come out rather recently, and honestly I wasn't looking for it.
I'll make an instruction reference for the simple connector.
Looks like all my work is now obsolete ☹️
But at least we have an easy connector now 😀
Your hard work is greatly appreciated. I don't think it is obsolete because the connector only lets you create an out of the box document set. I was able to use your helpful information to create my custom document sets. Thank you SO MUCH for sharing!!!
Thank you for this post. It helped me creating docsets with a dynamic url. Hope you can help with the following. How can I extract the ID of the docset so that I can use it in other actions?
Thank you in advance for your time!
Hi @Pearple
The steps to get the ID are in the original example photos above. If you look at the actions that follow "Send an HTTP request to SharePoint POST Add New DocumentSet" you can see they are about getting the ID of the new document set and putting it into the variable.
It is basically using Parse JSON on the HTTP Request that was used to create the new Document Set
The final HTTP request in the example is just to show using the ID of the document set in a new HTTP request. But you could use the variable anywhere.
Here are the details of the steps below:
The Schema used in the Parse JSON is below:
{
"type": "object",
"properties": {
"d": {
"type": "object",
"properties": {
"AddValidateUpdateItemUsingPath": {
"type": "object",
"properties": {
"__metadata": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"results": {
"type": "array",
"items": {
"type": "object",
"properties": {
"ErrorCode": {
"type": "integer"
},
"ErrorMessage": {},
"FieldName": {
"type": "string"
},
"FieldValue": {
"type": "string"
},
"HasException": {
"type": "boolean"
},
"ItemId": {
"type": "integer"
}
},
"required": [
"ErrorCode",
"ErrorMessage",
"FieldName",
"FieldValue",
"HasException",
"ItemId"
]
}
}
}
}
}
}
}
}
These are the steps below that use that Parse JSON to finally get the ID into a variable.
Let me know if this works for you,
Thank you for your quick response! I'm having trouble with converting the FieldValue Id to integer.
The body of the Select action to get the Id is:
It looks like FieldValue is replaced by "76"?
It is difficult to tell which Select action you are referring since I have 2 select actions in the example I made for you. But I think you have something backwards or selected out of order.
You want to Select the results from the Parse JSON and
Map the FieldName to FieldValue
Also, it seems like we are in different languages, so there might be some confusion with how my instructions or pictures are being translated.
Thank you, but I can't get it to work.
I'm referring to action 'Select the Fieldvalue to get the Id value of the new Document Set'.
Output of filter array
output of action 'Select the Fieldvalue to get the Id value of the new Document Set'.
The value of Fieldvalue is blanc, while "Fieldvalue" is replaced bij the value.
I can't figure out what is going wrong.
Good Morning @Pearple , I think I can see the issue you are having.
You need to change the Select action so that the Map field is a single box. The Map field can be changed from the Key Value Mode which has two boxes. You want the Map to be in Text Mode which is a single box.
You can change the mode by clicking the icon next to the Map field.
When the Select action Map field is in Text Mode there will be a single box where you can enter the expression item()?['FieldValue'] so that there is just a single value instead of a split column.
Do this and the output will only have "87" in the result instead of "87":""
Let me know if this works for you,
Do Not click Accept as Solution. Accepteer niet als oplossing. (Please do not click Accept as Solution button for any of my responses to you @Pearple . I made the original post as a reference for creating an HTTP request. I also made a Solution for the original post. If you mark one of my replies to you as a solution it will move that response up to the top of the original post. I do not want that to happen.)
@Pearple I'm not sure if this will be helpful to you, but this is a screenshot of how I got the ID after the http action that creates a document set (thanks to this very helpful post by @wskinnermctc).
Dear Community Members, We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd. During this period, members will not be able to Kudo, Comment, or Reply to any posts. On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities. What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!
We are excited to announce the Summer of Solutions Challenge! This challenge is kicking off on Monday, June 17th and will run for (4) weeks. The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities. Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”) - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024 Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods. You must enter into each weekly Entry Period separately. How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different. Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers. At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing. Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner. A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random. Individuals will be contacted before the announcement with the opportunity to claim or deny the prize. Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners. Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event. ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE** Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24 17 @Anil_g 7 @ManishSolanki 13 @eetuRobo 5 @David_MA 10 @VishnuReddy1997 5 @SpongYe 9JhonatanOB19932 (tie) @Nived_Nambiar 8 @maltie 2 (tie) @PA-Noob 2 (tie) @LukeMcG 2 (tie) @tgut03 2 (tie) Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate @Deenuji 12@ManishSolanki 19 @Anil_g 10 @NathanAlvares24 17 @VishnuReddy1997 6 @Expiscornovus 10 @Tjan 5 @Nived_Nambiar 10 @eetuRobo 3 @SudeepGhatakNZ 8 Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22 Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2 Anil_g2 SharonS2
On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners. The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights. Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.
We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for. We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer. Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together. Here's to new beginnings and endless possibilities! If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport. To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages