prodperfect / monday Goto Github PK
View Code? Open in Web Editor NEWPython client for Monday.com
Home Page: https://github.com/ProdPerfect/monday
License: BSD 3-Clause "New" or "Revised" License
Python client for Monday.com
Home Page: https://github.com/ProdPerfect/monday
License: BSD 3-Clause "New" or "Revised" License
Hi - I received an error while trying to retrieve data from one of our Monday boards using fetch_items_by_board_id
. The error was caused by the breaking changes announced here: https://developer.monday.com/api-reference/docs/migrating-to-v-2023-10
I checked the source code in query_joins.py and updated the query I needed under get_board_items_query
to this:
query
{
boards(ids: %s) {
name
items_page (%s) {
cursor
items {
id
name
column_values {
column {
id
title
}
id
type
value
}
}
}
}
}
That solved my issue. Would be nice to get a new release to account for the changes. Happy to help, just haven't really contributed to another package before.
There is a missing (and rather useful) method to allow users to create new boards at ease.
mutation {
create_board (board_name: "my board", board_kind: public) {
id
}
}
I have implemented such a simple function to let us create a board with an optional parameter to determine its workspace.
create_board(board_name, board_kind [, workspace_id])
Pull Request (#60) created
When running the below example: (Note, I removed my token and boardID for security)
from monday import MondayClient
monday = MondayClient('****Token****')
monday.items.create_item(board_id='**boardid**', group_id='today', item_name='Do a thing')
I get the following error, have I missed something?
File "C:\Python39\lib\site-packages\monday\resources\items.py", line 14, in create_item
return self.client.execute(query)
File "C:\Python39\lib\site-packages\monday\graphqlclient\client.py", line 12, in execute
return self._send(query, variables)
File "C:\Python39\lib\site-packages\monday\graphqlclient\client.py", line 41, in _send
raise e
File "C:\Python39\lib\site-packages\monday\graphqlclient\client.py", line 37, in _send
response.raise_for_status()
File "C:\Python39\lib\site-packages\requests\models.py", line 960, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.monday.com/v2
@all-contributors please add @pevner-p2 to code
Hi there,
I've got a problem with the function : .items.change_multiple_column_values
I can't succeed to change the date on monday.
Maybe I didn't fond the good way to send my datas.
I tried :
Hi all! Wondering if there is a plan to refactor this client to support the new 2023-10 api version with breaking changes?
Thanks!
https://developer.monday.com/api-reference/docs/migrating-to-v-2023-10
When creating an item through the API, the item name is specified as a separate argument:
MondayClient(<key>).items.create_item(
board_id=<board_id>,
group_id=<group_id>,
item_name='"A" name,
column_values={"key": '"A" value'},
)
However, the "
s are not escaped and will therefore generate a faulty query:
mutation
{
create_item (
board_id: 1234,
group_id: "4321",
item_name: ""A" name", #<-- this is the problem
column_values: "{\\"key\\": \\"\\\\\\"A\\\\\\" value\\"}",
create_labels_if_missing: false
) {
id
}
}
I've worked around this for now by doing a value.replace('"', '\\"')
before passing it to the api, but it would be nice if this library took care of it automatically.
For updating I'm only using change_multiple_column_values
where the item name is in the dictionary, so no problems there, but there are probably other places where unescaped quotes are an issue.
Monday.com API has a rate limit that resets every minute [0].
If I want to perform an expensive operation, but already spent too many "complexity points", I need to wait for x seconds before retrying.
Currently, this library has no way to query how many seconds I need to wait, so the safest approach is to wait for 60 seconds before retrying.
We can reduce this time by querying the actual time in seconds that we need to wait:
In [12]: monday.boards.client._send('query { complexity { reset_in_x_seconds } }', None)
Out[12]: '{"data":{"complexity":{"reset_in_x_seconds":44}},"account_id":8442039}'
This saves many hours of waiting time when handling several thousands of resources.
In the example above, I called boards.client._send
in order to send this request.
Calling an internal method is not so neat. Also, boards
has nothing to do with complexity points.
So what I suggest is:
a) Add a new resource complexity
, so we can get the value by calling monday.complexity.get_rate_limit_reset_time()
and/or
b) Add a way to send arbitrary queries. This is already possible by calling monday.<resource>.client._send(query)
with whatever resource, but it would be nice to have an official way to do this, like monday.arbitrary_query(query)
.
[0] https://monday.com/developers/v2#queries-section-complexity
Hi,
I can't use the class from my workplace lab which requires proxy
is there a way to add it?
Correct me if I'm wrong, but it doesn't look like we can update a board item's name using this library. Seems like a useful facility and a common issue that should be included.
Hey :)
Is there a way to create a group with this module?
I couldn't find a way to do so.
When trying to create an item in a group whose id starts with a number, I get a Parse error
.
Steps to reproduce:
20210518 new group
)Expected results:
Actual results:
Parse error
occurs, and no item is created.Following is an example error message I get:
In [16]: monday.groups.create_group('1304228016', '20210518 new group')
Out[16]: {'data': {'create_group': {'id': '20210518_new_group'}}, 'account_id': 8442039}
In [17]: monday.items.create_item('1304228016', '20210518_new_group', 'foo')
Out[17]:
{'errors': [{'message': 'Parse error on "item_name" (IDENTIFIER) at [6, 13]',
'locations': [{'line': 6, 'column': 13}]}],
'account_id': 8442039}
From the Monday Web Site: "Querying items directly returns all items across the account. Starting October 3rd, 2022, you will not be able to return more than 100 items per query."
There is a way to page the fetch_items_by_board_id function?
Do you plan to update the package
Thanks
Fernando
Using the Monday v1.2.9 and running the following,
from monday import MondayClient
conn = MondayClient(MY_MONDAY_KEY)
users = conn.users.fetch_users()
the users variable is:
{'errors': [{'message': 'Query has complexity of 200140010, which exceeds max complexity of 5000000'}],
'account_id': 10368903}
This was working before the weekend. I have every expectation that mdc changed something. Thanks for your help.
Hi, thanks for writing this.
When I try and get all items on a board, I get a parse error. Any ideas?
from monday import MondayClient
import json
monday = MondayClient('secret')
data = monday.boards.fetch_boards()
ids = [b['id'] for b in data['data']['boards']]
for id in ids:
items = monday.boards.fetch_items_by_board_id([id])
print(items)
Yields this:
{'errors': [{'message': 'Parse error on "\'" (error) at [3, 22]', 'locations': [{'line': 3, 'column': 22}]}], 'account_id': 10353263}
{'errors': [{'message': 'Parse error on "\'" (error) at [3, 22]', 'locations': [{'line': 3, 'column': 22}]}], 'account_id': 10353263}
{'errors': [{'message': 'Parse error on "\'" (error) at [3, 22]', 'locations': [{'line': 3, 'column': 22}]}], 'account_id': 10353263}
{'errors': [{'message': 'Parse error on "\'" (error) at [3, 22]', 'locations': [{'line': 3, 'column': 22}]}], 'account_id': 10353263}
{'errors': [{'message': 'Parse error on "\'" (error) at [3, 22]', 'locations': [{'line': 3, 'column': 22}]}], 'account_id': 10353263}
{'errors': [{'message': 'Parse error on "\'" (error) at [3, 22]', 'locations': [{'line': 3, 'column': 22}]}], 'account_id': 10353263}
{'errors': [{'message': 'Parse error on "\'" (error) at [3, 22]', 'locations': [{'line': 3, 'column': 22}]}], 'account_id': 10353263}
{'errors': [{'message': 'Parse error on "\'" (error) at [3, 22]', 'locations': [{'line': 3, 'column': 22}]}], 'account_id': 10353263}
{'errors': [{'message': 'Parse error on "\'" (error) at [3, 22]', 'locations': [{'line': 3, 'column': 22}]}], 'account_id': 10353263}
{'errors': [{'message': 'Parse error on "\'" (error) at [3, 22]', 'locations': [{'line': 3, 'column': 22}]}], 'account_id': 10353263}
{'errors': [{'message': 'Parse error on "\'" (error) at [3, 22]', 'locations': [{'line': 3, 'column': 22}]}], 'account_id': 10353263}
{'errors': [{'message': 'Parse error on "\'" (error) at [3, 22]', 'locations': [{'line': 3, 'column': 22}]}], 'account_id': 10353263}
{'errors': [{'message': 'Parse error on "\'" (error) at [3, 22]', 'locations': [{'line': 3, 'column': 22}]}], 'account_id': 10353263}
{'errors': [{'message': 'Parse error on "\'" (error) at [3, 22]', 'locations': [{'line': 3, 'column': 22}]}], 'account_id': 10353263}
{'errors': [{'message': 'Parse error on "\'" (error) at [3, 22]', 'locations': [{'line': 3, 'column': 22}]}], 'account_id': 10353263}
{'errors': [{'message': 'Parse error on "\'" (error) at [3, 22]', 'locations': [{'line': 3, 'column': 22}]}], 'account_id': 10353263}
{'errors': [{'message': 'Parse error on "\'" (error) at [3, 22]', 'locations': [{'line': 3, 'column': 22}]}], 'account_id': 10353263}
We require to delete items throught item id
Monday.com looks to have updated their API for non-admins to restrict boards queries, hence whenever I tried to create a subitem, this is the error I get:
{'errors': [{'message': "Permission Denied! Your token doesn't grant access to boards:read"}], 'account_id': 1234567}
After looking through the library code, it seems like the function mutate_subitem_query() in Lib\site-packages\monday\query_joins.py
is returning the mutation with an additional boards:read query, which is why it is erroring out:
def mutate_subitem_query(parent_item_id, subitem_name, column_values, create_labels_if_missing): column_values = column_values if column_values else {} return '''mutation { create_subitem ( parent_item_id: %s, item_name: "%s", column_values: %s, create_labels_if_missing: %s ) { id, name, column_values { id, text }, board { id, name } } }''' % (parent_item_id, subitem_name, monday_json_stringify(column_values), str(create_labels_if_missing).lower())
After deleing the below from the mutation return above, I was able to create a subitem successfully.
board { id, name }
Just to save the next person from working this out, I wonder if you could beef up your README to include an example for reading and formatting a whole board?
def get_col_defs(conn, board_id):
data = conn.boards.fetch_boards_by_id([board_id])
columns = data['data']['boards'][0]['columns']
col_defs = {}
for column in columns:
col_defs[column['id']] = column
return col_defs
def get_formatted_value(col_defs, field_name, value):
""" Take a cell and make it human readable. """
def format_default(col_defs, field_name, value):
return value
def format_text_field(col_defs, field_name, value):
return json.loads(value)
def format_date_field(col_defs, field_name, value):
if value is None:
return ''
return json.loads(value)['date']
def format_numeric_field(col_defs, field_name, value):
if value is None:
return ''
return json.loads(value)
def format_longtext_field(col_defs, field_name, value):
if value is None:
return ''
value = json.loads(value)['text']
return value.strip() if value else ''
def format_color_field(col_defs, field_name, value):
if value is None:
return ''
labels = json.loads(col_defs[field_name]['settings_str'])['labels']
return labels.get(str(json.loads(value)['index']))
def format_dropdown_field(col_defs, field_name, value):
if value is None:
return ''
labels = json.loads(col_defs[field_name]['settings_str'])['labels']
label_map = dict([(row['id'], row['name']) for row in labels])
return ", ".join([label_map.get(id) for id in json.loads(value)['ids']])
type_to_callable_map = {
'color': format_color_field,
'dropdown': format_dropdown_field,
'long-text': format_longtext_field,
'date': format_date_field,
'numeric': format_numeric_field,
'text': format_text_field,
}
t = col_defs[field_name]['type']
formatter = type_to_callable_map.get(t, format_default)
return formatter(col_defs, field_name, value)
monday_api_key = 'xxx'
board_id = xxx
# Connect to Monday
conn = MondayClient(monday_api_key)
# Grab a map of column IDs and their settings
col_defs = monday.get_col_defs(conn, board_id)
# Grab all the rows (items) from a board
data = conn.boards.fetch_items_by_board_id([board_id])
# Loop through each cell and format it according to the cell settings
rows = []
for item in data['data']['boards'][0]['items']:
row = {}
for col in item['column_values']:
row.append(monday.get_formatted_value(col_defs, col['id'], col['value']))
rows.append(row)
# Use e.g. tablib to format for console.
ds = tablib.Dataset()
ds.dict = rows
print(ds.tsv)
When trying to add an item with a nonexistent dropdown label, the API raises a ColumnValueException
.
Same happens when creating an subitem.
Steps to reproduce:
Expected results:
Actual results:
ColumnValueException
is raised, and no item is created.Following is an example error message I get:
In [9]: monday.items.create_item('1272290775', 'new_group11612', 'foo', column_values={'dropdown': 'non-existing'})
Out[9]:
{'error_code': 'ColumnValueException',
'status_code': 200,
'error_message': "The dropdown label 'non-existing' does not exist, possible labels are: {1: ..., 15: Personal Development}",
'error_data': {'column_value': '{"labels"=>["non-existing"]}'}}
To avoid such exception, the board should be created with all the possible dropdown labels pre-created.
But sometimes it is hard to know in advance all the possible labels that the dropdown might receive.
API v2 create_item
and create_subitem
accept a boolean parameter create_labels_if_missing
[0], which instructs to create the label if absent.
This could be added as an optional parameter to the library methods, with current behavior False
as default.
If someone wants the label to be created upon item/subitem insertion, it can be done by specifying create_labels_if_missing=True
[0] https://monday.com/developers/v2#mutations-section-items-create
Based on this change: https://developer.monday.com/api-reference/docs/migrating-to-v-2023-10
I am no longer able to get subitems for items due to this deprecation:
Deprecated: text field returns empty values for mirror, dependency and connect boards columns when using the generic column_values object. You should retrieve this data by querying the display_value field through the relevant implementation (i.e., MirrorValue, DependencyValue, or BoardRelationValue.
Are there any plans to support this? Or any means of getting subitems at all using existing library that I'm missing?
Thank you in advance this module is a huge time-saver.
Creating and modifying items generally requires the 'group' field, but there doesn't seem to be a way to fetch those without manual calls to the API.
Can this be added to the responses for functions like fetch_items_by_id(board_id, [ids])
?
The users.fetch_users
method returns a string instead of a dictionary, and the caller needs to json.loads
the result.
Steps to reproduce:
users.fetch_users
Expected results:
Actual results:
For instance, when I try to fetch a user:
In [21]: monday.users.fetch_users(ids='20766495')
Out[21]: '{"data":{"users":[{"id":20766495,"name":"Lucio Seki","email":"[email protected]","enabled":true,"teams":[]}]},"account_id":8442039}'
I need to perform json.loads
before using it as a dictionary:
In [22]: json.loads(monday.users.fetch_users(ids='20766495'))
Out[22]:
{'data': {'users': [{'id': 20766495,
'name': 'Lucio Seki',
'email': '[email protected]',
'enabled': True,
'teams': []}]},
'account_id': 8442039}
The official documentation for mutation create_item says the parameter should be named "item_name" however in this implementation it is called "item". This creates confusion.
Hi, thank you for your effort maintaining this helpful package. However, I am wondering whether rate limits are being considered, and if not, how I can resolve my issues. Do you have experience with Monday rate limits?
Hi!
Thank you very much for this library! really saves me a lot of time. Are you planning to add the duplicating board feature from the API? That would be amazing 🔥
Keep up the good work
Hi , please check your code.
the monday.updates is not written in class MondayClient, i can't use it
"errorMessage": "Parse error on \"\" (STRING)",
Both create_item
and create_subitem
have the same issue. If the item/subitem name contains double quotes, it will fail when parsing the string.
Lines 14 to 27 in 2de9c46
Momentarily I have fixed it by replacing any "
on an item's name with single quotes '
but I can imagine confusing strings when the item makes use of single quotes on its name...
I try to upload .png file to Bubble by id item, how can I do it?
Can you tell me if this feature will be added in the future?
Hi,
I am experiencing a Parse error issue with methods such as monday.boards.fetch_boards() and monday.users.fetch_users(). Methods from workspaces are running normally though.
Here is the code:
from credentials import credentials
from monday import MondayClient
api_token = credentials['token']
monday = MondayClient(api_token)
print(monday.boards.fetch_boards())
print(monday.users.fetch_users())
Hi, thank you for this package, I'm finding it very useful! This is a feature request for supporting paging for retrieval of items. I have more data than can be retrieved in sixty seconds, and run into timeouts. To get around the issue, I have monkey patched the package:
monday = MondayClient(config.MONDAY_API_TOKEN)
def patch_query_arg(f, limit, page):
def result(query):
if 'items {' in query:
query = query.replace('items {', 'items(limit: %s , page : %s) {'%(limit, page))
print(query)
return f(query)
return result
def fetch_monday_items(board_id, limit = 1000):
orig_f = monday.boards.client.execute
result = []
page = 1
try:
while page:
monday.boards.client.execute = patch_query_arg(orig_f, limit = limit, page = page)
items = monday.boards.fetch_items_by_board_id(board_id)['data']['boards'][0]['items']
if items:
result.extend(items)
page+= 1
else:
page = 0
except Exception as e:
raise e
finally:
monday.boards.client.execute = orig_f
return result
If more people have this problem, the package could solve it by extending fetch_items_by_board_id to do the looping like I just did - with no monkey patching, and a much simpler logic.
I was attempting to use the code but when it runs it errors out at this line:
col_defs = monday.utils.get_col_defs(conn, board_id)
Traceback (most recent call last):
File "c:\Users\juan\Documents\Programming\monday3.py", line 75, in
col_defs = monday.utils.get_col_defs(conn, board_id)
AttributeError: module 'monday.utils' has no attribute 'get_col_defs'
another thing to point out is that 'row' in line 85 is defined as a dictionary and then there is an attempt to append to the dictionary in line 87 - but dictionary does not have a method of 'append', what is the intent here??
if you try to upload a file and the files column doesn't exist on the board, it looks like the upload Succeeded and the file appears on the board in the correct item disappears when you refresh the page
Our group names have '-' in them and this seems to cause a 'parse error' when I try to create an item with that group name. I have tried several different delimindators ('*, ^, _, [, ]) and they all seem to give different errors. I really do need '-' in my group names. It does create the groups just fine though, it's only an issue when I try to create items. What can I do?
monday_group = 'J2021-00016 - test999'
monday.items.create_item(board=job_board_id, group=monday_group.lower(), item_name='Do a thing')
{'errors': [{'message': 'Parse error on "-00016" (FLOAT) at [5, 28]', 'locations': [{'line': 5, 'column': 28}]}], 'account_id': xxxxxxx}
Error message
{'errors': [{'message': 'Parse error on ":" (COLON) at [6, 22]', 'locations': [{'line': 6, 'column': 22}]}], 'account_id': XXXXXXX}
Code
from monday import MondayClient
board_id = '1223372619'
group_id = '#dev_frontend'
comp.name = 'src/components/Chips'
r = monday.items.create_item(board_id, group_id, item_name=comp.name)
The API could gain these two functions in query_joins and monday.items:
def move_item_to_group_query(item_id, group_id):
query = '''mutation
{
move_item_to_group (item_id: %s, group_id: "%s") {
id
}
}
'''% (item_id, group_id)
return query
def change_item_group(self, item_id, group_id):
query = move_item_to_group_query(item_id, group_id)
return self.client.execute(query)
I added this extension locally, and call it as change_item_group(monday.items, job_id, group_id)
, but it would be nice if the package supported it!
Hello,
I have an issue with some commands, despite the commands being listed I get the error above. (create group is only one of the occurences)
Any ideas of the issue?
Many thanks
I was trying to use this library, but a function that I was attempting to use was unavailable
items_by_column_values
query ($boardId: Int!, $columnId: String!, $columnValue: String!){
items_by_column_values (board_id: $boardId, column_id: $columnId, column_value: $columnValue) {
id
name
}
}
Hello,
I was wondering if I can use change_item_value to upload and/or delete files from items in Monday (assuming that there's a files column in the board). If so, what arguments should be passed? any other changes required?
Thank you!
Hi,
is this project maintained anymore?
There should be a method create_subitem. But I do not see it implemented.
Hi,
I am wondering do you know how can I update the Monday Board subitem? Is is possible using Monday Client?
I have tried passing subitem_id as the item_id and to the board_id I have tried passing subitem_board_id (which is different) but it still raises 404 error. The method I have tried was explained here: https://community.monday.com/t/updating-subitems-via-api/16626
Best
Jakub
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.