【问题标题】:Populating custom fields via. Trello API通过填充自定义字段。特雷罗 API
【发布时间】:2018-10-18 08:40:18
【问题描述】:

我在通过卡片填充自定义字段时遇到了一些问题。 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!" }}

我在这里做错了什么明显的事情吗?你能指出我正确的方向吗?自定义字段的类型是:文本,所以我很茫然。

【问题讨论】:

    标签: api trello


    【解决方案1】:

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

    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 翻译的另一个变体也适用于我。您确定您为 key、token、cardid 和 customfieldid 使用了正确的值吗?

    【讨论】:

    • 我相信我的问题与您建议的价值观有关。
    【解决方案2】:

    解决同样的问题,请求头,内容都需要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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-05
      • 2016-03-20
      • 1970-01-01
      • 1970-01-01
      • 2018-05-18
      • 1970-01-01
      相关资源
      最近更新 更多