Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to file 'Invalid requests[0].updateTextStyle: At least one field must be listed in 'fields'. (Use '*' to indicate all fields.)">'

I'm trying to update a google docs and when I try and push the update it says googleapiclient.errors.HttpError: <HttpError 400 when requesting https://docs.googleapis.com/v1/documents/1UeorM9adOh8Nds1Z457RRKBZMkh0VZ_kn_jllpkzh7U:batchUpdate?alt=json returned "Invalid requests[0].updateTextStyle: At least one field must be listed in 'fields'. (Use '*' to indicate all fields.)"> and I have no clue what is means.

This is the method that throws the error

def update(request):
    result = service.documents().batchUpdate(
        documentId=DOCUMENT_ID, body={'requests': [request]}).execute()
    return result

If anyone can help that would be great!

This is what my request is

request = {
  'updateTextStyle': {
    'range': {
      'segmentId': None,
      'startIndex': None, # gets filled with the proper number
      'endIndex': None # gets filled with the proper number
    },
    'textStyle': {
      "bold": False,
      "italic": False,
      "underline": False,
      "strikethrough": False,
      "smallCaps": False,
      "backgroundColor": {
        'color': {
          'rgbColor': {
            'red': 0.2,
            'green': 0.2,
            'blue': 0.2
          }
        }
      },
      "foregroundColor": {
        'color': {
          'rgbColor': {
            'red': 0.96,
            'green': 0.96,
            'blue': 0.96
          }
        }
        },
    "fontSize": {
        'magnitude': 10,
        'unit': 'PT'
    },
  "weightedFontFamily": {
    'fontFamily': 'Courier New OS',
    'weight': 400
  },
  "baselineOffset": 'NONE',
  "link": None
    }
  }
}
like image 945
Max Gordon Avatar asked Nov 30 '25 00:11

Max Gordon


1 Answers

At least one field must be listed in 'fields'. (Use '*' to indicate all fields.) means that the property of fields is not set in your request body. So for example, how about this modification?

From:

  },
  "baselineOffset": 'NONE',
  "link": None
    }
  }
}

To:

            },
            "baselineOffset": 'NONE',
            "link": None
        },
        "fields": "*"  # Added
    }
}

Note:

  • This answer supposes that you have already been able to update the Google Document using Google Docs API.
  • This modification supposes that when you use this request body, None of 'range': {'segmentId': None, 'startIndex': None, 'endIndex': None}, and "link": None are replaced to the correct values.

Reference:

  • UpdateTextStyleRequest
like image 90
Tanaike Avatar answered Dec 01 '25 15:12

Tanaike



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!