From aa4546096b9b26a1bfd9341badb5f9f5836dad17 Mon Sep 17 00:00:00 2001 From: shalomcarmel Date: Mon, 17 Apr 2023 17:18:45 +0300 Subject: [PATCH 1/5] fix documentation bug --- docs/README.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/README.rst b/docs/README.rst index 2390b4d..f07969f 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -31,12 +31,13 @@ Getting started monday.items.create_item(board_id='12345678', group_id='today', item_name='Do a thing') -**Available methods:** #### Items Resource (monday.items) - -``create_item(board_id, group_id, item_name, column_values=None, create_labels_if_missing=False)`` -- Create an item on a board in the given group with name item_name. +**Available methods:** -- ``create_subitem(parent_item_id, subitem_name, column_values=None, create_labels_if_missing=False)`` - - Create a subitem underneath a given parent item. Monday API will +Items Resource (monday.items) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +- ``create_item(board_id, group_id, item_name, column_values=None, create_labels_if_missing=False)`` - Create an item on a board in the given group with name item_name. + +- ``create_subitem(parent_item_id, subitem_name, column_values=None, create_labels_if_missing=False)`` - Create a subitem underneath a given parent item. Monday API will return an error if the board you’re trying to add to does not have a subitems column/at least one subitem created. From ca8755c7b2be4d2910d66003b0136943bca865b8 Mon Sep 17 00:00:00 2001 From: shalomcarmel Date: Mon, 17 Apr 2023 17:24:47 +0300 Subject: [PATCH 2/5] boards: add create_column method to boards resource --- monday/query_joins.py | 19 +++++++++++++++++++ monday/resources/boards.py | 6 ++++++ monday/tests/test_case_resource.py | 3 +++ monday/tests/test_group_resource.py | 13 ++++++++++++- 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/monday/query_joins.py b/monday/query_joins.py index d075643..1396df0 100644 --- a/monday/query_joins.py +++ b/monday/query_joins.py @@ -9,6 +9,25 @@ # Eventually I will organize this file better but you know what today is not that day. # ITEM RESOURCE QUERIES +def create_column_in_board(board_id, title, description, column_type): + # List of acceptable types 2023-04-17: https://asset.cloudinary.com/monday-platform-dev/cde9c7ca84b78ec7dde46cc5c8588946 + query = '''mutation + { + create_column ( + board_id: %s, + title: "%s", + description: "%s", + column_type: %s + ) { + id + title + description + } + }''' % (board_id, title, description, column_type) + return query + + + def mutate_item_query(board_id, group_id, item_name, column_values, create_labels_if_missing): # Monday does not allow passing through non-JSON null values here, diff --git a/monday/resources/boards.py b/monday/resources/boards.py index ce506a6..6992bab 100644 --- a/monday/resources/boards.py +++ b/monday/resources/boards.py @@ -6,6 +6,7 @@ get_board_items_query, get_columns_by_board_query, create_board_by_workspace_query, + create_column_in_board, ) from monday.resources.types import BoardKind, BoardState, BoardsOrderBy @@ -33,3 +34,8 @@ def fetch_columns_by_board_id(self, board_ids): def create_board(self, board_name: str, board_kind: BoardKind, workspace_id: int = None): query = create_board_by_workspace_query(board_name, board_kind, workspace_id) return self.client.execute(query) + + def create_column(self, board_id, title, description, column_type='text'): + query = create_column_in_board(board_id, title, description, column_type) + return self.client.execute(query) + # TODO check all possible column types \ No newline at end of file diff --git a/monday/tests/test_case_resource.py b/monday/tests/test_case_resource.py index f6a4d5c..f51edca 100644 --- a/monday/tests/test_case_resource.py +++ b/monday/tests/test_case_resource.py @@ -28,4 +28,7 @@ def setUp(self): self.team_ids = [105939, 105940, 105941] self.notification_text = "This is an awesome notification." self.notification_target_type = "Project" + self.column_description = "some decription" + self.column_type = "text" + diff --git a/monday/tests/test_group_resource.py b/monday/tests/test_group_resource.py index bedaecb..e913e67 100644 --- a/monday/tests/test_group_resource.py +++ b/monday/tests/test_group_resource.py @@ -1,6 +1,6 @@ from monday.tests.test_case_resource import BaseTestCase from monday.query_joins import get_groups_by_board_query, get_items_by_group_query, create_group_query, \ - duplicate_group_query, archive_group_query, delete_group_query + duplicate_group_query, archive_group_query, delete_group_query, create_column_in_board class GroupTestCase(BaseTestCase): @@ -45,3 +45,14 @@ def test_archive_group_query(self): self.assertIn(str(self.board_id), query) self.assertIn(str(self.group_id), query) + def test_create_column_in_board(self): + query = create_column_in_board( + board_id=self.board_id, + title=self.column_id, + description=self.column_description, + column_type=self.column_type + ) + self.assertIn(str(self.board_id), query) + self.assertIn(str(self.column_id), query) + self.assertIn(str(self.column_description), query) + self.assertIn(str(self.column_type), query) \ No newline at end of file From 8b45938e9f737a13d37b51b9f23f55958c40808d Mon Sep 17 00:00:00 2001 From: shalomcarmel Date: Tue, 18 Apr 2023 16:03:18 +0300 Subject: [PATCH 3/5] prepare the way to work with graphql variables --- monday/graphqlclient/client.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/monday/graphqlclient/client.py b/monday/graphqlclient/client.py index 5836940..448adf9 100644 --- a/monday/graphqlclient/client.py +++ b/monday/graphqlclient/client.py @@ -31,6 +31,9 @@ def _send(self, query, variables): files = [ ('variables[file]', (variables['file'], open(variables['file'], 'rb'))) ] + else: + headers['Content-Type'] = 'application/json' + payload = json.dumps({'query': query, "variables": json.dumps(variables)}).encode('utf-8') try: response = requests.request("POST", self.endpoint, headers=headers, data=payload, files=files) From 2cc95744a594812a3e4240e41bb559c58f8e204d Mon Sep 17 00:00:00 2001 From: shalomcarmel Date: Tue, 18 Apr 2023 16:19:24 +0300 Subject: [PATCH 4/5] Update documentation with new method --- docs/README.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/README.rst b/docs/README.rst index f07969f..d6532b6 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -125,6 +125,11 @@ Boards Resource (monday.boards) - ``create_board(board_name, board_kind, workspace_id)`` - Create board with the given name and kind by (and optional) workspace id. +- ``create_column(board_id, column_title, column_description, column_type)`` - Create a new column + on a given board, with the given name, description, (and optional) column_type. + The column type defaults to text if not provided. + + Users Resource (monday.users) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From d10b408289cb667698f07042cc3e84c0088f9b65 Mon Sep 17 00:00:00 2001 From: shalomcarmel Date: Sat, 22 Apr 2023 23:38:14 +0300 Subject: [PATCH 5/5] retrieve item title --- monday/query_joins.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/monday/query_joins.py b/monday/query_joins.py index 1396df0..773a347 100644 --- a/monday/query_joins.py +++ b/monday/query_joins.py @@ -327,7 +327,8 @@ def get_board_items_query(board_id: Union[str, int], limit: Optional[int] = None name column_values { id - text + title + text type value }