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
- Customer Resources
- 64.9K Get Help
- 440 Global Discussions
- 138 Industry Talk
- 471 Announcements
- 4.9K Ideas & Feature Requests
- 129 Brandfolder
- 148 Just for fun
- 68 Community Job Board
- 486 Show & Tell
- 33 Member Spotlight
- 2 SmartStories
- 300 Events
- 36 Webinars
- 7.3K Forum Archives