Fetching columns title and id

I am trying to fetch the column title and their id’s of a particular board by passing its id(boardId) but I am getting the result of all the boards that are there in my workspace.
Can anybody help me out if i want to have the result for that particular board only?

Note : When I try the same query on API Playground,I get a perfect result.

@basdebruin can you please suggest?

hi @aquibk

I am using this function to do just that (returning also few other fields)

  static async getBoardColumns(token, boardId) {
try {
  const mondayClient = initMondayClient({ token });

  const query = `query($boardId: [Int]) {
    boards (ids: $boardId) {
      columns {
  const variables = { boardId };
  const response = await mondayClient.api(query, { variables });
  this.checkThrowError(variables, response, token);
  return response.data && response.data.boards[0] ? response.data.boards[0].columns : false;
} catch (err) {
  return false;


When calling this function make sure you pass an Int value as the boardId. I always parseInt all board and item id’s just to be on the safe side.

Thank you for your quick response but If you can see my screenshot, I am also doing the same way but still not getting the specific result though its working fine in Playground.
I have tried the other ways as well both on Playground and Code but its only fruitful on Playground not in the application.

Hi @aquibk!

What does it look like if you click into one of the boards in the returned array?


Your query looks good to me, so I’m not sure why you would be getting returned all your boards!


@Helen I am getting column list of a board when I click on the array ,where I want to get the specific for just one board whose id I am passing into the query

The problem is with the variable. It is supposed to be variables not variable

const variables = {boardId};
const response = await mondayClient.api(query, {variables});

Thank you so much…!!

It really worked…!!

But I still have a doubt why is it mandatory to have the variable name as variables, It should have worked the same for any other as well?
Or Is it something related to the predefined variable for Graphql?

The api takes an object with a property name of variables and other properties as a second parameter. By using another other property name apart from variables, that property doesn’t exist and therefore, the API wouldn’t recognize that property. It’s the same as going to the playground and providing no variables at all. It will return all the data just as it returned in your case.
If you want to use any other name apart from variables, then use will have to write the object key and value in full. Since the variable is called variable and the property name is also variable,we can object the value and JavaScript will reference the variables property automatically.
Here is an example of using another variable name instead of variables

const hello = {boardId};
const response = await mondayClient.api(query, {variables: hello});

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.