none
Create document set with REST API?

    질문

  • Hey there

    My main goal is to create & update a document set (containing custom fields) with Microsoft-Flow. I managed to create a document set already based on this article, but I'm having troubles setting the properties when creating it.

    I really don't know how I need to declare the following part of the blog

    var docSetOptions = {
    ‘Title’: myTitle,
    ‘Path’: ‘/Documents’,
    ‘ContentTypeId’: contentTypeId,
    ‘ContentType’: contentType
    };


    to add it to a variable in Microsoft-flow. I've tried "Data Operations - Select", "Data Operations - Compose" as well as "Initiate Variable" and set the type to "Object". Nothing seems to work.

    Therefore, does anyone know how I can create a document set and add metadata at the same time?



    • 편집됨 lemex 2018년 6월 14일 목요일 오전 9:31
    2018년 6월 13일 수요일 오후 12:20

모든 응답

  • You need to use : listdata.svc

    function getListUrl(webUrl,listName,success, error) 
    {
        var headers = {};
        $.ajax({       
           url: webUrl + "/_api/lists/getbytitle('" + listName + "')/rootFolder?$select=ServerRelativeUrl",   
           type: "GET",   
           contentType: "application/json;odata=verbose",
           headers: { 
              "Accept": "application/json;odata=verbose"
           },   
           success: function(data){
               success(data.d.ServerRelativeUrl);
           },
           error: error
        });
    }
    
    function createFolder(webUrl,listName,folderName,folderContentTypeId, success, error) 
    {  
        getListUrl(webUrl,listName,
          function(listUrl) {
              var folderPayload = {
                 'Title' : folderName,
                 'Path' : listUrl
              };
    
              //Create Folder resource
              $.ajax({
                    url: webUrl + "/_vti_bin/listdata.svc/" + listName,
                    type: "POST",
                    contentType: "application/json;odata=verbose",
                    data: JSON.stringify(folderPayload),
                    headers: {
                       "Accept": "application/json;odata=verbose",
                       "Slug": listUrl + "/" + folderName + "|" + folderContentTypeId
                    },
                    success: function (data) {
                        success(data.d);
                    },
                    error: error
              });
          },
          error);
    }
    
    
    function createDocumentSet(webUrl,listName,folderName, success, error)
    {
       createFolder(webUrl,listName,folderName,'0x0120D520', success, error);
    }

    Here are the examples:

    https://sharepoint.stackexchange.com/questions/114882/is-it-possible-to-create-a-document-set-using-rest-api

    https://stackoverflow.com/questions/46322396/create-document-set-with-rest-in-sharepoint-online


    Avijit Sur

    2018년 6월 13일 수요일 오후 12:59
  • Hi Avijiit

    Thanks for your answer. Though, I'm not sure if you read my question completely. I am able to create a document set with listdata.svc, but I also would like to update some metadata during the creation process. I'm struggling with how to do that in Microsoft Flow, respectively, how to transform the following array to MS Flow:

    var docSetOptions = {
    ‘Title’: myTitle,
    ‘Path’: ‘/Documents’,
    ‘ContentTypeId’: contentTypeId,
    ‘ContentType’: contentType
    };
    • 편집됨 lemex 2018년 6월 13일 수요일 오후 1:08
    2018년 6월 13일 수요일 오후 1:02
  • As per my knowledge, you cannot do this in one request. You need to split the request into two.

    With first request you create the documentset.

    And with second request, update the metadata of that documentset.


    Avijit Sur

    2018년 6월 13일 수요일 오후 1:38
  • Hi Avijit

    Are you saying it's not possible to do that with one request in flow or generally it is not possible?

    • 편집됨 lemex 2018년 6월 14일 목요일 오전 5:16
    2018년 6월 14일 목요일 오전 5:15
  • Hi,

    In the Microsoft Flow, we can add a Initialize variable action("Jsonpayload") and using the String type to store the update data, and then in the HTTP action body, convert the variable to Json using json(variables('Jsonpayload')).

    Here is a blog for your reference:

    PowerApps, Flow and Managed Metadata fields

    http://www.cleverworkarounds.com/2017/10/20/powerapps-flow-and-managed-metadata-fields-part-3/

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    2018년 6월 14일 목요일 오전 8:16
    중재자
  • Hi Dennis

    Thanks - that helps me get closer to the solution.

    I just couldn't figure out yet on how to integrate that successfully into the "slug".

    I created a variable including the Jsonpayload as explained by you. I then had to create a second variable which converts the variable to json as I think adding it to the body of the rest request seems wrong (I also tried that, but it didn't work).

    After that, I tried to include it in the slug without success.


    If you know what I'm doing wrong I'd be happy to know.

    Cheers

    2018년 6월 14일 목요일 오후 12:18
  • Hi,

    Why did you use "Slug" in the Headers in the HTTP requests?

    If you pass the data, please add JSON data to the Body.

    Check the article below to get more helps, this article contains how to use POST in HTTP action.

    http://www.cleverworkarounds.com/2017/10/20/powerapps-flow-and-managed-metadata-fields-part-3/

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    2018년 6월 15일 금요일 오전 9:17
    중재자