Python script, graphql fetching subitems = Query has complexity > 5000000

I am trying to run a quick query on python trying to fetch a lot of subitem information. Then I get the following error:

{'errors': [{'message': 'Query has complexity of 11010020, which exceeds max complexity of 5000000', 'extensions': {'code': 'maxComplexityExceeded', 'complexity': 11010020, 'maxComplexity': 5000000}}], 'extensions': {'warnings': [{'message': 'Replaced by Board.items_page in 2023-10', 'locations': [{'line': 4, 'column': 9}], 'path': ['query', 'boards', 'items'], 'extensions': {'code': 'deprecatedField', 'typeName': 'Board', 'fieldName': 'items'}}]}, 'account_id': 16336358}

The query is:

query = fβ€™β€˜β€™
query{{
boards(ids: board_id){{
items{{
subitems{{
column_values{{
title
}}
}}
}}
}}
}}
β€˜β€™β€™
And the script is as simple as this:

import requests
import pandas as pd
import os
import json

api_key = api_key
url = f'https://api.monday.com/v2'
headers = {
    'Authorization': api_key
}

query = query (above)
response = requests.post(url, headers=headers, json={'query': query})
rjson = response.json()
print(rjson)

Obviously it fails on the response.

Is it possible to get this items?

The idea is to create some dataframes with pandas and toy with the information.

Hello there @juholaan1,

That is a deprecated query. You can use items_page instead (as explained here).

For example:

{
  boards(ids: 11111) {
    items_page(limit: 10) {
      items {
        name
        id
        subitems {
          name
          id
          column_values {
            value
            text
          }
        }
      }
    }
  }
}

I hope that helps!

Cheers,
Matias

1 Like

Hello @Matias.Monday, thank you so much for you answer. I have tried that code directly on the playground and it definetevely works, but when I tried to replicate the query on my python script I get the following error:

{'errors': [{'message': "Field 'items_page' doesn't exist on type 'Board'", 'locations': [{'line': 4, 'column': 5}], 'path': ['query', 'boards', 'items_page'], 'extensions': {'code': 'undefinedField', 'typeName': 'Board', 'fieldName': 'items_page'}}], 'account_id': 16336358}

Can you please provide some insights regarding this issue?

Make sure you’re passing the API-Version header with one of the current versions in there (2023-10, 2024-01, 2024-04) :slight_smile:

Best,
Rachel

1 Like

Hello Rachel,

This completely solves my doubt, it works to update the header to:

headers = {
    'Authorization': api_key,
    'API-Version' : '2024-01'
}

Thanks a lot

1 Like

That is great @juholaan1!

Let us know if you need anything else!

Cheers,
Matias

1 Like