-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
Hello,
I am using your api python client for Google Sheets API. It works well on some requests (such as 'findReplace' for instance) but for others (such as 'DeleteRange') it does not work at all and it returns an error Message as if the request Type was wrong.
Here is the error Message I get
"exception": "\"<HttpError 400 when requesting https://sheets.googleapis.com/v4/spreadsheets/10MrP6O2bsAhq8nzMM8ohPVnwOxGf7Up8MdqvPQolzhI:batchUpdate?alt=json returned \\\"Invalid JSON payload received. Unknown name \\\"DeleteRange\\\" at 'requests[0]': Cannot find field.\\\". Details: \\\"[{u'fieldViolations': [{u'field': u'requests[0]', u'description': u'Invalid JSON payload received. Unknown name \\\"DeleteRange\\\" at \\\\'requests[0]\\\\': Cannot find field.'}], u'@type': u'type.googleapis.com/google.rpc.BadRequest'}]\\\"
Quick overview of the code I used
SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
SERVICE_ACCOUNT_FILE = 'keys.json'
creds = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
sheets_service = build('sheets', 'v4', credentials=creds)
...
requests.append({'DeleteRange': {'range': {'sheetId': sheet_id, 'startRowIndex': '26', 'endRowIndex': '34', 'startColumnIndex': '1', 'endColumnIndex': '2'}, 'shiftDimension': 'ROWS'}})
body0 = {'requests': requests}
try:
response = sheets_service.spreadsheets().batchUpdate(spreadsheetId=file_id, body=body0).execute()
except Exception as e:
return {"erreur": "true", "exception": json.dumps(e, indent=4, sort_keys=True, default=str), "requests": json.dumps(requests, indent=4, sort_keys=True, default=str)}
I do not understand how to call this method described here : https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#deletenamedrangerequest
Any help on this would be amazing
Thank you in advance,
Jérémy