question

MadhuSudanSingh-1785 avatar image
0 Votes"
MadhuSudanSingh-1785 asked MichaelHan-MSFT answered

Not able to rename folder using REST API using POSTMAN

Hi All,

I am not Not to rename the folder using REST API using POSTMAN, Please refer to the below screenshot of my REQUEST

113894-capture.png


office-sharepoint-onlineoffice-sharepoint-server-developmentoffice-sharepoint-server-customization
capture.png (67.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered

Hi MadhuSudanSingh-1785,

You need to set the Content-Type header as application/json;odata=verbose, as the below:

114045-image.png


And the body:

 {
         "__metadata": {            
             "type": "SP.Data.Shared_x0020_DocumentsItem"
         },
         "FileLeafRef": "NewFolderName"
 }  



If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.




image.png (63.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

cooldadtx avatar image
0 Votes"
cooldadtx answered MadhuSudanSingh-1785 edited

The issue is that you're passing an ETag to the request. ETags (and other E-headers) are used to detect modifications. They are most often used for GET requests and allow a server (or proxy) to skip retrieval of the data if there has been no changes on the E-headers since the last request. It is a caching mechanism.

In your case you are passing an ETag probably from a previous GET. However by the time you make the request the object has been modified and therefore the tag doesn't match and it fails the call. This is a concurrency detection thing. Two solutions that I can see.

Option 1 update to the new ETag and try again. In your Postman screenshot it doesn't actually look like you're passing the ETag header so that might be the problem by itself. Set the header to whatever you got from the GET request and try again.

Option 2 is to not bother with the concurrency detection. Since you're just renaming a folder I would wager changes to it shouldn't matter. Therefore remove the If-Match header.

· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,

Even after removing If-Match header, I get an error, below is the response
113886-capture.png



The body is as below

{
"__metadata": {
"type": "SP.Data.Shared_x0020_DocumentsItem"
},
"Title": "Newname",
"FileLeafRef": "Newname"
}


0 Votes 0 ·
capture.png (61.8 KiB)
cooldadtx avatar image cooldadtx MadhuSudanSingh-1785 ·

I don't use SP API so maybe the tag is required. Add the If-Match header in again and also ensure you are setting the ETag header to the value from the previous GET (or for testing the value it is giving you). As I mentioned earlier it didn't appear you were actually passing the ETag originally.

Also note that the Headers tab in Postman shows you passing a lot of headers. Be sure to scan those as well. It is possible the header(s) are being auto-added by the collection/folder and causing issues. If in that tab you see the ETag/If-Match headers then it is being applied by the collection/folder or session. This is common in sample PM collections. We tell you to run a GET and we use a post-run script to update your environment with values from the results so we can then tell you to run a POST/PUT and it uses the results of your previous GET.

0 Votes 0 ·

Hi,

Thanks for your quick response.

I went through the API documentation which says give Etag or , so I mentioned and now I get a new error.

113922-capture.png

Request Body is as below

{
"__metadata": {
"type": "SP.Data.Shared_x0020_DocumentsItem"
},
"Title": "Newname",
"FileLeafRef": "Newname"
}

0 Votes 0 ·
capture.png (64.6 KiB)
Show more comments