Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gonchik committed Apr 23, 2024
2 parents 00c18e0 + 85458f1 commit 3f33de8
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
41 changes: 41 additions & 0 deletions atlassian/confluence.py
Expand Up @@ -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) #
Expand Down
4 changes: 3 additions & 1 deletion atlassian/rest_client.py
Expand Up @@ -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])
Expand Down
15 changes: 15 additions & 0 deletions docs/confluence.rst
Expand Up @@ -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
----------------

Expand Down
20 changes: 20 additions & 0 deletions examples/confluence/confluence_whiteboard.py
@@ -0,0 +1,20 @@
from atlassian import Confluence

confluence = Confluence(
url="<instance_url>",
username="<atlassian_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://<instance_name>/wiki/spaces/<space_key>/whiteboard/<whiteboard_id>
# Deleting a whiteboard moves the whiteboard to the trash, where it can be restored later
confluence.delete_whiteboard("42342")
confluence.get_whiteboard("42342")

0 comments on commit 3f33de8

Please sign in to comment.