Why?
At the moment there are no out-of-the-box Microsoft Flow actions regarding the Document Set. Now the Document Set is going Modern: let us go Old School! 🧓
What?
This post will explain step-by-step how you can create a Document set in a SharePoint Online library by using the Send an HTTP request to SharePoint action of Microsoft Flow. These calls are based on the SharePoint REST endpoints where a lot of documentation on can be found here:
Basics on SharePoint REST service: https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/get-to-know-the-sharepoint-rest-service
SharePoint Foundation REST Interface: https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ff521587(v%3Doffice.14)
SharePoint Object Information: https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-visio/jj246089(v=office.15)
How?
Let me warn you up front that I like variables a lot 😉.
1) First remember to activate the Site collection feature called Document set as explained in my post earlier https://knowhere365.space/add-the-sharepoint-document-set-to-a-site/ .
Then I suggest to create a Child content type of the default Document set, because the default Document set created by the SharePoint Site Collection itself is inernally named depending the language (I believe of the Site Language). So in Dutch it is named Documentenset but in English it is Document set and because we need the exact name for HTTP requests, I recommend creating an own content type based on the default document set so you know for sure what the exact naming is.
2) When you have a site with a library in which you have added your Document set content type we will create a Microsoft Flow starting with some useful variables. You need to initalize every variable in the main stream of the Flow (variables can not be initialized within Conditions, Apply to each loops et cetera)
before you can use them in the rest of the Flow:
- varWebUrl = link of the site you want to create automated Document sets in ending with / (My site URL is [name of your tenant].sharepoint.com/SC/DocumentSets/)
- varDocLibName = URL naming of the library in which the Document sets are present. It would be wise to not use spaces or any other strange characters but if you do start every word in the new name with a capital letter; there is a hidden name that SharePoint gives to lists and libraries with spaces in the name. You can check these names by accessing the <varWebUrl>/_vti_bin/ListData.svc REST service.
- varDocLibNameClean = this variable will be relevant when the display name of your library is different from the name you gave it upon creation. We just strip the spaces from the previous variable. Otherwise you will get a failed Flow with the notification “BadGateway“.
- varListEntityTypeName = this variable will be relevant when the display name of your library is different from the name you gave it upon creation (the internal list name visible in the URL). Otherwise you will get a failed Flow with the notification “Resource not found for the segment…”.
- varDocSetCtName = Name of the content type you are using for the Document set (I created a Child content type DocumentSetCustomized)
- varContenttypeID = content type ID of your Document set (we will get this from within the Microsoft Flow because this ID could be dynamic)
- varAcceptHeaderString = a default string I reuse when I create a flow with multiple HTTP requests (the string is application/json;odata=verbose)
- varListGUID = the GUID (unique ID) of the Library with the desired Document set (we will also get this from within the Microsoft Flow later on so the flow is reusable)
- varDocumentSetName = Name of the new to be created Document set. Because a Document set is a folder 🤫 that just inherits data to its content, this piece of information needs to be an unique string without any special characters. I combine some data from the process to create something unique #BeCreative but because users will be confronted with this naming in the library itself also be clear.
3) The first request is the request to get the GUID of the Library:
The code for the call =
/_api/web/lists/getByTitle('@{variables('varDocLibName')}')
We want to store the GUID coming from this rest call in the corresponding variable earlier. Because the Microsoft Flow gets a set of data (array) from this post we can directly get data from that call using the following syntax =
@{body('Send_an_HTTP_request_to_SharePoint_-_ListGUID')['d']['Id']}
Note that this is the naming of HTTP request where the spaces are replaced by underscores. When we paste this code in a Set variable action it will look like this:
‼ When the display name of the library is different from the internal name we will also set the varListEntityTypeName variable:
@{body('Send_an_HTTP_request_to_SharePoint_-_ListGUID')['d']['EntityTypeName']}
‼ When the display name of the library contains spaces or other strange characters we need to set a varDocLibNameClean variable:
@{replace(replace(variables('varDocLibName'),' ',''),'_','')}
4) Then we can get the Content type of ID of the Document set of this specific library:
The code for the call =
_api/web/lists(guid'@{variables('varListGUID')}')/contenttypes?$filter=Name%20eq%20%27@{variables('varDocSetCtName')}%27
Again (but now a little bit more complicated because this request gets multiple results) we can directly get data from this call using the following syntax and put this data in the variable varContenttypeID for later use =
@{first(body('Send_an_HTTP_request_to_SharePoint_-_GetDocumentSetInfo')?['d']['results'])?['StringId']}
5) Now we can create a Document set with the last request:
The code for the call =
_vti_bin/listdata.svc/@{variables('varDocLibName')}
The special Header in this request is the Slug:
concat(variables('varWebUrl'),variables('varDocLibName'),'/',variables('varDocumentSetName'),'|',variables('varContenttypeID'))
‼ Depending on if you followed the advise on not using spaces or strange characters in the URL naming of the library you may need to replace varDocLibName with varListEntityTypeName or with varDocLibNameClean in one or both of the calls above.
This combines all the variables above to create a Document set:
If you managed to get this far, your journey in Document sets with Microsoft Flow has started. The real business scenario’s can be much more complex (check if set already exists, update of the set metadata and so on) so I will keep posting about these possibilties the coming weeks 👍
Hi Django Lohn, Thanks for sharing this great information, I took all the steps and it worked, but I have a problem that I can’t solve, when I create a file inside the documentset it doesn’t inherit the main metadata. This only happens with the documentset created from powerautomate, when I do this same process manually, if it manages to inherit the metadata. Any idea what that might be?
Hi Julian,
I know that you need to configure the Document Set settings that determines which properties inherit to the sub-documents. If you have only one Document Set Content Type in the library and it works with manually created document sets –> this should be ok…
Are you able to confirm that the document set created with Power Automate actually is the right content type? I do not see this behavior in my Test Document Library so could be configuration / power automate creation issue?
Hi! I used the the process above and it worked wonderfully, but now I have recently started receiving a 409 error. Have you seen this error before? I might have changed something in the library but I am not positive what it was, but I do not understand why that would change being able to create an item with the flow still. Thank you in advance!
Hi sk,
Could it be a name change in Content Types?
I posted a comment earlier and I found my error. I grabbed the content Type ID from the site and not the library. The extra octet of data created the error.
Thank you for sharing Kevin! 💪👍
Using your method it appears that I have created a docset, with 1 exception. If I use the URL directly to the item, i.e “http://mysiteurl/libraryName/ItemName” the url is appended with “Forms/AllItems.aspx?…” which is folder view not the docset view which has the URL appended with “Forms/Contract%20Folder/docsethomepage.aspx?…” and additional variables than the folder view. Is this something that can be addressed with additional steps in PowerAutomate?
Hi Django,
Thanks for the post and I hope you can respond!
This way of using the Send an HTTP Request to SPO to create Document Sets is well covered by so many.
Though I wanted to check if it actually delivers what the OOTB New > Document Set option in the library does?
I’ve used your method from above via Power Automate. It creates the so called Document Set in the library successfully. This visually at first glance looks like a document set, but when you check the details panel for it, it appears to show up as a ‘Folder’ type and not Document Set. Within the library view, one can see the Document Set icon on it but not in the details pane.
Also, when checked in classic view to verify, this shows up as a folder and no welcome page of document set shows up etc.
I’m just wondering if people are actually checking it completely under the Details pane and seeing a “Folder” type shown in there? And not Document Set as the type.
Look to hear from you – Thanks in advance!
Hi SP,
I can confirm that the icon in the details pane of the Modern Experience is not the same icon as in the library. However when moving to Classic Experience, I do see a (classic) Document Set Icon and when clicked I do see a Classic Document Set welcome page. Are you sure you have enabled the Document Set Feature in the Site?
Did you also see my tip in one of my posts to ALWAYS create a custom Document Set Content Type with your own name to avoid language translation issues?
Hello,
I am getting Bad gateway error for document set creation.
Below is the slug
https://Site/DeliItemCreation/274493|0x0120D52000EADFE72343E8E14FA83750D6AAAFC94000176945CBE4BEF346AA09587DE8773FFA
Library Name: DeliItemCreation
DocSetName: 274493
Same flow works fine for another library with same content type on another site. But on this site it runs for long time with all other actions are green and then fails with Bad Gateway error.
I compared both the library and content type, everything is same.
Please provide some pointer to fix this. I have been scratching my head since 1 week.
Thanks,
Prafull
Hi Prafull,
A lot that can go wrong in HTTP Requests so a lot to check.
I copied an existing flow last week and the second flow also gave me a bad gateway –> it seemed I did not change the Site URL so the second flow was posting to the first site where the Document Set was already existing.
Another customer of me, changed the All Items view where the existing item was filtered out –> took me an hour to discover that the item was already existing, but it was not showing up in the view.
I recommend to post your question here: https://powerusers.microsoft.com/t5/Microsoft-Power-Automate/ct-p/MPACommunity
Add as much details on your situation as possible with screenshots and expressions you are using.
You can tag me (@Django) and I will definitely help you there. The advantage of the community forum is that other experts will also help 👍
Hello, i can only run the Flow once successfully. Then when i change the DocSetname Variable , save flow and run it again the i beomme “badgateway Error”.
“message”: “BadGateway”, HTTP 502
“body”: {
“error”: {
“code”: 502,
“source”: “flow-apim-europe-001-northeurope-01.azure-apim.net”,
“clientRequestId”: “568b42d2-e948-488a-a2cb-8cb5b942bc6b”,
“message”: “BadGateway”,
“innerError”: {
“status”: 502,
“message”: “An error occurred while processing this request.\r\nclientRequestId: 568b42d2-e948-488a-a2cb-8cb5b942bc6b\r\nserviceRequestId: a223ac9f-100a-2000-a1d2-0cd903602f4f”,
“source”: “https://xxx.sharepoint.com/sites/eAkte_SPO/_vti_bin/listdata.svc/Dossier”,
“errors”: []
}
…
{
“Accept”: “application/json;odata=verbose”,
“Slug”: “https://xxx.sharepoint.com/sites/eAkte_SPO/Dossier/kombozz03|0x0120D52000910B13F93B65B44C99E2B95481248DCF01006AF3CDBC923E0B4E8F0A09E3F19017B9”
}
ohhh …Sorry i found it. My ContentType Column the reason .
Thanks alot Mate. Very good
Haha very good!
Thank you for sharing 💪👍
Django – I had my flow running using this logic and it started giving me BadGateway. I have run the Send HTTP Request in another flow nearly 1000 times and I cannot figure out why I am getting the BadGateway now.
My document library is ‘Course Documents’ with the Uri being _vti_bin/listdata.svc/CourseDocuments. Here is the original slug:
https://scmed.sharepoint.com/sites/CMEOrganizer/Course%20Documents/Course Documents for 2341|0x0120D520006001E5C9AEC1574F9A6BE72331EE619500F60BEB9EC4232F4AB3A49C77E57F938B
I have tried the following w/o success:
https://scmed.sharepoint.com/sites/CMEOrganizer/CourseDocuments/Course Documents for 2341|0x0120D520006001E5C9AEC1574F9A6BE72331EE619500F60BEB9EC4232F4AB3A49C77E57F938B
https://scmed.sharepoint.com/sites/CMEOrganizer/Course_x0020_Documents/Course Documents for 2341|0x0120D520006001E5C9AEC1574F9A6BE72331EE619500F60BEB9EC4232F4AB3A49C77E57F938B
Hi Brandt,
Looking at your data you have different URL name and Display name of the document library –> this means you have a lot of options to walkthrough. In some calls you need ‘CourseDocuments’, in other calls you need ‘Course Documents’ in other calls you need ‘Course_x0020_Documents’…
I tried to add some info about this above but depending on your scenario, the options to walkthrough are too many. Also try https://powerusers.microsoft.com/t5/Microsoft-Power-Automate/ct-p/MPACommunity to post your help question and other experts will also help with your specific scenario. Feel free to mention me in your Community Post 👍
Hello Django!
This is great article. I walked through the steps and it works for me. But for another site it created a folder instead of Document Set, I tried to figure it out but didn’t find the cause of it.
I’m using logic Apps to created Doc Set in SP 2019 through Azure on premises data gateway.
Could you please help me identifying why it works for one site and the other on it creates Folder not Doc Set.
Appreciated! Thanks!
Hi Mohammed, are you able to create a Document Set in the concerning site manually?
(this is to verify that alle Site (Collection) Settings have Doc Sets enabled)
If so: can you check if the Content Type ID / Content Type Name is aligned with what you want to create?
(language settings may also influence the naming of default content types)
Could you please elaborate more about
“can you check if the Content Type ID / Content Type Name is aligned with what you want to create?”
Hello Django!
I checked the Content Types and there was a mismatching. When I had sent the right content type Id, It has worked perfectly.
Appreciated! Thanks!
I’m pretty close to getting this done but the final challenge seems to be that I can’t use dynamic content from a SPOL library as part of the create DocSet action. From what I can see when using the Output function everything looks right and if I manually type in an DocSet Name number to be used it creates the DocSet as desired. The format for all the DocSet Names is “MP-20-0001”, without quotes. Apparently it has something to do with using dynamic content…which is a must. Any help is solving this issue would be most appreciated as I have several of these to create.
Hi Daren,
Every Document Set is like a Folder so each folder should have unique name.
Maybe you can use an incremental numbering or a date-time stamp in the naming convention?
Have a look at the https://knowhere365.space/microsoft-flow-handy-expressions/ for the Formate Date Time Stamp.
I’m hoping someone might have a suggestion for me. My power automate flow makes document sets successfully following the approaches mentioned above. However one thing is not working. I have turned on document IDs and if I make a document set in the library itself it creates the document ID just fine. But a document set created from the flow does not create a document ID. Can anyone suggest where I might look to solve this problem?
Hi Jim, I honestly cannot point in you in the rigt direction at the moment. But I will definetely do some testing on my side and search online for similar issues…
I know that there is also a backend process that assigns Document IDs –> could it be that the Document ID is assigned with a delay?? (maybe a day or a week later)
Keep us posted!
In some more testing it looks like it won’t take any special characters. In my case the DocSet name format looks like MP-20-0001 so I’m thinking it’s the “-“. I guess if I could figure out how to strip out the dashes from the dynamic content and put it into a variable that may work. Thoughts?
I got it working! Have to remove special characters and I used the Replace function to do so and now it works!
Haha great! Thank you for updating us! 👍🏼💪🏼
Hi Django, thanks for this great tutorial. This enables me to use the same flow for multiple custom PowerApps forms because of the modular concept using variables.
I already had my content type created and used the original document set so did not follow your advice. Big mistake. After a lot of testing and head scratching I can now clarify on your assumption that the name is dependent on the site language. It’s not. It’s worse. It’s dependent on the user language. Took a while to figure out why the exact same request worked once and then stopped working in my second try until I discovered that the difference was between the two user accounts I used.
Wow Thomas!
That is some valuable information -> thank you for sharing with us 👍💪
Thank you so much for posting all of this extremely valuable information. I have created multiple custom content types (project deliverables) all built off of document sets and I am trying to figure out a way to create them using a flow. I’ve been forced to use a power app rather than the standard sharepoint form and I currently can’t create new deliverables. I understand this is a little outside of what your original post was about but I figured I’d give it a shot. Thanks again for sharing!
Hi Michael,
Good to have you here!
So from what I understand you want to create Document Sets from within a Canvas App that is tied to a SharePoint List?
You should be able to follow my blog posts in setting up a Power Automate Flow to create Document Sets and then link your Power App to the new Flow: see https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/using-logic-flows
It turns out my issue was being caused by a column validation, not by the method. Now everything is working on my custom content perfectly. Thanks for the valuable information and for replying so quickly a year after the original post!
Hi Django,
I am getting a the following error on step 5. Resource not found for the segment ‘BI_x0020_Working_x0020_Files’. I am using a global content type, not a site specific one.
Do you have any ideas why this might be failing?
Hi Sean,
Based on your info provided, my guess is that you are not using the exact naming of
– the library you are creating a DocSet in
OR
– the content type you want to create.
See the variables section where I try to explain all possible sitations. Because there are so many steps it could by a very small mistake so I can only ask you to double check every step (especially exact namings and exact interpunction).
Hi Django,
So I may a new DocLib, and it appears something about the space didn’t work out properly. I tried all of the options provided and wasn’t able to make it go. ?Using the secret MSoft name of the DL resulted in a fail at step 3, whereas using the different options for step 5 result in a fail there.
Using a DL with no spaces results in a success.
Sean
Can you show one example of how you initialized the variables?
Hi Hetal,
I added a screenshot at the start of Step 2 but understanding Variables is definitely something you want to get the hang of before creating the more complex Flows and starting with HTTP Requests. Maybe the Microsoft Learn modules about Power Automate can help you with this? See https://docs.microsoft.com/en-us/learn/modules/build-more-flows/
Nice one 🙂
Sort of reminds me of trying to be clever as a kid aand being too quick with Lego set instructions only to find that later it aint working!
Haha sounds familiar!
Good for clarification though 👍🏼
Hi! This has been a really cool tutorial and i would love to figure it out. I am already brainstorming a few cool things i could try to make with it. My problem is that the last step (HTTP Post to sharepoint for CreateDocumentSet) is not going through.
If i go into the debugger while the flow is running, all steps are “green checked” and succeeded except the last POST HTTP request which is still running (20 mins now). Clicking in to see what happened, it has a small yellow bar at the top of the block that says “w retires occured” with the option to view them. When i view the duration is 0 seconds and the Status is “BadGateway”.
My Uri is…
_vti_bin/listdata.svc/PersonnelMasterList
My header is…
{
“Accept”: “application/json;odata=verbose”,
“Slug”: “concat(variables(‘varWebUrl’),variables(‘varDocLibName’),’/’,variables(‘varDocumentSetName’),’|’,variables(‘varContenttypeID’))”
}
Any thoughts?
Hi Nolan, sometimes when you copy from browsers the single quote ‘ becomes an apostrophe ’ –> from my experience this is the first thing to check. Let us know 👍
Hi Django,
Thanks for your gr8 tutorials.
Been struggling with this onme. Getting ‘Bad Gateway’, not caused by apostrophes.
If i omit this part of the slug “,variables(‘varContenttypeID’)”, it works(but creates an unknown content type) however when using the contentTypeId i get the error.
Here is my generated slug;
{
“Accept”: “application/json;odata=verbose”,
“Slug”: “https://secret.sharepoint.com/sites/VRTErrors/202007081548_306_|0x0120D520008896FD28C344B648BC94E647EE61783C003480535FAF904441A41FE4A382D7554D”
}
Hi Terry,
Great to have you here!
Does the error give any other info maybe in the outputs of the erroring action?
Based on your info I see:
a site VRTErrors
a library 202007081548_306_
Where is the name of your document set? Or if 202007081548_306_ is your document set name then where is your library?)
Look at my example: https://secret.sharepoint.com/SC/LibraryWithSets/Set_11|0x0120D52000AFDB523DBB0927479436879787BBB6BD007C1F20D23F1243439033EAE3999DD5A8
Ah – in that case there is a slash missing from your slug example from the tutorial above 🙂
There should be a slash beetween site and library according to your reply.
Do you mean in my concat function for the slug??
concat(variables('varWebUrl'),variables('varDocLibName'),'/',variables('varDocumentSetName'),'|',variables('varContenttypeID'))
I did not put it in there because my first variable (varWebUrl) already ends with / according to the instruction ☺️
I’m using this process and it’s working great to create the document set, but it ISN’T creating the new default file I set for the document set. If I manually create a document set on the same library the file is generated, but I need the flow creating the document set to generate the file too. Any ideas?
Hi Django, just following up to see if you have any insight on this issue 🙂
Sorry for my late reply!
I tried to test and I indeed do not see predefined default content of a Document Set being created when the Document Set is being created this way. This means that you are more in control because this gives you the flexibility to predefine content for manual creation but create other default content for this automatic creation.
It just means you have extra work to create the default content in your flow. Hopefully you can use one of the default actions to copy or create documents within the Document Set?
Hi Django,
This post is great. I could able to add new document set using this flow. But I’ve a query. Suppose we’ve multiple fields associated with document set other than document set name. With this flow, I could able to provide document set name during document set creation. How can I be able to provide values for other fields?
Please assist.
Thanks,
Kunal
Hi Kunal,
I’m glad this post helped!
You cannot create the set and update properties in one action through this method. You will need to add a second action as explained here: https://knowhere365.space/microsoft-flow-update-sharepoint-document-set/. Depending on the type of property you want to update, the complexity grows but within one update action you should be able to update all types of properties.
Can you please post on how to check for existing document set , I have tried by using list folder but not worked
Hi Anurag, because the CreateDocumentSet action fails if a Document Set already exists, the shortest way is to split the flow after this action using Add a parallel branch and the Configure run after settings in the first actions of the parallel branches. One branch will run after the CreateDocumentSet action “is succesful“, the other branch will run after “has failed” / “is skipped” / “has timed out“.
Dear Django,
Thanks so much for your reply. I am still getting failed if you just upload some screenshot as a reference will be grateful
Sure! Hopefully a screenshot will be enough oherwise I am more than happy to have a short Microsoft Teams call to explain so I can improve my blog post. The parallel branch after an action that can fail:
Super thank you for your description
JLuc
Hi Django,
I am trying to do the same thing but with custom folder, it will be great to give me some guide line to accomplish that.
Best Regards
Ben
Hi Ben, using REST you can check the “Working with folders”-section on the page of Microsoft: https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest.
But also please check out the default SharePoint action in Power Automate that can do this: “Create new folder”.
you are a lifesaver, I was making a Powerapp and could not figure out how to make new items.
Thanks to you I might just make my deadline.