cannot delete a folder in communication site using sharepoint rest apis

%3CLINGO-SUB%20id%3D%22lingo-sub-1094055%22%20slang%3D%22en-US%22%3Ecannot%20delete%20a%20folder%20in%20communication%20site%20using%20sharepoint%20rest%20apis%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1094055%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20share-point%20account%20with%20admin%20priviledges.%3C%2FP%3E%3CP%3EI'm%20using%20share-point%20rest%20apis%20for%20deleting%20a%20folder%20in%20communication%20site.%3C%2FP%3E%3CP%3EI%20was%20able%20to%20create%20a%20folder%20in%20share-point%20communication%20site.%3C%2FP%3E%3CP%3Ebut%20couldn't%20do%20it%20for%20the%20already%20created%20folder%20for%20deletion.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Efollowing%20is%20rest%20end%20point%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Ehttps%3A%2F%2F***.sharepoint.com%2F_api%2Fweb%2FGetFolderByServerRelativeUrl('%2F***-test-folder')%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E(above%20stars%20are%20placeholders)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20making%20a%20post%20request%20instead%20of%20delete%20in%20postman.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20set%20the%20valid%20bearer%20token%20in%20the%20request%20header%20as%20well.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ealso%20following%20are%20the%20request%20headers%20which%20I%20have%20set.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EIf-Match%20-%26gt%3B%20*%0AX-HTTP-Method%20-%26gt%3B%20DELETE%0AX-RequestDigest%20-%26gt%3B%20some%20random%20string%0AAccept%20-%26gt%3B%20application%2Fjson%3Bodata%3Dverbose%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ewhen%20I'm%20sending%20the%20request%20I'm%20getting%20following%20error.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3E%7B%0A%20%20%20%20%22error%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22code%22%3A%20%22-2147024891%2C%20System.UnauthorizedAccessException%22%2C%0A%20%20%20%20%20%20%20%20%22message%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22lang%22%3A%20%22en-US%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22value%22%3A%20%22Access%20denied.%20You%20do%20not%20have%20permission%20to%20perform%20this%20action%20or%20access%20this%20resource.%22%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E**%3C%2FP%3E%3CP%3EI%20have%20already%20registered%20a%20share-point%20application%20in%20the%20azure%20directory%20as%20well.%3C%2FP%3E%3CP%3Eand%20given%20the%20required%20permission.%3C%2FP%3E%3CP%3Ebelow%20is%20the%20screenshot.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F164030i67DF997ACB8AE898%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Capture.JPG%22%20title%3D%22Capture.JPG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eplease%20any%20one%20give%20me%20what%20I'm%20doing%20wrong%20here.%3C%2FP%3E%3CP%3Eany%20help%20would%20be%20appreciated.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1094125%22%20slang%3D%22en-US%22%3ERe%3A%20cannot%20delete%20a%20folder%20in%20communication%20site%20using%20sharepoint%20rest%20apis%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1094125%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F508841%22%20target%3D%22_blank%22%3E%40buddhika_jayakodi%3C%2FA%3E%26nbsp%3BWhen%20using%20Postman%20you%20need%20to%20use%20a%20bearer%20token%20to%20access%20Sharepoint.%3CBR%20%2F%3EX-RequestDigest%20only%20works%20when%20you%20are%20communicating%20on%20Sharepoint%20with%20a%20logged%20in%20account.%3CBR%20%2F%3E%3CBR%20%2F%3ETry%20using%20Ajax%20call%20in%20your%20console%2C%20then%20you%20can%20use%20x-requestdigest%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1094181%22%20slang%3D%22en-US%22%3ERe%3A%20cannot%20delete%20a%20folder%20in%20communication%20site%20using%20sharepoint%20rest%20apis%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1094181%22%20slang%3D%22en-US%22%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F508889%22%20target%3D%22_blank%22%3E%40IshtarOnline%3C%2FA%3E%20%2C%20I%20have%20set%20the%20bearer%20token%20in%20the%20request%20header%2C%20but%20the%20same%20result.%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

I have a share-point account with admin priviledges.

I'm using share-point rest apis for deleting a folder in communication site.

I was able to create a folder in share-point communication site.

but couldn't do it for the already created folder for deletion.

 

following is rest end point

https://***.sharepoint.com/_api/web/GetFolderByServerRelativeUrl('/***-test-folder')

 

(above stars are placeholders)

 

I'm making a post request instead of delete in postman.

 

I have set the valid bearer token in the request header as well.

 

also following are the request headers which I have set.

 

If-Match -> *
X-HTTP-Method -> DELETE
X-RequestDigest -> some random string
Accept -> application/json;odata=verbose

 

when I'm sending the request I'm getting following error.

 

{
    "error": {
        "code": "-2147024891, System.UnauthorizedAccessException",
        "message": {
            "lang": "en-US",
            "value": "Access denied. You do not have permission to perform this action or access this resource."
        }
    }
}

 

**

I have already registered a share-point application in the azure directory as well.

and given the required permission.

below is the screenshot.

 

Capture.JPG

 

please any one give me what I'm doing wrong here.

any help would be appreciated.

2 Replies
Highlighted

@buddhika_jayakodi When using Postman you need to use a bearer token to access Sharepoint.
X-RequestDigest only works when you are communicating on Sharepoint with a logged in account.

Try using Ajax call in your console, then you can use x-requestdigest

Highlighted
@IshtarOnline , I have set the bearer token in the request header, but the same result.