通过以下方式填充自定义字段.Trello API.



我在通过 API 填充卡片上的自定义字段时遇到了一些问题。我使用的网址是:

https://api.trello.com/1/card/{CardID}/customField/{CustomFieldID}/item?key={Key}&token={Token}

发出请求时我得到的响应是 400 代码,响应正文是:

Invalid value for custom field type

在 PUT 请求中发送的数据是:

{ "value" : { "text": "Hello, world!" }}

我在这里做错了什么吗?你能指出我正确的方向吗?自定义字段的类型是:文本,所以我不知所措。

我没有看到您报告的尝试有任何明显的错误。我刚刚测试了以下内容,它对我有用:

TRELLO_API_KEY=<your api key>
TRELLO_TOKEN=<your oauth token>
CardID=<your card id>
CustomFieldID=<your custom field id>
curl -X PUT -H "Content-Type: application/json" 
"https://api.trello.com/1/card/${CardID}/customField/${CustomFieldID}/item?key=${TRELLO_API_KEY}&token=${TRELLO_TOKEN}" 
-d '{"value": { "text": "Hello, world!" }}'

将密钥和令牌放入 JSON 中的变体也可以正常工作:

curl -X PUT -H "Content-Type: application/json" 
"https://api.trello.com/1/card/${CardID}/customField/${CustomFieldID}/item 
-d '{
"value": { "text": "Hello, world!" },
"key": "'"${TRELLO_API_KEY}"'",
"token": "'"${TRELLO_TOKEN}"'"
}'

为Node翻译的另一个变体也对我有用。您确定对键、令牌、卡迪德和自定义字段 ID 使用了正确的值吗?

只需解决相同的问题,请求头和内容需要是 json 类型。 下面是一个 python 函数:

def trelloUpdateCustomFieldItems(cardID,**kwargs):
url = f"https://api.trello.com/1/cards/{cardID}/customField/{list(kwargs)[0]}/item"
payload =  json.dumps({"value": {"text": "abcd"}})
headers = {'content-type': "application/json"}
query = {
'key': trelloKey,
'token': trelloToken
}
response = requests.put(url, data=payload2, headers=headers, params=query)

最新更新