diff --git a/docs/README.rst b/docs/README.rst index 2390b4d..d6532b6 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. @@ -124,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) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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) diff --git a/monday/query_joins.py b/monday/query_joins.py index d075643..773a347 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, @@ -308,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 } 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