Giter VIP home page Giter VIP logo

monday's People

Contributors

albcl avatar allcontributors[bot] avatar andrewrgoss avatar chdastolfo avatar dependabot[bot] avatar lucioseki avatar pevner-p2 avatar rhymiz avatar shaurya-blip avatar spencefull avatar tonymorello avatar wbazant avatar willnaoosmith avatar yogeshnile avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

monday's Issues

Breaking Changes for Monday API

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.

Missing a create board method

Issue

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
    }
}

Solution

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

Others

  • Tests included.
  • Readme updated.

Example in ReadMe doesn't seem to work?

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

Problem with dates change

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 :

  • a Dictionnary like : {'column_id': { 'from' : 'start_date' , 'to' : 'end_date'} }
  • Another dictionnary : { 'column_id' : 'start_date - end_date'}
    Hope you can help me.
    I'm waiting for your answer.

Double quote (") in item name will fail to create the item

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.

No means to query for complexity reset_in_x_seconds

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

Proxy handling

Hi,

I can't use the class from my workplace lab which requires proxy
is there a way to add it?

Ability to Update Item Name

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.

Creating a Group

Hey :)
Is there a way to create a group with this module?
I couldn't find a way to do so.

Parse error trying to create an item in a group that starts with a number

When trying to create an item in a group whose id starts with a number, I get a Parse error.

Steps to reproduce:

  1. Create a group with the name starting with a number (e.g. 20210518 new group)
  2. Try to create an item within this group

Expected results:

  • Have the item created successfully

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}

Fetch items with page limit

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

fetch_users() query complexity exceeds max complexity

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.

fetch_items_by_board_id: Parse error on "\'"

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}

Creation of Subitems not working for workspace non-admins as of Aug 22, 2023

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 }

Provide a formatting example

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)

ColumnValueException when creating an item with a nonexistent dropdown label

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:

  1. Create a dropdown column
  2. Try to create an item specifying a nonexistent label for the dropdown

Expected results:

  • To have the label automatically created if it doesn't yet exist.

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

No way to get Subitems for a Parent Item

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.

Can you add a 'group' field to items that are returned?

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]) ?

fetch_users returns a string instead of a dictionary

The users.fetch_users method returns a string instead of a dictionary, and the caller needs to json.loads the result.

Steps to reproduce:

  1. Fetch users using users.fetch_users

Expected results:

  • Get a dictionary containing a list of users

Actual results:

  • It returns a string that still needs to be parsed

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}

create_item needs an argument named item

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.

Duplicating boards

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

Parse error on item_name

"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.

query = '''mutation
{
create_item (
board_id: %s,
group_id: "%s",
item_name: "%s",
column_values: %s,
create_labels_if_missing: %s
) {
id
}
}''' % (board_id, group_id, item_name, monday_json_stringify(column_values),
str(create_labels_if_missing).lower())

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...

{'message': 'Parse error on ")" (RPAREN) at [3, 17]'

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())

Retrieve items with page and limit

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.

Error in python script

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??

bug in add_file_to_column

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

Parse Error on 'monday.items.create_item()

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}

Parse error when trying to create_item

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)

Feature request: assign group to an item

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!

Missing items_by_column_values method

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
    }
}

Uploading/deleting files

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.