如何使用Trello JS API创建卡片

时间:2015-01-30 06:42:51

标签: javascript jquery json api trello

我一直试图通过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。我确认代码确实执行了onAuthorizeSuccessful()函数。

如何修改此项以创建Trello卡?

1 个答案:

答案 0 :(得分:0)

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/" ...可能是问题...