Trello卡更新API

时间:2014-10-05 22:35:41

标签: javascript trello

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

我可以使用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模块中。有谁知道我做错了什么?

提前致谢!

2 个答案:

答案 0 :(得分:1)

好的,已经有一段时间了,但是现在我在最近几个小时里遇到了同样的问题。对我来说,x-www-form-urlencoded主体的窍门没有解决。

对于仍在挣扎中的人们:

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

2。)确保以https://而非http://的形式输入URL!这实际上解决了问题。

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

玩得开心! :-)

答案 1 :(得分:0)

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

* 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