I am using the Monday API to pull data via Python. I am using the following code:
def monday_fetch_and_process_data(api_key, board_id):
# API Endpoint
url = “https://api.monday.com/v2”
# Query to get items from a specific board
query = '''
{
boards(ids: %s) {
items {
name
column_values {
title
text
}
}
}
}
''' % board_id
# Headers
headers = {
'Authorization': api_key,
'Content-Type': 'application/json'
}
# Make the API Request
response = requests.post(url, json={'query': query}, headers=headers)
data = response.json()
Everything has been running smoothly until this morning, where I get this error when running the code:
API Response: {‘errors’: [{‘message’: “Field ‘items’ doesn’t exist on type ‘Board’”, ‘locations’: [{‘line’: 4, ‘column’: 9}], ‘path’: [‘query’, ‘boards’, ‘items’], ‘extensions’: {‘code’: ‘undefinedField’, ‘typeName’: ‘Board’, ‘fieldName’: ‘items’}}], ‘account_id’: 4064623}
I would greatly appreciate if someone can help me.
And use this function to get all the data in the board. Make sure you specify all variables :
headers = {‘Authorization’: api_key, ‘Content-Type’: ‘application/json’}
def fetch_items(api_key, board_id, url, cursor=None):
while True:
# Include the cursor parameter if it’s provided
cursor_param = f’cursor: “{cursor}”’ if cursor else ‘’
query = f"“”
{{
boards(ids: {board_id}) {{
items_page(limit: 50, {cursor_param}) {{
cursor
items {{
id
name
column_values {{
column {{
title
}}
text
}}
}}
}}
}}
}}
“”"
response = requests.post(url, headers=headers, json={‘query’: query})
data = response.json()
if ‘data’ in data and ‘boards’ in data[‘data’] and len(data[‘data’][‘boards’]) > 0:
items_page = data[‘data’][‘boards’][0][‘items_page’]
items = items_page[‘items’]
next_cursor = items_page[‘cursor’]
for item in items:
item_id = item[‘id’]
item_name = item[‘name’]
# Check if ‘column_values’ key exists before accessing it
column_values = item.get(‘column_values’, )
column_values_dict = {column[‘column’][‘title’]: column[‘text’] for column in column_values}
print(f"Item ID: {item_id}, Item Name: {item_name}, Column Values: {column_values_dict}")
# Break the loop if there is no next page
if not next_cursor:
break
# Set the cursor to the next_cursor value for the next iteration
cursor = next_cursor
else:
print(“No data available or invalid board ID”)
break
Hi, @Cindy. Thank you for sharing this snippet. It really helped me. One issue I am having now is that the values from columns that are connected to other boards are coming up as None, which seems to be a pretty bizarre behaviour by the API.
Would anyone here have any idea how to get those values too.
Would anyone know how to simply pull all rows of a given dashboard? The query above returns None to some of the columns even though I can see that the field is not empty in the UI
I think its likely youre running into None values due to having board relation values/Dependency values/Mirror values that you arent specifically asking for. The October 2023 API updates made it so they have to be specifically asked for to limit overhead
Here is a query I use to grab every column for a specific item name on a given board. If you remove the query_params line it will grab all items on the given board up to the given limit
Please note, for any formula values on your dashboard those will always return blank as the formulas are calculated on the client and therefore cannot be accessed by the API
Thanks, @Adam.B! I am trying to test your query on the API playground here. What would be the compare_value parameter? I am not sure what value to pass there.
My use case entails pulling all the rows and all the columns from the board. Would those rules still be required in this case?
I have tried to investigate the schema and the documentation, but graphql seems to be the main issue for me. It is as if I had to learn a whole new query language just to automate a simple board export
No problem @tlgemp
You can use any item name for that value (item name being the first column on a table) but that line isnt actually necessary. If you simply want all the items on the table you can remove the “query_params” line entirely. Then it will display the first N items of the table (where N is the limit you set on the line above)
I use the compare value since im generally looking for exactly one item in a table based on a serial number.
Hopefully that works for you!
EDIT: Regarding your edits, I think removing the query parameter line should allow you to pull all the rows and columns from a board. The other rules (on MirrowValue/BoardRelationValue/DependencyValue) would be required if your board has linkages to other boards (eg connected columns and mirror columns)
Additionally, some column types are wholly unsupported for export, such as formula columns where the display value cant be export via the API since it is calculated client side. You may be able to pull the formula from the API somehow but im not sure so youd have to dig into the documentation.
Good luck with GraphQL! It definitely is a change from the more common RESTful API so yeah it is kind of a new query language to learn. And I am definitely no expert myself.
Previously, you could directly access items within the boards object. However, Monday.com has enrich customer data, and now you need to use a different field to access them.
Instead of requesting items directly under boards, use the items_page field. This field retrieves a paginated list of items for a board.
Here’s the updated query:
query = ‘’’
{
boards(ids: “%s”) {
items_page(limit: 100) { # Adjust limit as needed
name
column_values {
title
text
}
}
}
}
‘’’ % board_id
Hi guys, thanks a lot for the great help. I can now read out the data again. However, I now have the problem that columns that are created as formulas in Monday are no longer transferred. Can anyone help me here? The column is indeed in the answer, but there is no text in it.
I am working with an organization that gave me a APIKEY and a Temporary Email to use and that email is meant to have access to boards that I need data for. However I don’t have the Board IDs. Is that required to use the Python API techniques shown here? If I do need the board ID and acquire it, do I need to know anything about the fields in the board before I go to capture them?