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"">
In your script, sheetId
is used for "sheetId": sheetId,
and spreadsheetId=sheetId
.
sheetId
at "sheetId": sheetId,
is gid
of URL. Please check here. https://developers.google.com/sheets/api/guides/concepts#sheet_id
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With