Query all groups and specific column values

I am having a difficult time figuring out how to configure my query to get the desirable information.

I have a board with about 500 groups. Each group can have any where between 1 to 100 items. I need my query to gather each groups “id” and “title”. Within that I need every item with it’s “id”, “name”, and a specific “column_values” based on a provided column id. Within the “column_values”, I need it’s “value” and “id”. A final return would look something like this:

{'group': {'id': '12345_y4321_00___nags_head_', 'title': '12345-R039177.00 - Nags Head', 'items_page': {'items': [{'id': '12345', 'name': 'Echo', 'column_values': [{'value': None, 'id': 'phase'}]}, {'id': '56789', 'name': '02 - Admin', 'column_values': [{'value': '"0001 - 0001 Project Management"', 'id': 'phase'}]}]}}}

I was hitting some query limits, and read that I should be use next_items_page and cursor. I can then append each query to a list and iterate through each list for the rest of my processes. My code is producing almost exactly as what I need, however it’s only selecting 25 items within a group. I think I need to add or move one of my item_page methods. I’ve been on this problem for a few hours now and need a couple of pointers of what I am doing wrong.

Python3.10 Code

    created_board_id = "12345"
    phase_col_id = cid_dict['Phase'][0]

    # Query group and items
    start_time = timeit.default_timer()
    next_section = True
    group_board_info = []
    query_page = f"""
        {{
            boards (ids: {created_board_id}) {{
                items_page (limit: 1) {{
                    cursor
                    items {{
                        group {{
                            id
                            title
                            items_page (limit: 100) {{
                                items {{
                                    id
                                    name
                                    column_values (ids: [{json.dumps(phase_col_id)}]) {{
                                        value
                                        id
                                    }}
                                }}
                            }}
                        }}
                    }}
                }}
            }}
        }}
        """

    data = {'query' : query_page}
    r = requests.post(url=apiUrl, json=data, headers=headers)
    r_dict = r.json()
    section_board_info = r_dict['data']['boards'][0]['items_page']
    group_info = section_board_info['items']
    next_cursor = section_board_info['cursor']
    group_board_info.append(group_info)

    while next_section:
        # First item limit is X-times will get group data per item row
        # Second item limit is amount of column
        query_next_section = f"""
        {{
            next_items_page (limit: 1, cursor: {json.dumps(next_cursor)}) {{
                cursor
                items {{
                    group {{
                        id
                        title
                        items_page (limit: 100) {{
                            items {{
                                id
                                name
                                column_values (ids: [{json.dumps(phase_col_id)}]) {{
                                        value
                                        id
                                }}
                            }}
                        }}
                    }}
                }}
            }}
        }}
        """
        data = {'query' : query_next_section}
        r = requests.post(url=apiUrl, json=data, headers=headers)
        r_dict = r.json()

        section_board_info = r_dict['data']['next_items_page']
        group_info = section_board_info['items']
        next_cursor = section_board_info['cursor']
        group_board_info.append(group_info)

        if next_cursor is None:
            next_section = False

Hello there @Binx96,

That is odd. If you are using a limit of 100, it should give you 100 items.

Please send us an email to appsupport@monday.com with:

  1. Your full query (including IDs)
  2. The full response you get
  3. The last time you tested it (if you can, please run it now) including date, hour, minute and the user whose API token is being used for the query

We can take a look from there :grin:

Cheers,
Matias

1 Like

Hi @Matias.Monday,

