You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python调用Smartsheet API向Picklist列插入值失败求助

解决Smartsheet API更新Picklist列的400错误

问题描述

调用Python版Smartsheet API更新Picklist类型列时,即使插入的是列已有的选项,仍返回400错误:

{"response": {"statusCode": 400, "reason": "Bad Request", "content": {"detail": {"index": 0, "rowId": 8212749243377540}, "errorCode": 1235, "message": "Value is not supported for this column type. Use objectValue instead.", "refId": "wv6as6"}}}

原代码:

new_row = smartsheet.models.Row()
new_row.id = row_id
new_cell = smartsheet.models.Cell() #Cell configuration
new_cell.column_id = 5727843499960196
new_cell.value = "Jysk Bumpers"
new_cell.strict = False
new_row.cells.append(new_cell) 
updated_row = smartsheet_client.Sheets.update_rows(1398305516218244, # sheet_id
                                                   [new_row])
print("Complete")

解决方案

Picklist类型列必须使用objectValue字段而非value字段,且需传入包含displayValue的字典结构,对应下拉列表的选项文本。修正后的代码如下:

new_row = smartsheet.models.Row()
new_row.id = row_id
new_cell = smartsheet.models.Cell()
new_cell.column_id = 5727843499960196
# 替换value为objectValue,使用displayValue对应选项文本
new_cell.object_value = {"displayValue": "Jysk Bumpers"}
new_cell.strict = True  # 严格模式确保匹配已有选项,可选但推荐
new_row.cells.append(new_cell) 
updated_row = smartsheet_client.Sheets.update_rows(1398305516218244, [new_row])
print("Complete")

关键说明

  • Picklist(下拉列表)列属于特殊类型,Smartsheet API要求必须通过objectValue传递值,不能直接用value字段。
  • objectValue的结构必须包含displayValue键,值为下拉列表中已存在的选项文本,大小写和空格需与列中选项完全一致。
  • 建议将strict设为True,这样如果传入的选项不存在,API会返回明确错误,便于排查问题;若设为False,可能会导致值被忽略或创建无效条目(取决于列配置)。

内容的提问来源于stack exchange,提问作者Frederik Toft

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 03:03:25