0

UPDATE: I used the api explorer on the google bactch update page and was able to successfully update the spreadsheet but when I replicate this in my code I am still getting an error. The API explorer did work with the json format.

<HttpError 400 when requesting
Invalid JSON payload received. Unknown name "value_input_option" at 'requests[0]': Cannot find field.
Invalid JSON payload received. Unknown name "data" at 'requests[0]': Cannot find field.">



scope = ['https://spreadsheets.google.com/feeds',
     'https://www.googleapis.com/auth/drive']
creds = 
ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
service = discovery.build('sheets', 'v4', credentials=creds)
client = gspread.authorize(creds)

# find workbook by name and open the first sheet
# make sure you use the right name here
sheet = client.open("forklift").sheet1

# extract and print all of the values
# list_of_hashes = sheet.get_all_records()

spreadsheet_id = '112345'


batch_update_spreadsheet_request_body =  {
     "requests": [

{
    "valueInputOption": "RAW",
    "data": [
        {
            "majorDimension": "ROWS",
            "range": "43:48",
            "values": [
                ["www.colossalpoint.com","colossal point llc"]
            ]
        }
    ]
}
  ],
  "includeSpreadsheetInResponse": True,
  "responseIncludeGridData": True
}


request = service.spreadsheets().batchUpdate(spreadsheetId=spreadsheet_id,
                                         body=batch_update_spreadsheet_request_body)
response = request.execute()
dcarlo56ave
  • 253
  • 5
  • 18
  • your body needs to be formatted correctly thats not even close to the documentation for a body https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/batchUpdate – Linda Lawton - DaImTo Dec 06 '18 at 12:53
  • The documentation on this is not to clear did get that part from the documentation. So basically I need to start with that json thats in batch update and continue to add? Its my first time doing this so I dont understand what to add and where to add it. – dcarlo56ave Dec 06 '18 at 14:21
  • For example I see insert range has a few properties that I can choose from. Where in the documentation can I go to understand how to map the dict. – dcarlo56ave Dec 06 '18 at 14:24
  • Check the request body in the page i linked. I dont think you should be doing this manually i think you should be building up the object properly in your library. – Linda Lawton - DaImTo Dec 06 '18 at 14:29
  • I did check the link and have been using the api explorer in the batch update page. What I am doing is clicking on the request object link in the json from the page you send to see what values I can enter. Thats what I am understanding from the documentation. – dcarlo56ave Dec 06 '18 at 14:33
  • Are you trying to add value at the cell in batches or one at a time? Your JSON payload looks more like a singe request format. Let me know if you're okay with a single update and I can share the code – fcsr Dec 17 '18 at 14:18

0 Answers0