Prior to sending that email, there are two important things I wanted to point out that I found with items_page (limit: #). They are mentioned under my while loop.

  1. The First item limit is querying the group data per item row. For example:
query_next_section = f"""
        {{
            next_items_page (limit: 3, cursor: {json.dumps(next_cursor)}) {{
                cursor
                items {{
                    group {{ .......
>>>
{'group': {'id': '12345_y4321_00___nags_head_', 'title': '12345-R039177.00 - Nags Head', 'items_page': {'items': [{'id': '12345', 'name': 'Echo', 'column_values': [{'value': None, 'id': 'phase'}]}, {'id': '56789', 'name': '02 - Admin', 'column_values': [{'value': '"0001 - 0001 Project Management"', 'id': 'phase'}]}]}}}
{'group': {'id': '12345_y4321_00___nags_head_', 'title': '12345-R039177.00 - Nags Head', 'items_page': {'items': [{'id': '12345', 'name': 'Echo', 'column_values': [{'value': None, 'id': 'phase'}]}, {'id': '56789', 'name': '02 - Admin', 'column_values': [{'value': '"0001 - 0001 Project Management"', 'id': 'phase'}]}]}}}
{'group': {'id': '12345_y4321_00___nags_head_', 'title': '12345-R039177.00 - Nags Head', 'items_page': {'items': [{'id': '12345', 'name': 'Echo', 'column_values': [{'value': None, 'id': 'phase'}]}, {'id': '56789', 'name': '02 - Admin', 'column_values': [{'value': '"0001 - 0001 Project Management"', 'id': 'phase'}]}]}}}
  1. The second limit is amount of columns. For example:
              ......
                    group {{
                        id
                        title
                        items_page (limit: 1) {{
                            items {{
                                id
                                name ......
>>>
{'group': {'id': '12345_y4321_00___nags_head_', 'title': '12345-R039177.00 - Nags Head', 'items_page': {'items': [{'id': '12345', 'name': 'Echo', 'column_values': [{'value': None, 'id': 'phase'}]}]}}}

So if we were to put these two limits together, we would get the following output:

>>>
{'group': {'id': '12345_y4321_00___nags_head_', 'title': '12345-R039177.00 - Nags Head', 'items_page': {'items': [{'id': '12345', 'name': 'Echo', 'column_values': [{'value': None, 'id': 'phase'}]}]}}}
{'group': {'id': '12345_y4321_00___nags_head_', 'title': '12345-R039177.00 - Nags Head', 'items_page': {'items': [{'id': '12345', 'name': 'Echo', 'column_values': [{'value': None, 'id': 'phase'}]}]}}}
{'group': {'id': '12345_y4321_00___nags_head_', 'title': '12345-R039177.00 - Nags Head', 'items_page': {'items': [{'id': '12345', 'name': 'Echo', 'column_values': [{'value': None, 'id': 'phase'}]}]}}}

That being said, I can set my first limit to 1 and my second limit to 100 to ensure that I only query the group once and account for all of my columns. Though, I still have the problem that I don’t know how to query more than 25 items from each group.

Does all that make sense?

Hello again,

I am not sure I follow how you are using these two together.

Please send this over via email with your full query and everything detailed in the last message and we will take a look into it :grin:

Cheers,
Matias

1 Like

Work with Monday’s support team to resolve this issue and wanted to report my findings. The items_page limit functionality does if fact work as expected. After digger further I found that my query needed to changed.

First I needed to query through and find all my group ids. Then I loop through each group to query out the necessary data and append it to an list. Fortunately I will likely never have a group with over 500 items so the max limit will never be hit. However, if that is the case (or I decide to choose a different limit threshold), I would need to loop the additional cursors through the next_items_page functionality. Note that this functionality has to be called as a root and cannot be imbedded into the query I currently have.

Happy to discuss more if anyone has any remaining questions.

group_board_info = []
    for group_id in group_id_list:

        query_groups = f"""
        {{
            boards (ids: {created_board_id}) {{
                groups (ids: {json.dumps(group_id)}) {{
                    title
                    items_page (limit: 50) {{
                        cursor
                        items {{
                            id
                            name
                            column_values (ids: [{json.dumps(phase_col_id)}]) {{
                                value
                                id
                            }}
                        }}
                    }}
                }}
            }}
        }}"""

        data = {'query' : query_groups}
        r = requests.post(url=apiUrl, json=data, headers=headers)
        r_dict = r.json()
        
        section_board_info = r_dict['data']['boards'][0]
        group_board_info.append(section_board_info)
1 Like