question

edGar-8448 avatar image
0 Votes"
edGar-8448 asked MichaelHan-MSFT commented

Sharepoint REST API Renaming Issue

There is a problem with the renaming command. It seems nothing is being returned if the renaming process completes successfully. Because of it, an error is generated on the caller. The following VBscript (.vbs) code replicates the error.

Code:
Option Explicit
dim http, endPointLink, strRequest, responseText
endPointLink = "https://[CompanyDomain].sharepoint.com/sites/[CompanySite]/_api/Web/GetFolderByServerRelativePath(decodedurl='/sites/[CompanySite]/[OldFolderName]')/ListItemAllFields"

strRequest="{'Title':'NewFolderName','FileLeafRef':'NewFolderName'}"

set http=createObject("Microsoft.XMLHTTP")
http.open "POST",endPointLink,false
http.setRequestHeader "Authorization","[Token]"

http.setRequestHeader "Accept","application/json;odata=verbose"
http.setRequestHeader "Content-Type","application/json"
http.setRequestHeader "X-HTTP-Method","MERGE"
http.setRequestHeader "If-Match","*"

http.send strRequest
responseText=http.responseText

If http.Status = 200 Then
msgbox "RESPONSE : " & http.responseText
responseText=http.responseText
else
msgbox "ERRCODE : " & http.status
End If

If the preceding code runs successfully, it returns this error...

Error: Operation aborted
Code: 80004004
Source: msxml3.dll

The way to avoid the error is to use the "On Error Resume Next" command, but I don't think that is an acceptable solution.

Microsoft: Can you please update the process so it returns the appropriate status code?

Thanks.

sharepoint-dev
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.

1 Answer

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

Hi @edGar-8448,

As far as I know, the http status for updating operation in SharPoint is 204. Try to chang the if condition to If http.Status = 204, see if it works for you.


If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
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.



· 4
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.

The error is generated before it even gets to the If condition. Notice that the if condition has an Else, it does not even make it there.

The clue was initially given to me by Postman (application used for API testing). When the command is sent, Postman confirms that the command was received by the server but nothing was returned. Therefore, I assume that the renaming process is not returning anything. All other operations (copy, move, etc) do send back a status.

I think basic API design says that something should always be returned. Don't you agree?

0 Votes 0 ·

@edGar-8448,

Yes, you are right. Just test in the postman, nothing returned in the response body. In your code, you need to remove http.responseText


142369-image.png



0 Votes 0 ·
image.png (46.9 KiB)

I removed the line like you said. But I still get the same error.

I know I can use the "On Error Resume Next" right before sending the request (http.send strRequest), so the error will be ignored. However, VBscript is not the only tool I use. I mainly use FileMaker (Application Development Platform) and that platform hangs because it expects something to be sent back. I guess whoever designed the FileMaker tool never expected for an API not to return anything. I've used several API services before, and this is the first time I encounter one that does not return anything, even though the command runs successfully.

I use VBscript with the "On Error Resume Next" clause because it was the only way for my custom application to rename a folder in Sharepoint. I initially used javascript/jquery (which worked perfectly) but then I switched to VBscript, I think it's better to use local OS libraries/tools.

Thanks for your help. But I think the only solution to this problem is for Microsoft to update the renaming API process so it returns something.

0 Votes 0 ·
Show more comments