Python Google Sheets API: Hide or Show Sheet

July 25, 2019
credentials = ...
service = build('sheets', 'v4', credentials=credentials)
sheet = service.spreadsheets()

SPREADSHEET_ID = ...
SHEET_ID = ...

body = {
    'requests': [
        {
            'updateSheetProperties': {
                'properties': {
                    'sheetId': SHEET_ID,
                    'hidden': True
                },
                'fields': 'hidden'
            }
        }
    ]
}

# Using sheet.values().batchUpdate will trigger: Invalid JSON payload received. Unknown name "requests": Cannot find field.
result = sheet.batchUpdate(spreadsheetId=SPREADSHEET_ID,
                           body=body).execute()

NOTE: Refer Setup and Access Google Sheets API With Python.

NOTE: Refer Get Sheet Id by Sheet Name.

References:

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.