Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send DELETE API Calls via Sharepy #47

Closed
Cable-1406 opened this issue Dec 27, 2020 · 7 comments
Closed

Send DELETE API Calls via Sharepy #47

Cable-1406 opened this issue Dec 27, 2020 · 7 comments
Milestone

Comments

@Cable-1406
Copy link

Hey I wanted to ask if there is a way to send delete API Calls via the sharepy Library as there is no requests equivalent of delete() in your source code.

Grateful for any helping hand.

@JonathanHolvey
Copy link
Owner

JonathanHolvey commented Dec 27, 2020

In the current release, the auth headers are sent explicitly for the post method, but nothing else.

Currently only the post() method will send a digest header, allowing modifications to be made to SharePoint objects

This means that, although you should be able to call the delete method, you'll probably get an authentication error.

There is a beta release branch for SharePy v2, which uses a Requests authentication class, which should handle all HTTP methods transparently. I'd recommend you give this a try.

https://github.com/JonathanHolvey/sharepy/tree/release-2.0.0-beta

@Cable-1406
Copy link
Author

Thanks for the quick reply! So with the beta branch I should be able to use delete() exactly like get() and post() in the previous version?

@JonathanHolvey
Copy link
Owner

JonathanHolvey commented Dec 27, 2020

Yes, you should be able to.

When I originally wrote SharePy, I only ever used the POST method, so I didn't implement authentication for the others. The v2 beta delegates authentication to Requests, so every HTTP method will include the necessary auth headers.

I haven't been able to release v2, due to lack of testing. Let me know how you get on and I might be able to finally release it.

@Cable-1406
Copy link
Author

Cable-1406 commented Dec 28, 2020

Hm, so I downloaded the zip archive of the 2.0.0 beta and imported it locally, but it I still get the SPException whenever I try to delete something.

I tried something like this:

from Local import sharepy as sharepy

s = sharepy.connect(server_url, username=user, password=passwd)

uri = "https://example.sharepoint.com/sites/Test-Site/_api/web/folders/add('/sites/Test-Site/Freigegebene Dokumente/test')"
r = s.post(uri)

uri = "https://example.sharepoint.com/sites/Test-Site/_api/web/GetFolderByServerRelativeUrl('/sites/Test-Site/Freigegebene Dokumente/test')"
r = s.get(uri)
r = s.delete(uri)

(I also write the answers into files, but for simplicity I did not include this in here)

Curiously the post() function does not work either. I tried switching back to the master branch version (1.3.0 I think) and the POST Call worked fine again. Maybe my import is faulty (unpacked the zip of the beta branch and imported that locally)? Le ol' Debugger showed that the beta version directly switches to the requests sessions (which is expected from what I understood of your explanation).

@JonathanHolvey
Copy link
Owner

Can you post the stack trace of the error you're seeing?

@Cable-1406
Copy link
Author

Well the program itself does not really throw any Errors, but the API Call Response contains an SPException:

{ "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." } } }

The "value" field says something along the lines of "The security clearance for the page is invalid and may contain errors." which I always get with DELETE API Calls and also POST Calls if I use the beta version.

@JonathanHolvey
Copy link
Owner

It turns out the digest header was missing for all HTTP methods in SharePy v2, which is the cause of the error you're seeing. I've updated the release-2.0.0-beta branch, so please download it again and see if it works.

Thanks for picking this up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants