【问题标题】:Trello Card Update APITrello 卡片更新 API
【发布时间】:2014-11-30 05:19:39
【问题描述】:

我一直在尝试使用 Trello 的 REST API。到目前为止,我可以通过常规的 POST 调用将一些卡片推送到系统中。我现在想做的是用新信息更新卡片(即新描述、新 cmets 或将卡片移动到新列表等)。

我可以使用 PUT 或 POST 方法执行此操作,还是我首先需要删除旧卡并创建新卡?如果是这样,有人可以举例说明他们是如何做到的吗?

我尝试了以下 PUT 方法,但它似乎不起作用:

PUT https://api.trello.com/1/cards/[existing card id]?key=[key]&token=[TOKEN]

然后我将在请求正文中提供参数,如下所示:

{
    "id": "542de77c832cff3f97884ad8",
    "badges": {
        "votes": 0,
        "viewingMemberVoted": false,
        "subscribed": false,
        "fogbugz": "",
        "checkItems": 0,
        "checkItemsChecked": 0,
        "comments": 0,
        "attachments": 0,
        "description": true,
        "due": null
    },
    "checkItemStates": [],
    "closed": false,
    "dateLastActivity": "2014-10-03T00:02:04.042Z",
    "desc": "test",
    "descData": null,
    "due": null,
    "idBoard": "5417684179931e027c3d6bb9",
    "idChecklists": [],
    "idList": "5417684179931e027c3d6bbc",
    "idMembers": [],
    "idShort": 14,
    "idAttachmentCover": null,
    "manualCoverAttachment": false,
    "labels": [],
    "name": "new test #1 updated",
    "pos": 131072,
    "shortUrl": "https://trello.com/c/XYZ",
}

顺便说一句,我正在使用 Postman Client 来执行我的 HTTP 方法。最后,我想将这些功能实现到一个小的 javascript 模块中。有谁知道我做错了什么?

提前致谢!

【问题讨论】:

  • "然后我将更新的票证添加为 JSON 文件" - 这是什么意思?您应该在请求正文中或作为 url 参数提供参数。
  • 感谢您的快速回复。这就是我真正的意思。对困惑感到抱歉。我已经更新了我的问题。所以我希望,它现在更清楚一点......
  • 您应该只在参数中包含您正在更改的字段。您尝试设置的许多字段都是经过计算的,因此是只读的。可以设置哪些字段请咨询the documentation
  • 再次感谢。即使我只尝试使用 PUT 方法更新名称,也不会发生任何事情......我只是将票证作为响应返回,名称字段未更改。
  • 在 Postman 中你想使用x-www-form-urlencoded body。

标签: javascript trello


【解决方案1】:

好吧,已经有一段时间了,但现在我在过去的几个小时里遇到了同样的问题。对我来说,x-www-form-urlencoded 正文的技巧没有奏效。

对于仍在挣扎的人:

1.) 您要更改的每个参数都必须在 Query-Params 中定义 - 不需要正文

2.) 确保将 URL 输入为 https:// 而不是 http://!这实际上解决了这个问题。

Trello Api 似乎将每个 http:// 请求解释为 GET。

玩得开心! :-)

【讨论】:

    【解决方案2】:

    使用失眠休息客户端,它使用 PUT + 正文内容作为 json 工作。不需要在 url 中添加字段。

    * Preparing request to https://api.trello.com/1/cards/card_id?key=your_key&token=some_token
    * Current time is 2020-08-07T11:28:18.144Z
    * Using libcurl/7.69.1 OpenSSL/1.1.1g zlib/1.2.11 brotli/1.0.7 libidn2/2.1.1 libssh2/1.9.0 nghttp2/1.40.0
    * Using default HTTP version
    * Disable timeout
    * Enable automatic URL encoding
    * Enable SSL validation
    * Enable cookie sending with jar of 1 cookie
    * Found bundle for host api.trello.com: 0xa7f54da37800 [can multiplex]
    * Re-using existing connection! (#4) with host api.trello.com
    * Connected to api.trello.com (96.7.239.40) port 443 (#4)
    * Using Stream ID: 3 (easy handle 0xa7f54da37800)
    
    > PUT /1/cards/card_id?key=your_key&token=some_token HTTP/2
    > Host: api.trello.com
    > user-agent: insomnia/2020.3.3
    > cookie: dsc=blablabla
    > content-type: application/json
    > accept: */*
    > content-length: 20
    
    {"desc":"123123123"}
    
    * We are completely uploaded and fine
    

    【讨论】:

      猜你喜欢
      • 2020-10-20
      • 2014-10-30
      • 2020-12-12
      • 2015-06-28
      • 1970-01-01
      • 1970-01-01
      • 2012-05-01
      • 2012-08-20
      • 2012-04-06
      相关资源
      最近更新 更多