0

Hi i am trying to create documentset and set the properties from a webpart. I can create the document set

private async _CreateFolder(webUrl,listName,folderName,folderContentTypeId,folderPayload, 
itemProperties): Promise<void> {
           var ServerRelativeUrl = "/sites/mySite/myrepo" ;

            var resultData: any =  await jquery.ajax({
                                    url: webUrl + "/_vti_bin/listdata.svc/myrepo" ,
                                  type: "POST",
                                  contentType: "application/json;odata=verbose",
                                  data: JSON.stringify(folderPayload),
                                  headers: {
                                            "Accept": "application/json;odata=verbose",
                                            "Slug": ServerRelativeUrl + "/" + folderName + "|" + folderContentTypeId
                                  }     
                                 });

            var result = resultData;

              const properties =  await this._updateFolderProperties(result, itemProperties);
              console.log(properties);
        }

I have the following for updating the properties on the document set but constantly fails with a Failed to load resource: the server responded with a status of 403

 var ServerRelativeUrl = "https://mytenantRoot/sites/mySite/" ;
 var result = folder.d;
 var myDocumentSet = result.__metadata.uri;
 var listItemUri = ServerRelativeUrl + "_api/web/lists/getbytitle('Myrepo')/items(" + result.Id + ")";


        var resultData: any = await jquery.ajax({
        type: 'POST',
        url: listItemUri,
        contentType: 'application/json',
        headers: {      
          "Content-Type": "application/json;odata=verbose",
          "Accept": "application/json;odata=verbose",         
          "X-HTTP-Method": "MERGE",
          "If-Match": "*"
        },
        data: JSON.stringify(properties),
      });

Properties

  var properties= {
'myProperty' : "Property Text"

}

1

Your request is missing the request form digest (see this blog post). When doing any POST/PUT/DELETE with SharePoint's REST APIs, you either need to specify an authentication context (bearer access token, NTLM auth) when working remotely or a request digest + cookie (the cookie is automatically sent by the browser) when working within a SharePoint page.
Attaching the request digest would be automated for you if you were using Pnpjs JavaScript fluent library instead of crafting the requests manually.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.