简体   繁体   中英

How to use Trello JS API to create a card

I've been trying to utilize the Trello API via JSFiddle and haven't been able to get it to work (I have very limited JS/JSON knowledge). I need to create a card under a specific list, using the 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});
        }
    });
}

I have JQuery and the Trello API included. I blanked out the idList in the code for security purposes. I confirmed that the code does execute the onAuthorizeSuccessful() function.

How can I modify this to create a Trello card?

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*/};

}

this code works for me. i get function Auth() triggered on button click.

Also, you might have some issues with tokens which are expired, so Trello.deauthorize(); could be used on create new card failure function (it all depends on create new card error message).

regarding the create a new card...

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){ /*..............*/}

in success/error functions you are able to check the error data

EDIT: also i think that Trello.post("cards" ... should be replaced with Trello.post("/cards/" ... that might be the problem...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM