Finds all items in which a specific column has a specific value

Hi all
I’ve been trying to create a query for about 6 hours which I think is pretty straightforward.
Given a certain board, find all the elements in which the State column is valued with “YES” and the Number column is greater than 3, but i am not finding solution.
Can you give me a case study that I can study and understand?
Unfortunately I’m not understanding much from the API documentation.
Thank you

Hi @jackalope,

You could use the Items query to achieve this, for example:

query {
  items (ids: 123456789) {
    column_values (ids: ["status", "numbers"]) {
      value
      id
    }
  }
}

You can work with this response to parse out the items whose values match your conditions (“YES” and “>3”)

I hope this helps!

Thanks Alessandra.
Thanks to your suggestion i created this query:

 {
   boards (ids:3948979414) {
     id
     name
     items {
       column_values (ids: ["person", "status", "date4"]){
         id
         text
       }
     } 
   }
 }

I get status text and date text (i changed “number” with date) inside the given board.
Now, the goal I would like to achieve is to extract only the items where status = YES and date = “01/01/2023”.
Subsequently extract the owner for these (“person” column) and send them a notification linked to the item that I have recovered.
Is it possible to do this?
thanks

Hi @jackalope

I think your best option for this would be using the items_by_column_values query - Items By Column Values

This will allow you to get all items based on the status (or another column if you prefer), you can then loop through the returned items and filter based on your other column values.

A query like this would work:

query {
    items_by_column_values (board_id: 1234567, column_id: "status5", column_value:"YES") {
        id
        name
        column_values (ids: ["person", "status", "date4"]){
             id
             text
             value
       }
    }
}

Currently you can only search based on a single column.

1 Like

Thanks Mitchell. Tomorrow i will test you case-study and i will give you the final result.
Last but not least: with this solution (testing just one column) can i set a test, for example, on the date column and extract all the rows with the date4 column empty?

Thanks

Thanks Mitchell. Your suggestion works perfectly. Unfortunately i cannot query more than one column and i cannot query null columns but it’s something i can start with.

Regards

A quick side note.
The items_by_column_values has a delay in returning changed values. After you change any data on your board, it might take sometime for it to finally propagate into the API. You can test it out changing some data on your board and querying right away.
The query might return the previous data.
Current workaround is to wait for some seconds after the data is changed on your board before querying or query every item on your board and filter them by their column values

1 Like

Thanks kolaai for this note. I actually noticed that it takes a while to update the results recovered following a value change but for us it’s passable in terms of timing

1 Like