I am trying out the Sharepoint API, but I am having troubles deleting anything. GET Calls, Creating folders and uploading files works like a charm, but deleting stuff is giving me head aches. I tried following the doc (https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest), but every time I do a DELETE Call on either a folder or a file I get the same Error Message:

I also couldn't find any information to this error code. The site itself was created by the same account which does the API calls, so there shouldn't be any Permission Issues, right?

Code (I am using the sharepy python Library):

p = s.delete("https://example.sharepoint.com/sites/Test-Site/_api/web/GetFolderByServerRelativeUrl('/sites/Test-Site/Freigegebene Dokumente/test/Test Schuelerin')")
data = p.json()
write_to_file(data, "delete_folder.json")

The API Call itself is just on the Folder via GetFolderByServerRelativeUrl() and the sharepy.delete() should be the same as adding "X-HTTP-METHOD": "DELETE" to the header and using a POST call (altough I also tried that and the outcome was the same).

  "error": {
    "code": "-2130575251, Microsoft.SharePoint.SPException",
    "message": {
      "lang": "de-DE",
      "value": "Die Sicherheits\u00fcberpr\u00fcfung f\u00fcr die Seite ist ung\u00fcltig und m\u00f6glicherweise fehlerhaft. Klicken Sie im Webbrowser auf die Schaltfl\u00e4che 'Zur\u00fcck', um den Vorgang zu wiederholen."

This is the error message I get (it's in german and says something along the lines of "The Security Check for this site is invalid and may contain errors")

  • Hi, Can you put here the rest api end point you are using or your code – Hawk Nov 14 '20 at 22:30
  • Code added... my bad – Gurki_1406 Nov 17 '20 at 11:18

Code on how to delete a folder for your reference:

                url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetFolderByServerRelativeUrl('/Shared Documents/testfolder')",
                type: "POST",
                headers: {
                    "If-Match": "*",
                    "X-HTTP-Method": "DELETE",
                    "X-RequestDigest": $("#__REQUESTDIGEST").val()
                success: function (data) {
  • It seems like I am doing something pretty similar to what you are suggesting (but obviously in python and using sharepy). Do the If-Match and X-RequestDigest values matter much? If yes can you maybe explain what exactly they are doing? – Gurki_1406 Nov 17 '20 at 11:21
  • Both Headers is important specially the X-RequestDigest, you can that in the context of the site as a protection that the request is valid and coming from the site – Hawk Nov 17 '20 at 18:09
  • This error should be an X-RequestDigest problem, but I am not familiar with python and can’t help you more. – Amos Nov 18 '20 at 9:38
  • Okay thanks. I already did some resarch on that X-RequestDigest field, but I will need some serious brain grease, because I probably have to tinker with the library I am using, so yeah great fun. But thanks for the tip, knowing where the error is is better than to wonder.. – Gurki_1406 Nov 18 '20 at 23:40

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.