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

Trash Spreadsheets #598

Open
thuibr opened this issue Jun 12, 2024 · 0 comments
Open

Trash Spreadsheets #598

thuibr opened this issue Jun 12, 2024 · 0 comments

Comments

@thuibr
Copy link

thuibr commented Jun 12, 2024

Is your feature request related to a problem? Please describe.
It would be nice to be able to trash a spreadsheet instead of fully deleting it. The following code shows how to do it when using API v3. There's no rush on this, but we are implementing this ourselves, and I thought it would be good to share. Thanks!

Describe the solution you'd like

def trash_spreadsheet(client, file_id: str):
    """Trash a spreadsheet.

    Args:
        file_id: The id of the spreadsheet to trash.

    Returns:
        The updated file metadata.
    """
    # First retrieve the file from the API.
    file = client.drive.service.files().get(fileId=file_id, fields="trashed", supportsAllDrives=True).execute()

    # File's new metadata.
    file['trashed'] = True

    # Send the request to the API.
    updated_file = client.drive.service.files().update(fileId=file_id, body=file, supportsAllDrives=True).execute()

    return updated_file

Any other info
Any other info

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

No branches or pull requests

1 participant