From 27275fe3fe71428487431645f8ee3ce0cfa2956d Mon Sep 17 00:00:00 2001 From: Andrey Oleynik Date: Mon, 22 Apr 2024 11:37:51 +0300 Subject: [PATCH 1/2] fix missing error msg (#1378) --- atlassian/rest_client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/atlassian/rest_client.py b/atlassian/rest_client.py index e92baa7f7..bfe1096a7 100644 --- a/atlassian/rest_client.py +++ b/atlassian/rest_client.py @@ -537,7 +537,9 @@ def raise_for_status(self, response): else: error_msg_list = j.get("errorMessages", list()) errors = j.get("errors", dict()) - if isinstance(errors, dict): + if isinstance(errors, dict) and "message" not in errors: + error_msg_list.extend(errors.values()) + elif isinstance(errors, dict) and "message" in errors: error_msg_list.append(errors.get("message", "")) elif isinstance(errors, list): error_msg_list.extend([v.get("message", "") if isinstance(v, dict) else v for v in errors]) From 85458f17a448d8cb35d1c985de795fa02d08999a Mon Sep 17 00:00:00 2001 From: gkowalc Date: Mon, 22 Apr 2024 10:38:20 +0200 Subject: [PATCH 2/2] [Confluence] added new endpoints for confluence whiteboards + docs + example (#1377) * fixing minor issue in scrap_regex_from_issue method * new Confluence method scrap_regex_from_page+ docs + examples * added method get_attachments_ids_from_page to jira.py * added method download_attachments_from_issue * refactoring download_all_attachments_from_page method * finished download_attachments_from_issue * added two new methods: download_attachments.from_issue and get_attachments_ids_from_issue * added fix to the infinitive loop * adding reursion depth condition * fixed reursion depth condition * added update4d jira.py with new method + docs +example * added update4d jira.py with new method + docs +exampl * fix flake8 issue * hotfix get_issue_tree_recursive * added expand to get_issue method, added new method * get_issue_status_changelog method * included param expand in get_issue method decription * WIP PR changes - https://github.com/atlassian-api/atlassian-python-api/pull/1357 * improving index.rst docs https://github.com/atlassian-api/atlassian-python-api/issues/1365 * added whiteboard methods * added confluence whiteboard endpoints --------- Co-authored-by: gkowalc <> Co-authored-by: Greg --- atlassian/confluence.py | 41 ++++++++++++++++++++ docs/confluence.rst | 15 +++++++ examples/confluence/confluence_whiteboard.py | 20 ++++++++++ 3 files changed, 76 insertions(+) create mode 100644 examples/confluence/confluence_whiteboard.py diff --git a/atlassian/confluence.py b/atlassian/confluence.py index f8d102f4b..f195ae2fd 100644 --- a/atlassian/confluence.py +++ b/atlassian/confluence.py @@ -2877,6 +2877,47 @@ def audit( params["searchString"] = search_string return self.get(url, params=params) + """ + ############################################################################################## + # Confluence whiteboards (cloud only!) # + ############################################################################################## + """ + + def create_whiteboard(self, spaceId, title=None, parentId=None): + url = "/api/v2/whiteboards" + data = {"spaceId": spaceId} + if title is not None: + data["title"] = title + if parentId is not None: + data["parentId"] = parentId + return self.post(url, data=data) + + def get_whiteboard(self, whiteboard_id): + try: + url = f"/api/v2/whiteboards/{whiteboard_id}" + return self.get(url) + except HTTPError as e: + # Default 404 error handling is ambiguous + if e.response.status_code == 404: + raise ApiValueError( + "Whiteboard not found. Check confluence instance url and/or if whiteboard id exists", reason=e + ) + + raise + + def delete_whiteboard(self, whiteboard_id): + try: + url = f"/api/v2/whiteboards/{whiteboard_id}" + return self.delete(url) + except HTTPError as e: + # # Default 404 error handling is ambiguous + if e.response.status_code == 404: + raise ApiValueError( + "Whiteboard not found. Check confluence instance url and/or if whiteboard id exists", reason=e + ) + + raise + """ ############################################################################################## # Team Calendars REST API implements (https://jira.atlassian.com/browse/CONFSERVER-51003) # diff --git a/docs/confluence.rst b/docs/confluence.rst index 4858a8f6e..3d375e5b7 100644 --- a/docs/confluence.rst +++ b/docs/confluence.rst @@ -161,6 +161,21 @@ Page actions # Get regex matches from Confluence page confluence.scrap_regex_from_page(page_id, regex) +Confluence Whiteboards +---------------------- + +.. code-block:: python + + # Create new whiteboard - cloud only + confluence.create_whiteboard(spaceId, title=None, parentId=None) + + # Delete existing whiteboard - cloud only + confluence.delete_whiteboard(whiteboard_id) + + # Get whiteboard by id - cloud only! + confluence.get_whiteboard(whiteboard_id) + + Template actions ---------------- diff --git a/examples/confluence/confluence_whiteboard.py b/examples/confluence/confluence_whiteboard.py new file mode 100644 index 000000000..71695a707 --- /dev/null +++ b/examples/confluence/confluence_whiteboard.py @@ -0,0 +1,20 @@ +from atlassian import Confluence + +confluence = Confluence( + url="", + username="", + password="api_key", +) +""" +This is example on how to use confluence whiteboard endponds +Currently only available on confluence cloud +""" +# create whiteboard. First parameter is a spaceID (not spacekey!), +# second param is a name of whiteboard (optional), third one is a parent pageid (optional) +confluence.create_whiteboard("42342", "My whiteboard", "545463") + +# To delete of get whiteboard, use whiteboard id +# https:///wiki/spaces//whiteboard/ +# Deleting a whiteboard moves the whiteboard to the trash, where it can be restored later +confluence.delete_whiteboard("42342") +confluence.get_whiteboard("42342")