norberteder / trello

Use the Trello API from Node
332 stars 250 forks source link

How to use getCardsOnBoardWithExtraParams? #70

Open nillswe opened 5 years ago

nillswe commented 5 years ago

Hello, i'm trying to use getCardsOnBoardWithExtraParams, but i don't know what i'm doing wrong. I want to return only cards with due date equals false.

let params = { dueComplete: false }
let boardId = "......"
 trello.getCardsOnBoardWithExtraParams(boardId, params)
 .then(boards => {
// My implementation
})

Can anyone help me? Thanks!

mgaruccio commented 5 years ago

That looks correct as far as the syntax goes, are you getting an error or an incorrect list returned?

nillswe commented 5 years ago

That looks correct as far as the syntax goes, are you getting an error or an incorrect list returned?

Hi mgaruccio, thanks for answering. it return an incorrect list. I was reading trello api docs and i think that don't have this kind of filter. So i did like this:

let boardId = "......"
 trello.getCardsOnBoard(boardId)
 .then(cards => cards.filter(card => card.dueComplete === false))
.then(cardsNotDone => {
// code
})

I did not like to do this way because it weighs down my search. It returned all of my cards then i do my filter. Have another way?

mrjohnskelton commented 5 years ago

Hi all - I've done some fiddling and I think I've got to a more accurate understanding...

The answer lies in the interaction between trello and restler (which is handling the building of the actual RESTful url to Trello

restler is expecting trello to pass it ...(url, query), where query is of the form:

{query: {filter: '___'}}

The core trello getter functions handle putting your Trello API key and token onto the query JSON (and hence passed to Trello via restler) - the ExtraParams are the additional json you want adding on - i.e. a json representation of the string filter you'd add on the Trello url

As an example, a 'getCommentsForCard' method, with a hard-wired filter would look like:

Trello.prototype.getCommentsOnCard = function (cardId, callback) {
  var query = this.createQuery();    
  Object.assign(query, {'filter': 'commentCard'});
  return makeRequest(rest.get, this.uri + '/1/card/' + cardId + '/actions', {query: query}, callback);
};

Note that the makeRequest call line creates the query json for restler, the Object.assign adds the filter json required by Trello API to the value part of that json.

After going through trello and restler, this would result in a url to Trello along the lines of:

https://.../actions?filter=CommentCard&key=...&token=...

So @niltonslf - your original code would have been building a json 'query' of the form:

{query:
  {params: 
    {dueComplete: false}
  }
}

Which Trello wouldn't have understood.

Instead, I think it should have been along the lines of:

let params = {filter: { dueComplete: false }}

...need to crack on with my own use case so not had time to test out my understanding on your part of the API. Even if its not exactly correct I hope it points you in the right direction. :-)

mrjohnskelton commented 5 years ago

As a P.S. to previous comment, I can commit some code to get card attachments and get card comments with the latter showing a hard-coded filter example. Don't know how to drive github and permissioning to create a pull request/branch though.