Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid value at 'requests[0].delete_dimension.range.sheet_id' (TYPE_INT32)

I am using Google spreadsheets API v4. I want to delete some rows via python script. i tried their example code and i got the following error

Invalid value at 'requests[0].delete_dimension.range.sheet_id' (TYPE_INT32)

my code:

    batch_update_spreadsheet_request_body = {
    "requests": [
        {
            "deleteDimension": {
                "range": {
                    "sheetId": sheetId,
                    "dimension": "ROWS",
                    "startIndex": 0,
                    "endIndex": 3
                }
            }
        },
        {
            "deleteDimension": {
                "range": {
                    "sheetId": sheetId,
                    "dimension": "COLUMNS",
                    "startIndex": 1,
                    "endIndex": 4
                }
            }
        },
    ],
}

request = sheets_service.spreadsheets().batchUpdate(spreadsheetId=sheetId, body=batch_update_spreadsheet_request_body)
response = request.execute()

The full traceback

Traceback (most recent call last): File "/home/yahia/DSP_Project_Server_Software/python_scripts/TMSA/TMSA.py", line 70, in main() File "/home/yahia/DSP_Project_Server_Software/python_scripts/TMSA/TMSA.py", line 67, in main response = request.execute() File "/usr/local/lib/python2.7/dist-packages/oauth2client/_helpers.py", line 133, in positional_wrapper return wrapped(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/googleapiclient/http.py", line 840, in execute raise HttpError(resp, content, uri=self.uri) googleapiclient.errors.HttpError: https://sheets.googleapis.com/v4/spreadsheets/sheetId:batchUpdate?alt=json returned "Invalid value at 'requests[0].delete_dimension.range.sheet_id' (TYPE_INT32), "sheetId" Invalid value at 'requests[1].delete_dimension.range.sheet_id' (TYPE_INT32), "sheetId"">

like image 793
Yahia Farghaly Avatar asked Feb 04 '23 05:02

Yahia Farghaly


1 Answers

In your script, sheetId is used for "sheetId": sheetId, and spreadsheetId=sheetId.

  1. sheetId at "sheetId": sheetId, is gid of URL. Please check here. https://developers.google.com/sheets/api/guides/concepts#sheet_id

  2. sheetId at spreadsheetId=sheetId is Spreadsheet ID. Please check here. https://developers.google.com/sheets/api/guides/concepts#spreadsheet_id

Each sheetId is different. So please modify them.

like image 175
Tanaike Avatar answered Feb 15 '23 20:02

Tanaike