使用 curl 更新列选项列表值时出现 Smartsheet API 错误

Smartsheet API error when using curl to update column picklist values

早上好, 我正在寻找一种方法来更新我的 Smartsheet 中列中的下拉值。从 Smartsheet API 2.0 开始,我设法想出以下代码与 curl 一起使用,但是当在 CMD 中 运行 时出现以下错误。

这是我使用的代码:

curl https://api.smartsheet.com/2.0/sheets/7654838910642052/columns/4 -H "Authorization: Bearer 6cn0otb4tdjueqzuflgnkzff17" -X PUT -d '{"title":"Weekend Date","index":4, "type" : "PICKLIST", "options" :["31-OCT-2015"]}' -k

我从CMD得到的错误信息如下:

C:\New>curl https://api.smartsheet.com/2.0/sheets/7654838910642052/columns/4 -H "Authorization: Bearer 5cn0otb4tdjueqzuflgnkzff17" -X PUT -d '{"title"
:"Weekend Date","index":4, "type" : "PICKLIST", "options" :["31-OCT-2015"]}' -k
{"errorCode":1124,"message":"Invalid Content-Type header. Media type not supported."}curl: (6) Could not resolve host: type; Host not found
¶hA▓╔ôÒ±$═»ù0♠~¡lk§☺▄ÜQ­K¡^ Õf ƒîa♀ÛæçÂ"õ8Ê╝±↕åÊJcurl: (6) Could not resolve host: PICKLIST,; Host not found
curl: (6) Could not resolve host: options; Host not found
curl: (3) [globbing] error: bad range specification after pos 3

如果能得到任何帮助,我将不胜感激!!!这个错误真的很烦人,我花了好几个小时试图修复它。

** 请注意,出于安全原因我更改了访问令牌,但我使用的令牌绝对有效**

您使用的路径似乎有误。我可以看到列 ID 所在的路径中包含一个“4”。要更新列,您将使用以下路径:

curl https://api.smartsheet.com/2.0/sheets/{sheetId}/columns/{columnId}

您可以找到 API 参考 here

正如约瑟夫在他的回答中所建议的那样,您当然需要验证您在 URL 中为 {columnId} 指定的值是否有效。但是,您遇到的错误可能与该问题无关。

可能发生的情况是 cURL 自动将 Content-Type header 设置为值 "application/x-www-form-urlcoded" -- 这不是有效的内容类型这个请求到 Smartsheet。您可以通过简单地在请求中自己设置 Content-Type header 来解决此错误(即将此添加:-H "Content-Type: application/json" 到请求中)。

例如,我请求更新列的选项列表选项,以便唯一的选项是“2015 年 10 月 31 日”,如下所示:

curl https://api.smartsheet.com/2.0/sheets/{sheetId}/columns/{columnId} -H "Authorization: Bearer YOUR_TOKEN" -H "Content-Type: application/json" -X PUT -d "{\"type\":\"PICKLIST\", \"options\":[\"31-OCT-2015\"]}" -k

请注意,要更新选项列表选项,我需要在 JSON 中设置的唯一属性是 typeoptions。另请注意,我在 JSON 中使用(转义)双引号而不是单引号——您可能需要也可能不需要这样做(取决于您的平台)。