I’m using the Google Docs API to try and change the width of a table column through a batchUpdate request. Here’s the format of the request I have set up:
update_request = {
'updateTableColumnProperties': {
'tableStartLocation': {
'index': my_table_position
},
'columnIndices': [my_column_index],
'tableColumnProperties': {
'widthType': "FIXED_WIDTH",
'width': {
'magnitude': width_value,
'unit': 'PT'
}
},
'fields': 'width'
}
}
I’m encountering this error message in response:
{
"error": {
"code": 400,
"message": "Invalid requests[4].updateTableColumnProperties: Width type must be provided when updating column width.",
"status": "INVALID_ARGUMENT"
}
}
This is quite confusing as I am certain I added the widthType. What might be the reason behind this error?
Been there with Google Docs API. Field masks are a pain.
Honestly, Google API quirks like this are exactly why I ditched manual API calls for document automation. Just when you think you’ve got it, another gotcha hits.
I switched to Latenode for document workflows. It handles Google Docs API connections behind the scenes - no field mask syntax or nested property headaches. Just drag and drop what you need.
Last month I built a system updating table formatting across dozens of documents. No debugging API requests or perfect JSON structures. Just works.
Want to keep fighting the API? Fix that fields parameter like others said. Want to get stuff done without headaches? Check out https://latenode.com
The Problem:
You’re receiving the error “Invalid requests[4].updateTableColumnProperties: Width type must be provided when updating column width.” when attempting to change the width of a Google Docs table column using the batchUpdate request. Despite including widthType, the API call still fails.
Understanding the “Why” (The Root Cause):
The error message is misleading. The actual issue isn’t that widthType is missing from your request body; rather, it’s that the fields parameter in your batchUpdate request isn’t correctly specifying that you intend to update the widthType field. The Google Docs API only updates the fields explicitly listed in the fields parameter. By only specifying fields: 'width', you’re telling the API to update only the width property, ignoring widthType. When the API tries to update width without the necessary context of widthType, it throws the error.
Step-by-Step Guide:
-
Correct the fields Parameter: Modify your batchUpdate request to include both width and widthType in the fields parameter. There are two ways to achieve this:
-
Option A (Specific Fields): Change the fields parameter to explicitly list both fields:
'fields': 'width,widthType'
-
Option B (All Fields): For a more comprehensive update, use the wildcard *:
'fields': '*'
This ensures that the API considers both the width and widthType properties when processing the request. Replace your original update_request with the modified version below using your preferred option (A or B).
update_request = {
'updateTableColumnProperties': {
'tableStartLocation': {
'index': my_table_position
},
'columnIndices': [my_column_index],
'tableColumnProperties': {
'widthType': "FIXED_WIDTH",
'width': {
'magnitude': width_value,
'unit': 'PT'
}
},
'fields': 'width,widthType' # Option A
#'fields': '*' # Option B
}
}
-
Verify JSON Serialization: Ensure your Python code correctly serializes the update_request dictionary into valid JSON before sending it to the Google Docs API. Incorrect serialization might drop properties or alter their structure, causing unexpected behavior. Print your update_request to the console immediately before sending the API request to verify its integrity.
-
Double-Check Data Types: Make absolutely sure that width_value is a valid numeric type (integer or float) and that 'unit' is correctly set to 'PT' (or potentially 'POINT' if 'PT' proves problematic). The API is sensitive to these and will throw this misleading error if the data types are incorrect.
-
Inspect the Full API Response: Don’t only focus on the error message. Analyze the full response from the Google Docs API to check for other clues or more detailed error messages that might provide additional insights if the issue persists.
Common Pitfalls & What to Check Next:
-
Incorrect my_table_position or my_column_index: Double-check the table index (my_table_position) and column index (my_column_index). Incorrect indices will cause the API to target the wrong table or column.
-
API Rate Limits: If you’re making many requests, you might be hitting Google Docs API rate limits. Implement proper error handling and retry mechanisms to manage this.
-
Authentication Issues: Ensure that your application is correctly authenticated with the Google Docs API and has the necessary permissions to modify the document.
Still running into issues? Share your (sanitized) config files, the exact command you ran, and any other relevant details. The community is here to help!
The problem’s likely your fields parameter. You’re using 'fields': 'width', but you’re updating both width and widthType. Try 'fields': 'width,widthType' instead, or just use 'fields': '*' to update everything at once. I ran into this same issue before - the API needs you to explicitly list which fields you’re updating. If you don’t include widthType, the API ignores it completely and throws that error.
This error drove me crazy for weeks when I started with Google Docs API. Yeah, it’s the fields parameter like everyone said, but there’s another gotcha - your width object structure needs to be spot on. The API throws this misleading error when your magnitude value isn’t a proper number or the unit’s wrong. Log your entire request payload before sending it to check the JSON didn’t get messed up during serialization. PT units are finicky too - I’ve had better luck with POINT instead of PT sometimes, even though the docs say both work.
Yeah, alexlee’s right. But also check your indentation in the request - I’ve hit this same error when widthType gets nested wrong or drops out because of formatting issues. Print your request object before sending it to make sure everything’s actually there.
Double check you’re not accidentally overwriting the widthType somewhere in your code before the API call. I had a similar bug where my widthType was getting set to null during object manipulation and the request looked fine when debugging but was actually broken.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.