Query specific columns in multiple boards

Any help is appreciated - please be patient with me as I am new to this. I am trying to do something that I think can probably be done easily, but can’t figure out how to do it. Basically I want to search 2 different boards for a specific value in a specific column, and return any items that match. For example, order number 12345678; in one board, this may be in the column with column ID “text0” and on the other board it may be under column ID “text24” -so I want to return:

any items on board 1 where the value of text0 is 12345678
and
any items on board 2 where the value of text24 is 12345678

When I only try to query a single board, it works with no problems (see below)

query {  
  boards (ids:[MY_BOARD_1]){
    items_page (
      query_params: {
        rules: [
          {            
            column_id: "text0",
            compare_value: "12345678",
            operator: any_of
          }
        ]
        # will have other rules here, but have removed them to keep this example simple
        operator: or
      },
      
    ) {
      items{id board {
        id
      } column_values (ids: ["creation_log","status","status2"]){text}}
    }   
  }  
}

This, however, does not work:

query {  
  boards (ids:[MY_BOARD_1, MY_BOARD_2]) { 
    items_page (
      query_params: {
        rules: [
          {            
            column_id: "text0",    #this is meant to be queried from the first board
            compare_value: "12345678",
            operator: any_of
          },
          {
            column_id: "text24",    #this is meant to be queried from the second board
            compare_value: "12345678",
            operator: any_of
          }
        ],
        operator: or
      },
      
    ) {
      items{id board {
        id
      } column_values (ids: ["creation_log","status","status2"]){text}}
    }   
  }  
}

My expected output for the second bit of code is that it would return the details for the item(s) on board 1 with a “text0” value of “12345678” and that it would return the item(s) on board 2 with a “text24” value of “12345678” - and that it would not even attempt to return values for “text24” on board 1 and “text0” on board 2 because these columns do not exist on those boards.

However, I get the error “Column not found” which seems to be because it is searching both boards for both fields and stopping if both fields don’t exist on both boards - in other words it is searching board 1 by “text0” and “text24” and then searching board 2 by “text0” and “text24”. Since the boards don’t use all the same column names, this will not work; I need it to search board 1 only by “text0” and board 2 only by “text24” (or if it has to search by both columns on both boards, I just need it not to return anything for a particular column when that column doesn’t exist on the board in question, rather than giving an error that stops any part of the process from working). I’m not sure how a multi-board query would even work if it relies on both boards having the same set of column IDs, which is often not the case.

I have searched extensively for solutions, but any examples of something similar only search a single board. However, it seems like there must be a way to do what I need to do, as it accepts the argument board (ids: ) and not board_id or some other phrasing that indicates it would need to be singular. It also recognizes, when testing, that 2 boards have been specified, and the only issue seems to be that just can’t find both columns on both boards (which again, they don’t both need to be on both boards for my needs, it just needs to skip over columns it can’t find rather than breaking).

I am really stuck on this, so suggestions would be very helpful. Thanks for reading this!

Hi Sam,

Welcome to the community! At this time, it is not available to query for different columns on different boards within the same query. You can query for multiple boards in a boards query, but query_params will look for the column_id in both boards, which in your case, is not true. So this is expected behavior. Thank you for your understanding.

Best,
Joseph

Thanks for taking the time to reply. That’s disappointing, but good to know so I don’t keep spending time on trying to figure out out to do it.

I suppose I could return every item on every board I wish to search, and manipulate the returned values (outside of Monday API) to exclude the ones I don’t need; this seems like it is doing a lot more processing than what I need. To make sure I’m understanding clearly though, there’s no other method or workaround that would allow me to search more than board for a specific value? (Even one that is not based on my code, but takes a different approach entirely, would be fine if there is some way this can be accomplished.) Anyway, thanks again for your help.

Edit: I think I found a solution. I didn’t know that you could run more than one query in sequence. This seems like it will work for me. Once I have something functional I will post back here in case it might be helpful to anyone else.

Update: this seems to work for me. Thanks again for your help Joseph!

query{    
  firstQuery: boards (ids: MY_BOARD_1) { 
    items_page (
      query_params: {
        rules: [
          {            
           column_id: "text0",
            compare_value: "12345678",
            operator: any_of
          },
          #{            
          #  more criteria will go here
          #}
        ],
        operator: or
      },
      
    ) {
      items{id board {
        id
      } column_values (ids: ["creation_log","status","status2"]){text}}
    }   
  }
  secondQuery:  boards (ids: MY_BOARD_2) {  
    items_page (
      query_params: {
        rules: [
          #{            
          #  more criteria will go here
          #},
          {
            column_id: "text24",
            compare_value: "12345678",
            operator: any_of
          }
        ],
        operator: or
      },
      
    ) {
      items{id board {
        id
      } column_values (ids: ["creation_log","status","status2"]){text}}
    }  
  }
}

Where you landed is a solution. But my question is if the load is so heavy that cutting the number of requests this way vs just making requests for each board is worth it?

Just challenging you if this is premature optimization.