Power Automate: Creating and updating a document set in SharePoint

Many colleagues have asked me how to create or update document sets with Power Automate. I had never done this before so I told them to use a web service. From now on, I can point them to this blog post. The flow is created with the help of my colleague Jasper Voskuilen, because this web service is a bit more complicated to setup.

Creating the flow

  • Open Power Automate and create a new flow (automation).
  • I created a flow with the trigger, for a selected item.
  • In my situation I get all items from a list and then create a document set for each result.
  • Create the following variables with the related values.
  • This will make the flow more dynamic for later changes.
  • SiteURL as a string, fill in the Site URL.
  • ContentType as a string, fill in the content type id.
  • URLLibrary as a string, fill in the library name part of the ULR.
    For this example it is: Library
https://domein.sharepoint.com/sites/ExampleSite/Library/Forms/allitems.aspx
  • TitleLibrary as a string, fill in the title (name) of the library.
  • WebServiceURLBibliotheek as a string, fill in the Library URL used by the web service.
  • You can find the web service url by using the following URL
https://domein.sharepoint.com/sites/ExampleSite/_vti_bin/listdata.svc/
  • Add the action Send an HTTP request to SharePoint
  • Use the varibles to configure the web service.
  • The name of the document set needs to be unique. I used a value from my list item, your situation might be different.
  • If required you can update the newly created document set.
  • Add the action Parse JSON and parse the Body of the Create Document set HTTP request.
  • Add the action Send an HTTP request to SharePoint
  • Use the variables to configure the web service.
  • The properties you need to set might be different than mine. I used values from my list item but your situation might be different.
Share

17 Replies to “Power Automate: Creating and updating a document set in SharePoint”

  1. Hi Ben, Could you please show what this would look like if we need to update document sets that have already been created? I’m trying to migrate and update some historical document sets and I’m not sure which variables I need

  2. Ben,

    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?

    1. The easier way does not create proper document sets, in classic view they won’t show the documents and the document set welcome page, and both classic and modern view they can not be sorted together with proper (manually created) document sets.

  3. Hey Ben,

    Thanks for compiling this guide, it’s the first one that’s worked!

    I can create a document set but when trying to update the managed metadata columns I’m getting this erro:

    The type SP.ListItemEntityCollection does not support HTTP PATCH method.

    Have you come across this before?

    I’ve tried with two users who are Site Admins and managers of the Term Store. Any insights would be appreciated.

    Cheers,

    Jeff

    1. Hi Jeff,

      Thank you for your kind words.
      My first thought about that error is that you might be using an incorrect URL.
      Are you using a relative URL or absolute? You should be using an relative URL in the URI part.
      I have never encounter this error myself so I am not sure.

      1. Hey Ben,

        I realised that the JSON parse wasn’t passing the ID of the newly created Document Set. Deleting the Parse JSON step and recreating it got past that hurdle.

        Now I have another issue. I’m trying to update metadata columns and I’m getting an error: An unexpected ‘PrimitiveValue’ node was found when reading from the JSON reader. A ‘StartObject’ node was expected.

        The output is:

        {
        “statusCode”: 400,
        “headers”: {
        “Pragma”: “no-cache”,
        “x-ms-request-id”: “e415b89f-508e-b000-f1b5-c0a8f848eef2”,
        “Strict-Transport-Security”: “max-age=31536000; includeSubDomains”,
        “X-Content-Type-Options”: “nosniff”,
        “X-Frame-Options”: “DENY”,
        “Cache-Control”: “no-store, no-cache”,
        “Set-Cookie”: “ARRAffinity=9c9c847b5bd6c73a56d4f1afae4aecaa7f5b746d703be6c728afc87b6c50d7e3;Path=/;HttpOnly;Secure;Domain=sharepointonline-ne.azconn-ne.p.azurewebsites.net,ARRAffinitySameSite=9c9c847b5bd6c73a56d4f1afae4aecaa7f5b746d703be6c728afc87b6c50d7e3;Path=/;HttpOnly;SameSite=None;Secure;Domain=sharepointonline-ne.azconn-ne.p.azurewebsites.net”,
        “Timing-Allow-Origin”: “*”,
        “x-ms-apihub-cached-response”: “true”,
        “Date”: “Fri, 26 Mar 2021 15:40:14 GMT”,
        “Content-Length”: “493”,
        “Content-Type”: “application/json”,
        “Expires”: “-1”
        },
        “body”: {
        “status”: 400,
        “message”: “An unexpected ‘PrimitiveValue’ node was found when reading from the JSON reader. A ‘StartObject’ node was expected.\r\nclientRequestId: 31fac4d3-aa2a-41f2-97af-f9f7ac2fede6\r\nserviceRequestId: e415b89f-508e-b000-f1b5-c0a8f848eef2”,
        “source”: “https:///_api/web/lists/GetByTitle(‘Cases%20002’)/items(76)”,
        “errors”: [
        “-1”,
        “Microsoft.SharePoint.Client.InvalidClientQueryException”
        ]
        }
        }

        The body is:

        {
        “__metadata”: { “type”: “SP.Data.Cases_x0020_002Item” },
        “DMS_x0020_IRN”: “#M107986”,
        “Inprotech_x0020_IRN”: “#M107986”,
        “DocumentSetDescription”: “docsetdescription”
        }

        Any ideas would be appreciated 🙂

        Cheers,

        Jeff

  4. That might be an issue with a choice field, are you using that?
    Try to set an default value for the choice field or remove it if you have one.

  5. Hi Ben
    Have you ever needed to create recurring reminder flows on document sets, based on review dates on documents within the set? I have a large number of document sets, each with a different document owner and each document within each set has different review dates. I have started playing around with simple reminder flows, but haven’t tried it out on any document sets yet.
    Thanks

  6. Hi Jan,

    I have not, but seems like a nice flow to build.
    It looks posisble with flow based on your description.

  7. This has been working great for us for the most part, however I have now started seeing failures of the flow where there are accented / macron characters in the parent folder path (and possibly when the document set to be created has them).

    My slug was:
    Contracts/Māori/Maori |0x0120D520003CC43674804D584D9A5468D5526B3D92020024DB50B71ACEDE45AAE10CA6222671F2
    (I’ve removed the irrelevant portion of the filename/folder). You can see the macron in the parent folder (parent folder exists already), and at this stage of debugging I removed the accent from the name of the document set that was being created.

    The result from SP was:
    Bad Request
    HTTP Error 400. The request is badly formed.

    Once i renamed the parent folder to remove the macron, the code worked successfully.

    Is there a trick to using unicode characters within the path?

    1. I’ve done further research and believe this problem is because the REST call requires the path to be passed in the HTTP headers, however these headers are required / assumed to be encoded in ISO-8859-1 (ASCII), not UTF-8. Use of the macron character “ā” requires Unicode which therefore requires UTF-8 and is unsupported in ISO-8859-1.

      Therefore unless there is some way to tell the SharePoint REST API that the “Slug” header is encoded in something other than ASCII, this API cannot create document sets in a path, or named, using Unicode characters, which is a significant problem.

      I note however that Plumsail Actions does not have a problem with creating document sets with Unicode characters – possibly because this product is developed in Russia where everything is basically Unicode, so it has to work with it. Does this mean that Plumsail Actions is using a different type of API call other than this REST API – or does it know how to tell SharePoint that the Slug is encoded in a different character set?

Leave a Reply to Jeff Christie Cancel reply

Your email address will not be published.