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

Folder rename - no change to folder or error #183

Closed
naomicrosthwaite opened this issue Apr 6, 2020 · 3 comments
Closed

Folder rename - no change to folder or error #183

naomicrosthwaite opened this issue Apr 6, 2020 · 3 comments
Labels

Comments

@naomicrosthwaite
Copy link

Hello 👋

I'm currently trying to rename a folder in a specific SharePoint site under the Shared Documents folder. My authenication and set up works (I am successfully creating Folders using a similar method) - however using the .rename() function from the Folder class is neither returning a renamed folder, or an error. My current code is below but I have tried many similar iterations:

def authenticate():
    ctx_auth = AuthenticationContext(SHAREPOINT_DOMAIN)
    if not ctx_auth.acquire_token_for_user(USERNAME, APP_PASS):
        raise Exception(
            "SharePoint Authentication failed, please ensure credentials are correct"
        )
    return ctx_auth

def update_folder_name(old_name, new_name):
    auth = authenticate()
    context = ClientContext(SHAREPOINT_SITE, auth)
    folder = context.web.get_folder_by_server_relative_url(f'Shared Documents/{old_name}')
    folder.rename(new_name)
    context.execute_query()

I am sure I am selecting the right folder with folder = context.web.get_folder_by_server_relative_url(f'Shared Documents/{old_name}') - if I print the contents of the folder then I get the expected output for example.

In tests/test_sharepoint_folder.py, the test to update a folder suggests to change the "Name" property but I do not think this is the right approach. Changing the "Title" and "FileLeafRef" as in the rename method is the right approach looking at the SharePoint REST API docs.
Another thing to mention that using the logger, I can see my requests are POST, not the expected MERGE as mentioned in the docs (https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest)

Any help would be greatly appreciated! Thanks!

@vgrem vgrem added the bug label Apr 6, 2020
vgrem added a commit that referenced this issue Apr 6, 2020
@vgrem
Copy link
Owner

vgrem commented Apr 6, 2020

Greetings!

Thank you for the thorough analysis and catching this bug, i confirm request payload was not correctly passed for rename endpoint and the last commit addresses this issue.

Since it would take some time before the changes will be published to pip, the latest version meanwhile could be installed from GitHub:

pip install git+https://github.com/vgrem/Office365-REST-Python-Client.git

Cheers,
Vadim

@vgrem vgrem closed this as completed Apr 6, 2020
@naomicrosthwaite
Copy link
Author

Awesome thanks @vgrem!!!!

@stefanstapinski
Copy link

@vgrem was the changes published in pip? I installed couple months ago and still running into issue, the folder does not rename?

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

No branches or pull requests

3 participants