0
votes

I want to use google spreadsheet api batchUpdate to update different values with the same request.

In the documentation examples they use a dict to store the Json request but I need to set the same attribute (insertDimension) multiple times. Here Google expected request

{
  "requests": [
    {
      "insertDimension": {
        "range": {
          "sheetId": sheetId,
          "dimension": "COLUMNS",
          "startIndex": 2,
          "endIndex": 4
        },
        "inheritBefore": true
      }
    },
    {
      "insertDimension": {
        "range": {
          "sheetId": sheetId,
          "dimension": "ROWS",
          "startIndex": 0,
          "endIndex": 3
        },
        "inheritBefore": false
      }
    },
  ],
}

I tried using json.dumps

mydata = json.dumps('''

"requests": [{{"updateDimensionProperties": {"range": {"sheetId": 0,"dimension": "ROWS","startIndex": 0 "endIndex": 50 }, "properties": { "pixelSize": 10 }, "fields": "pixelSize" } } } ] ''')

but I receive this error message "Invalid JSON payload received. Unknown name "": Root element must be a message."

1

1 Answers

0
votes

Your request is invalid because it never says what kind of request it is: the insertDimension request. The correct form is

{
"requests": [
  {
  "insertDimension": { 
    # required fields at https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#InsertDimensionRequest
  }
  },
  {
  "insertDimension": { 
    # required fields at https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#InsertDimensionRequest
  }
  }]
}

By the way, one of the fields is inheritFromBefore, not inheritBefore