What exactly does the Trello REST API return when I request the boards?

Viewed 321

Question

I'm trying to request all of the boards that my account is in. When I make the request, I do it to a custom class package that I made. I know that it works because it does return something, but I just am not sure where to look for the actual information about my boards.

Code

This is where I am pointing my request to.

GET https://api.trello.com/1/members/me/boards?fields=name,url&key=${this.key}&token=${this.token}

This is what I my package is using to make the request.

getBoards(callback) {
        fetch(`https://api.trello.com/1/members/me/boards?fields=name,url&key=${this.key}&token=${this.token}`,{
            method: 'GET'
        })
            .then(r => {
                callback(r,false)
            })
            .catch(e => {
                callback(null,e)
            })
    }

And this is what I am using to request the package's function.

const boards = trello.getBoards((boards,err) => {
            if (err) {
              console.log(err);
            } else {
              // do stuff with the boards
            }
          })

Results

Response {
  size: 0,
  timeout: 0,
  [Symbol(Body internals)]: {
    body: Gunzip {
      _writeState: [Uint32Array],
      _readableState: [ReadableState],
      readable: true,
      _events: [Object: null prototype],
      _eventsCount: 6,
      _maxListeners: undefined,
      _writableState: [WritableState],
      writable: false,
      allowHalfOpen: true,
      _transformState: [Object],
      _hadError: false,
      bytesWritten: 0,
      _handle: [Zlib],
      _outBuffer: <Buffer 5b 7b 22 6e 61 6d 65 22 3a 22 44 69 73 63 70 6c 69 6e 65 20 44 61 74 61 62 61 73 65 22 2c 22 69 64 22 3a 22 35 66 61 38 30 63 34 61 61 64 66 30 39 61 ... 16334 more bytes>,
      _outOffset: 0,
      _chunkSize: 16384,
      _defaultFlushFlag: 2,
      _finishFlushFlag: 2,
      _defaultFullFlushFlag: 3,
      _info: undefined,
      _level: -1,
      _strategy: 0,
      [Symbol(kCapture)]: false
    },
    disturbed: false,
    error: null
  },
  [Symbol(Response internals)]: {
    url: 'https://api.trello.com/1/members/me/boards?fields=name,url&key=xxxxxxxx&token=xxxxxxxx',
    status: 200,
    statusText: 'OK',
    headers: Headers { [Symbol(map)]: [Object: null prototype] },
    counter: 0
  }
}

I have four boards and am looking for the ID of a specific board. Does anybody know what this returns? Thanks in advance.

1 Answers

I've figured out the issue. Seems like the package that I was using, node-fetch had some weird thing to do with promises on response. Basically, what I did to solve this issue was form the response into a promise, return it, then get it again, which would return the actual response. This has nothing to do with trello or any REST API out there, but when using node-fetch I need to do that promise thing.

fetch(`https://api.trello.com/1/cards/${card.id}/customFieldItems?key=${process.env.TRELLOAPIKEY}&token=${process.env.TRELLOAPITOKEN}`,{
  method: `GET`
})
  .then(response2 => response2.text()) // Important Line
  .then(res2 => {
    res2 = JSON.parse(res2); // Variable res2 will be the data
  })
  .catch(err2 => {
    console.log(err2);
  })
Related