Sharepoint Document library - Cannot edit/update folder properties via the MS API

Sherry Friesen 0 Reputation points
2024-02-15T22:56:35.6533333+00:00

I am creating folders in Sharepoint then trying to add folder properties via the MS API. I have no issue creating the folder but can't seem to figure out how to add the folder properties. Any help is appreciated.

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sergii Bielskyi 75 Reputation points MVP
    2024-02-16T03:11:29.4966667+00:00

    Here are few steps how to do it:

    1. Use the POST method and the endpoint _api/web/folders to create a folder in the library. You need to specify the ServerRelativeUrl of the folder in the request body. For example, if you want to create a folder named Test in the Documents library, the request body would be:
       {
         "__metadata": {
           "type": "SP.Folder"
         },
         "ServerRelativeUrl": "/Documents/Test"
       }
       
    
    1. Use the GET method and the endpoint _api/web/GetFolderByServerRelativeUrl('Folder Name')/ListItemAllFields to get the folder’s list item properties. You need to replace Folder Name with the actual folder name. For example, if you want to get the properties of the Test folder, the endpoint would be:
       _api/web/GetFolderByServerRelativeUrl('Test')/ListItemAllFields
       
    
    1. Use the POST method and the endpoint _api/web/GetFolderByServerRelativeUrl('Folder Name')/ListItemAllFields to update the folder’s list item properties. You need to specify the __metadata and the properties you want to update in the request body. You also need to use the MERGE method and the If-Match header to avoid conflicts. For example, if you want to update the Title and the Description properties of the Test folder, the request body and headers would be:
       {
         "__metadata": {
           "type": "SP.Data.DocumentsItem"
         },
         "Title": "Test Folder",
         "Description": "This is a test folder"
       }
       X-HTTP-Method: MERGE
       If-Match: *
       
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.