Graphql query for all items in a board that have a particular column:value

I am using the following query to get all column values for a board:

let jobsQuery = { boards (ids: ${cfg.jobBoardId}) { items { id name column_values { id title value } } } };

It’s running in NodeJS. It’s working great, returning all the items.

I’d like to narrow the search to only return items that have a particular column set to a particular value.

Based on the current dataset returned, it’s the data in ‘name’ that should be used to narrow the search.

I tried the following:

let jobsQuery = { boards (ids: ${cfg.jobBoardId}) { items (names: ${cfg.jobName}) { id name column_values { id title value } } } };

But that didn’t work, it just returns an empty list.

What would I need to update my query to, so as to return the same data structure and columns, but only the subset that match name === cfg.jobName?

Hi @mjgs

The field items does not have an argument “name”, it’s a good practice to use the API playground to see what arguments are accepted by which fields.

There is another query that gets the items by column value:

query{
items_by_column_values(board_id: 1234567890, column_id: “name”, column_value: “My Name”) {
id
name
}

This one will return the itemIds and names for all items that have the name “My Name” in the board 1234567890
}

Hi @mjgs, welcome to our community!

I agree with @basdebruin here that the best thing to do in this case would most likely be to utilize the items_by_column_values() query that will return a set of items based off of a particular column’s value.

I would definitely try out his example to see if it works for you and your use-case.

Let us know if not and we can continue offering examples and ideas.

I got it working with a variation of your query. I had to do the following:

  1. Escape the double quotes around name, since single quotes weren’t accepted, and the double quotes messed up the json passed in the fetch request
  2. Add the column_values
  3. Update how I was handling the returned data as it looked a bit different, got returned inside a tems_by_column_values key

The final query was:

const jobsQuery = { items_by_column_values(board_id: ${cfg.jobBoardId}, column_id: \"name\", column_value: \"${cfg.companyId}\") { id name column_values { id title value } } };

Thanks!

1 Like

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