How do I access the trello API from Powerup?

How can I make requests against the trello API due to powerup? This seems like such an obvious question, but it doesn't seem to be covered, which I can find.

My simple powerup looks like this:

var boardButtonCallback = function(t){
  return t.popup({
    title: 'Tools',
    items: [
      {
        text: 'Hide Duplicates',
        callback: function(t){

          var cardQueryCb = function(result){
            console.log(result);
          }
          var cardQ = 'https://trello.com/1/boards/[board_id]/cards/all';
          fetch(cardQ).then(function(response) {
            return response.json();
          }).then(function(data) {
            console.log(data);
          });

          return t.cards('id', 'name')
          .then(cardQueryCb);
        }
      }
    ]
  });
};

TrelloPowerUp.initialize({
  'board-buttons': function(t, options){
    return [{
      text: 'Duplicates',
      callback: boardButtonCallback
    }];
  }
});

      

The response object after a call to retrieve says that the call is unauthorized.

I would have thought that calling this code from the power-on context would be considered authorized. While I am logged into trello, I can post this address in my browser and get the correct answer - why does the javascript call also not result in a valid response?

More importantly, how can I get a successful response from this URL?

+3


source to share


1 answer


Since your power start is done through the iframe, it doesn't actually exit the Trello page itself, so you need to include your API key and token in the GET url.

Example:



https://api.trello.com/1/boards/560bf4298b3dda300c18d09c?fields=name,url&key={YOUR-API-KEY}&token={AN-OAUTH-TOKEN}

Information on getting API key and token can be found here: https://trello.readme.io/v1.0/reference#api-key-tokens

+1


source







All Articles