nithinmurali / pygsheets

Google Sheets Python API v4
https://pygsheets.readthedocs.io/en/latest
Other
1.5k stars 220 forks source link

Trash Spreadsheets #598

Open thuibr opened 2 months ago

thuibr commented 2 months ago

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