Python SDK update_column syntax
Using the python SDK I am attempting to update the options list in a "Pick List" column type but can't seem to get the syntax correct. I keep getting the error 1008 Unable to parse request.
My code is: ss.Sheets.update_column(4065220*********, 5852349******, {"type": "PICKLIST", "options": ["a", "b", "c", "d", "e"]}
error msg: {"response": {"statusCode": 400, "reason": "Bad Request", "content": {"errorCode": 1008, "message": "Unable to parse request.", "refId": "8293a119***"}}}
{"result": {"code": 1008, "errorCode": 1008, "message": "Unable to parse request.", "name": "ApiError", "recommendation": "Do not retry without fixing the problem. ", "refId": "8293a119***", "shouldRetry": false, "statusCode": 400}}
I've confirmed my sheet_id and column_id are correct by calling get_column. I can successfully send an API put request with postman but this project calls for using the Python SDK.
The SDK documentation gives the syntax as "update_column(sheet_id,column_id,column_obj)" but doesn't give (nor could I find anywhere) the syntax for column_obj
My question is: What is the correct syntax for the column_obj in sheet.sheets.udpate_column() to update the options property of a PICKLIST column?
Answers
-
I gave up and just wrote my own python function to upload the new options:
#variables needed include: url, sheet_id, column_id, column_type, OptionStr, token
#OptionStr was retrieved from my python dictionary. In my case the dictionary key (for key in dictionary: OptionStr = dictionary[key])
#column_type in my case will always be 'PICKLIST'
def update_ColumnOptionsRequest(sheet_id, column_id, column_type, OptionStr):
url = 'https://api.smartsheet.com//2.0//sheets//'+sheet_id+'//columns//'+column_id
body = json.dumps({"type": column_type, "options": OptionStr}) # column type is required when changing options
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer '+ token
}
response = requests.request("PUT", url, headers=headers, data=body)
return response
Categories
- All Categories
- 14 Welcome to the Community
- Smartsheet Customer Resources
- 64.2K Get Help
- 419 Global Discussions
- 221 Industry Talk
- 461 Announcements
- 4.8K Ideas & Feature Requests
- 143 Brandfolder
- 141 Just for fun
- 58 Community Job Board
- 462 Show & Tell
- 32 Member Spotlight
- 1 SmartStories
- 299 Events
- 38 Webinars
- 7.3K Forum Archives