如何使用 Trello JS API 创建卡片

How to use Trello JS API to create a card

本文关键字:创建 API JS 何使用 Trello      更新时间:2023-09-26

我一直在尝试通过JSFiddle使用Trello API,但一直无法让它工作(我的JS/JSON知识非常有限)。我需要使用 API 在特定列表下创建一张卡。

function PostStuff()
{
    $(document).ready(function(){
    Trello.authorize({
    interactive: true,
    type: "popup",
    expiration: "never",
    name: "surveyrequest",
    persist: "true",
    success: function() { onAuthorizeSuccessful(); },
    error: function() { onFailedAuthorization(); },
    scope: { read: true, write: true}
});
function onAuthorizeSuccessful() {    
    Trello.post("cards", { name: "Card created for test", desc: "this is a test",  idList: "........", due: null, urlSource: null});
        }
    });
}

我有JQuery和Trello API。出于安全目的,我在代码中清空了 idList。我确认代码确实执行了onAuthorizeSuccess()函数。

如何修改此设置以创建 Trello 卡?

function Auth() {    
   Trello.authorize({
                type: 'popup',
                name: 'your app name',
                scope: {
                    read: true,
                    write: true },
                expiration: '30days',
                success: authenticationSuccess,
                error: authenticationFailure
            });
    var authenticationSuccess = function(data){ /*your function stuff*/};
    var authenticationFailure = function(data){ /*your function stuff*/};
}

这段代码对我有用。 我得到按钮单击时触发的函数 Auth()。

此外,您可能对过期的令牌有一些问题,因此Trello.deauthorize();可用于创建新卡失败功能(这完全取决于创建新卡错误消息)。

关于创建新卡...

var newCard = 
          {name: jQuery('input#tc_title').val(), 
          desc: jQuery('textarea#tc_desc').val(),
          pos: "top", 
          idList: trello_list_id_var
          };
Trello.post('/cards/', newCard, success, error);
var success = function(data){ /*..............*/}
var error= function(data){ /*..............*/}

在成功/错误函数中,您可以检查错误数据

编辑:另外,我认为Trello.post("cards" ...应该替换为可能是问题的Trello.post("/cards/" .........