title: Google Sheets API returning HTTP error 400
body: <p>I am trying to delete a row in a spreadsheet using the Google Sheets API. When running the code, I am getting a 400 error. Here is the full code:</p>
  <pre><code>from __future__ import print_function
  import pickle
  import os.path
  from googleapiclient.discovery import build
  from google_auth_oauthlib.flow import InstalledAppFlow
  from google.auth.transport.requests import Request
  
  # If modifying these scopes, delete the file token.pickle.
  SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
  
  def main():
      &quot;&quot;&quot;Shows basic usage of the Sheets API.
      Prints values from a sample spreadsheet.
      &quot;&quot;&quot;
      creds = None
      # The file token.pickle stores the user's access and refresh tokens, and is
      # created automatically when the authorization flow completes for the first
      # time.
      if os.path.exists('token.pickle'):
          with open('token.pickle', 'rb') as token:
              creds = pickle.load(token)
      # If there are no (valid) credentials available, let the user log in.
      if not creds or not creds.valid:
          if creds and creds.expired and creds.refresh_token:
              creds.refresh(Request())
          else:
              flow = InstalledAppFlow.from_client_secrets_file(
                  'credentials.json', SCOPES)
              creds = flow.run_local_server(port=0)
          # Save the credentials for the next run
          with open('token.pickle', 'wb') as token:
              pickle.dump(creds, token)
  
      service = build('sheets', 'v4', credentials=creds)
  
      # The ID and range of a spreadsheet.
      SPREADSHEET_ID = '1GrO8NHRKZzTVMRnG9FskjzhWLKJySWQxT2VSXcuRixw'
      RANGE_NAME = &quot;B:F&quot;
      batch_update_spreadsheet_request_body = {
          &quot;requests&quot;: [
              {
              &quot;deleteDimension&quot;: {
                  &quot;range&quot;: {
                  &quot;sheetId&quot;: SPREADSHEET_ID,
                  &quot;dimension&quot;: &quot;ROWS&quot;,
                  &quot;startIndex&quot;: 26,
                  &quot;endIndex&quot;: 26
                  }
              }
              }
          ],
          }
      request = service.spreadsheets().batchUpdate(spreadsheetId=SPREADSHEET_ID, body=batch_update_spreadsheet_request_body)
      response = request.execute()
  
  if __name__ == '__main__':
      main()
  </code></pre>
  <p>and here are the errors I'm getting:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;f:/owcsc/Documents/GitHub/aotw/stackoverflow.py&quot;, line 59, in &lt;module&gt;
      main()
    File &quot;f:/owcsc/Documents/GitHub/aotw/stackoverflow.py&quot;, line 54, in main
      response = request.execute()
    File &quot;C:\Python38\lib\site-packages\googleapiclient\_helpers.py&quot;, line 134, in positional_wrapper
      return wrapped(*args, **kwargs)
    File &quot;C:\Python38\lib\site-packages\googleapiclient\http.py&quot;, line 915, in execute
      raise HttpError(resp, content, uri=self.uri)
  googleapiclient.errors.HttpError: &lt;HttpError 400 when requesting https://sheets.googleapis.com/v4/spreadsheets/1GrO8NHRKZzTVMRnG9FskjzhWLKJySWQxT2VSXcuRixw:batchUpdate?alt=json returned &quot;Invalid value at 'requests[0].delete_dimension.range.sheet_id' (TYPE_INT32), &quot;1GrO8NHRKZzTVMRnG9FskjzhWLKJySWQxT2VSXcuRixw&quot;&quot;. Details: &quot;[{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'requests[0].delete_dimension.range.sheet_id', 'description': 'Invalid value at \'requests[0].delete_dimension.range.sheet_id\' (TYPE_INT32), &quot;1GrO8NHRKZzTVMRnG9FskjzhWLKJySWQxT2VSXcuRixw&quot;'}]}]&quot;&gt;
  </code></pre>
  <p>I'm sure this is probably a simple fix but I couldn't figure out any of the answers I found.</p>