atlassian-python-api 5.0.0__py3-none-any.whl → 5.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,12 +11,15 @@ import re
11
11
  import warnings
12
12
  from typing import Any, Dict, List, Optional
13
13
 
14
- from ...confluence_base import ConfluenceBase
14
+ from .databases import DatabaseOperations
15
+ from .folders import FolderOperations
16
+ from .tasks import TaskOperations
17
+ from .whiteboards import WhiteboardOperations
15
18
 
16
19
  log = logging.getLogger(__name__)
17
20
 
18
21
 
19
- class ConfluenceCloud(ConfluenceBase):
22
+ class ConfluenceCloud(WhiteboardOperations, TaskOperations, FolderOperations, DatabaseOperations):
20
23
  """
21
24
  Confluence Cloud API implementation class
22
25
  """
@@ -237,6 +240,34 @@ class ConfluenceCloud(ConfluenceBase):
237
240
  log.error(f"Failed to retrieve pages: {e}")
238
241
  raise
239
242
 
243
+ def get_page_versions(
244
+ self,
245
+ page_id: str,
246
+ body_format: Optional[str] = None,
247
+ limit: int = 25,
248
+ sort: Optional[str] = None,
249
+ cursor: Optional[str] = None,
250
+ ) -> Dict[str, Any]:
251
+ """Return the version history for a Confluence Cloud page.
252
+
253
+ This uses the Cloud V2 version endpoint. Cloud V2 exposes version
254
+ retrieval only; deletion remains unavailable in that API.
255
+ """
256
+ if body_format is not None and body_format not in ("storage", "atlas_doc_format", "view"):
257
+ raise ValueError("body_format must be 'storage', 'atlas_doc_format', or 'view'")
258
+ params: Dict[str, Any] = {"limit": limit}
259
+ if body_format is not None:
260
+ params["body-format"] = body_format
261
+ if sort is not None:
262
+ params["sort"] = sort
263
+ if cursor is not None:
264
+ params["cursor"] = cursor
265
+ return self.get(self.get_endpoint("page_versions", id=page_id), params=params)
266
+
267
+ def get_page_version(self, page_id: str, version_number: int) -> Dict[str, Any]:
268
+ """Return details for one Confluence Cloud page version."""
269
+ return self.get(self.get_endpoint("page_version", id=page_id, version_number=version_number), params={})
270
+
240
271
  def get_child_pages(
241
272
  self,
242
273
  parent_id: str,
@@ -676,6 +707,10 @@ class ConfluenceCloud(ConfluenceBase):
676
707
  log.error(f"Failed to retrieve spaces: {e}")
677
708
  raise
678
709
 
710
+ def get_space_names(self, **kwargs) -> List[str]:
711
+ """Return every visible space name without retrieving page content."""
712
+ return [space["name"] for space in self.get_spaces(**kwargs) if space.get("name")]
713
+
679
714
  def get_space(self, space_id: str) -> Dict[str, Any]:
680
715
  """
681
716
  Returns a specific space by ID.
@@ -1855,186 +1890,6 @@ class ConfluenceCloud(ConfluenceBase):
1855
1890
  log.error(f"Failed to delete comment {comment_id}: {e}")
1856
1891
  raise
1857
1892
 
1858
- # V2-specific methods will be implemented here in Phase 2 and Phase 3
1859
-
1860
- """
1861
- ##############################################################################################
1862
- # Confluence Whiteboards API v2 #
1863
- ##############################################################################################
1864
- """
1865
-
1866
- def create_whiteboard(
1867
- self,
1868
- space_id: str,
1869
- title: Optional[str] = None,
1870
- parent_id: Optional[str] = None,
1871
- template_key: Optional[str] = None,
1872
- locale: Optional[str] = None,
1873
- ) -> Dict[str, Any]:
1874
- """
1875
- Creates a new whiteboard in the specified space.
1876
-
1877
- Args:
1878
- space_id: ID of the space where the whiteboard will be created
1879
- title: (optional) Title of the new whiteboard
1880
- parent_id: (optional) ID of the parent content
1881
- template_key: (optional) Key of the template to use for the whiteboard
1882
- locale: (optional) Locale for the template if template_key is provided
1883
-
1884
- Returns:
1885
- Created whiteboard data
1886
-
1887
- Raises:
1888
- HTTPError: If the API call fails
1889
- """
1890
- endpoint = self.get_endpoint("whiteboard")
1891
-
1892
- data = {"spaceId": space_id}
1893
-
1894
- if title is not None:
1895
- data["title"] = title
1896
-
1897
- if parent_id is not None:
1898
- data["parentId"] = parent_id
1899
-
1900
- if template_key is not None:
1901
- data["templateKey"] = template_key
1902
-
1903
- if locale is not None:
1904
- data["locale"] = locale
1905
-
1906
- try:
1907
- return self.post(endpoint, data=data)
1908
- except Exception as e:
1909
- log.error(f"Failed to create whiteboard in space {space_id}: {e}")
1910
- raise
1911
-
1912
- def get_whiteboard_by_id(self, whiteboard_id: str) -> Dict[str, Any]:
1913
- """
1914
- Get a whiteboard by its ID.
1915
-
1916
- Args:
1917
- whiteboard_id: ID of the whiteboard to retrieve
1918
-
1919
- Returns:
1920
- Whiteboard data
1921
-
1922
- Raises:
1923
- HTTPError: If the API call fails
1924
- """
1925
- endpoint = self.get_endpoint("whiteboard_by_id", id=whiteboard_id)
1926
-
1927
- try:
1928
- return self.get(endpoint)
1929
- except Exception as e:
1930
- log.error(f"Failed to get whiteboard {whiteboard_id}: {e}")
1931
- raise
1932
-
1933
- def delete_whiteboard(self, whiteboard_id: str) -> Dict[str, Any]:
1934
- """
1935
- Delete a whiteboard by its ID.
1936
- This moves the whiteboard to the trash, where it can be restored later.
1937
-
1938
- Args:
1939
- whiteboard_id: ID of the whiteboard to delete
1940
-
1941
- Returns:
1942
- Response data from the API
1943
-
1944
- Raises:
1945
- HTTPError: If the API call fails
1946
- """
1947
- endpoint = self.get_endpoint("whiteboard_by_id", id=whiteboard_id)
1948
-
1949
- try:
1950
- return self.delete(endpoint)
1951
- except Exception as e:
1952
- log.error(f"Failed to delete whiteboard {whiteboard_id}: {e}")
1953
- raise
1954
-
1955
- def get_whiteboard_children(
1956
- self, whiteboard_id: str, cursor: Optional[str] = None, limit: Optional[int] = None
1957
- ) -> List[Dict[str, Any]]:
1958
- """
1959
- Get the children of a whiteboard.
1960
-
1961
- Args:
1962
- whiteboard_id: ID of the whiteboard
1963
- cursor: (optional) Cursor for pagination
1964
- limit: (optional) Maximum number of results to return
1965
-
1966
- Returns:
1967
- List of whiteboard children
1968
-
1969
- Raises:
1970
- HTTPError: If the API call fails
1971
- """
1972
- endpoint = self.get_endpoint("whiteboard_children", id=whiteboard_id)
1973
-
1974
- params = {}
1975
- if cursor:
1976
- params["cursor"] = cursor
1977
- if limit:
1978
- params["limit"] = limit
1979
-
1980
- try:
1981
- return list(self._get_paged(endpoint, params=params))
1982
- except Exception as e:
1983
- log.error(f"Failed to get children for whiteboard {whiteboard_id}: {e}")
1984
- raise
1985
-
1986
- def get_whiteboard_ancestors(self, whiteboard_id: str) -> List[Dict[str, Any]]:
1987
- """
1988
- Get the ancestors of a whiteboard.
1989
-
1990
- Args:
1991
- whiteboard_id: ID of the whiteboard
1992
-
1993
- Returns:
1994
- List of ancestor content
1995
-
1996
- Raises:
1997
- HTTPError: If the API call fails
1998
- """
1999
- endpoint = self.get_endpoint("whiteboard_ancestors", id=whiteboard_id)
2000
-
2001
- try:
2002
- response = self.get(endpoint)
2003
- return response.get("results", [])
2004
- except Exception as e:
2005
- log.error(f"Failed to get ancestors for whiteboard {whiteboard_id}: {e}")
2006
- raise
2007
-
2008
- def get_space_whiteboards(
2009
- self, space_id: str, cursor: Optional[str] = None, limit: int = 25
2010
- ) -> List[Dict[str, Any]]:
2011
- """
2012
- Get all whiteboards in a space.
2013
-
2014
- Args:
2015
- space_id: ID or key of the space
2016
- cursor: (optional) Cursor for pagination
2017
- limit: (optional) Maximum number of results to return (default: 25)
2018
-
2019
- Returns:
2020
- List of whiteboards in the space
2021
-
2022
- Raises:
2023
- HTTPError: If the API call fails
2024
- """
2025
- endpoint = self.get_endpoint("whiteboard")
2026
-
2027
- params = {"spaceId": space_id, "limit": limit}
2028
-
2029
- if cursor:
2030
- params["cursor"] = cursor
2031
-
2032
- try:
2033
- return list(self._get_paged(endpoint, params=params))
2034
- except Exception as e:
2035
- log.error(f"Failed to get whiteboards for space {space_id}: {e}")
2036
- raise
2037
-
2038
1893
  """
2039
1894
  ##############################################################################################
2040
1895
  # Confluence Custom Content API (Cloud only) #
@@ -0,0 +1,59 @@
1
+ """Confluence Cloud V2 database lifecycle operations.
2
+
3
+ The public API currently exposes database metadata only. Record, field, view,
4
+ and query operations are intentionally not provided because Atlassian does not
5
+ publish endpoints for them.
6
+ """
7
+
8
+ from typing import Any, Dict, Optional
9
+
10
+ from ...confluence_base import ConfluenceBase
11
+
12
+
13
+ class DatabaseOperations(ConfluenceBase):
14
+ """Base component implementing the supported Cloud database endpoints."""
15
+
16
+ def create_database(
17
+ self,
18
+ space_id: str,
19
+ title: str,
20
+ parent_id: Optional[str] = None,
21
+ private: Optional[bool] = None,
22
+ ) -> Optional[Dict[str, Any]]:
23
+ """Create a database in a Confluence Cloud space.
24
+
25
+ Requires the ``write:database:confluence`` scope for scoped tokens.
26
+ """
27
+ data: Dict[str, str] = {"spaceId": space_id, "title": title}
28
+ if parent_id is not None:
29
+ data["parentId"] = parent_id
30
+ params = {"private": private} if private is not None else None
31
+ return self.post(self.get_endpoint("database"), data=data, params=params)
32
+
33
+ def get_database(
34
+ self,
35
+ database_id: str,
36
+ include_collaborators: Optional[bool] = None,
37
+ include_direct_children: Optional[bool] = None,
38
+ include_operations: Optional[bool] = None,
39
+ include_properties: Optional[bool] = None,
40
+ ) -> Optional[Dict[str, Any]]:
41
+ """Return database metadata by ID.
42
+
43
+ Requires the ``read:database:confluence`` scope for scoped tokens.
44
+ """
45
+ optional_params = {
46
+ "include-collaborators": include_collaborators,
47
+ "include-direct-children": include_direct_children,
48
+ "include-operations": include_operations,
49
+ "include-properties": include_properties,
50
+ }
51
+ params = {key: value for key, value in optional_params.items() if value is not None}
52
+ return self.get(self.get_endpoint("database_by_id", id=database_id), params=params)
53
+
54
+ def delete_database(self, database_id: str) -> Optional[Dict[str, Any]]:
55
+ """Move a database to the Confluence Cloud trash.
56
+
57
+ Requires the ``delete:database:confluence`` scope for scoped tokens.
58
+ """
59
+ return self.delete(self.get_endpoint("database_by_id", id=database_id))
@@ -0,0 +1,48 @@
1
+ """Confluence Cloud V2 folder operations."""
2
+
3
+ from typing import Any, Dict, Optional
4
+
5
+ from ...confluence_base import ConfluenceBase
6
+
7
+
8
+ class FolderOperations(ConfluenceBase):
9
+ """Base component implementing the supported Cloud folder endpoints."""
10
+
11
+ def create_folder(self, space_id: str, title: str, parent_id: Optional[str] = None) -> Optional[Dict[str, Any]]:
12
+ """Create a folder in a Confluence Cloud space.
13
+
14
+ ``parent_id`` can identify a page or folder. Scoped tokens require the
15
+ ``write:folder:confluence`` scope.
16
+ """
17
+ data: Dict[str, str] = {"spaceId": space_id, "title": title}
18
+ if parent_id is not None:
19
+ data["parentId"] = parent_id
20
+ return self.post(self.get_endpoint("folder"), data=data)
21
+
22
+ def get_folder(
23
+ self,
24
+ folder_id: str,
25
+ include_collaborators: Optional[bool] = None,
26
+ include_direct_children: Optional[bool] = None,
27
+ include_operations: Optional[bool] = None,
28
+ include_properties: Optional[bool] = None,
29
+ ) -> Optional[Dict[str, Any]]:
30
+ """Return a Confluence Cloud folder by ID.
31
+
32
+ Scoped tokens require the ``read:folder:confluence`` scope.
33
+ """
34
+ optional_params = {
35
+ "include-collaborators": include_collaborators,
36
+ "include-direct-children": include_direct_children,
37
+ "include-operations": include_operations,
38
+ "include-properties": include_properties,
39
+ }
40
+ params = {key: value for key, value in optional_params.items() if value is not None}
41
+ return self.get(self.get_endpoint("folder_by_id", id=folder_id), params=params)
42
+
43
+ def delete_folder(self, folder_id: str) -> Optional[Dict[str, Any]]:
44
+ """Move a Confluence Cloud folder to the trash.
45
+
46
+ Scoped tokens require the ``delete:folder:confluence`` scope.
47
+ """
48
+ return self.delete(self.get_endpoint("folder_by_id", id=folder_id))
@@ -0,0 +1,86 @@
1
+ """Confluence Cloud V2 task operations."""
2
+
3
+ from typing import Any, Dict, List, Optional, Sequence
4
+
5
+ from ...confluence_base import ConfluenceBase
6
+
7
+
8
+ class TaskOperations(ConfluenceBase):
9
+ """Operations for Confluence Cloud inline tasks."""
10
+
11
+ def get_tasks(
12
+ self,
13
+ body_format: Optional[str] = None,
14
+ include_blank_tasks: Optional[bool] = None,
15
+ status: Optional[str] = None,
16
+ task_ids: Optional[Sequence[int]] = None,
17
+ space_ids: Optional[Sequence[int]] = None,
18
+ page_ids: Optional[Sequence[int]] = None,
19
+ blogpost_ids: Optional[Sequence[int]] = None,
20
+ created_by: Optional[Sequence[str]] = None,
21
+ assigned_to: Optional[Sequence[str]] = None,
22
+ completed_by: Optional[Sequence[str]] = None,
23
+ created_at_from: Optional[int] = None,
24
+ created_at_to: Optional[int] = None,
25
+ due_at_from: Optional[int] = None,
26
+ due_at_to: Optional[int] = None,
27
+ completed_at_from: Optional[int] = None,
28
+ completed_at_to: Optional[int] = None,
29
+ cursor: Optional[str] = None,
30
+ limit: int = 25,
31
+ ) -> List[Dict[str, Any]]:
32
+ """Return all visible Confluence Cloud tasks matching the supplied filters.
33
+
34
+ Date filters are Unix epoch milliseconds. The endpoint is cursor
35
+ paginated; this method follows every result page, while ``limit``
36
+ controls the number requested per page (1--250).
37
+ """
38
+ if body_format is not None and body_format not in ("storage", "atlas_doc_format", "view"):
39
+ raise ValueError("body_format must be 'storage', 'atlas_doc_format', or 'view'")
40
+ if status is not None and status not in ("complete", "incomplete"):
41
+ raise ValueError("status must be 'complete' or 'incomplete'")
42
+ if not 1 <= limit <= 250:
43
+ raise ValueError("limit must be between 1 and 250")
44
+
45
+ filters = {
46
+ "body-format": body_format,
47
+ "include-blank-tasks": include_blank_tasks,
48
+ "status": status,
49
+ "task-id": task_ids,
50
+ "space-id": space_ids,
51
+ "page-id": page_ids,
52
+ "blogpost-id": blogpost_ids,
53
+ "created-by": created_by,
54
+ "assigned-to": assigned_to,
55
+ "completed-by": completed_by,
56
+ "created-at-from": created_at_from,
57
+ "created-at-to": created_at_to,
58
+ "due-at-from": due_at_from,
59
+ "due-at-to": due_at_to,
60
+ "completed-at-from": completed_at_from,
61
+ "completed-at-to": completed_at_to,
62
+ "cursor": cursor,
63
+ }
64
+ params = {key: value for key, value in filters.items() if value is not None}
65
+ params["limit"] = limit
66
+ return list(self._get_paged(self.get_endpoint("tasks"), params=params))
67
+
68
+ def get_task(self, task_id: int, body_format: Optional[str] = None) -> Optional[Dict[str, Any]]:
69
+ """Return a task by ID. Scoped tokens require ``read:task:confluence``."""
70
+ if body_format is not None and body_format not in ("storage", "atlas_doc_format", "view"):
71
+ raise ValueError("body_format must be 'storage', 'atlas_doc_format', or 'view'")
72
+ params = {"body-format": body_format} if body_format is not None else None
73
+ return self.get(self.get_endpoint("task_by_id", id=task_id), params=params)
74
+
75
+ def update_task(self, task_id: int, status: str, body_format: Optional[str] = None) -> Optional[Dict[str, Any]]:
76
+ """Update a task's status to ``complete`` or ``incomplete``.
77
+
78
+ Confluence currently supports updating only the status. Scoped tokens
79
+ require ``write:task:confluence``.
80
+ """
81
+ if status not in ("complete", "incomplete"):
82
+ raise ValueError("status must be 'complete' or 'incomplete'")
83
+ if body_format is not None and body_format not in ("storage", "atlas_doc_format", "view"):
84
+ raise ValueError("body_format must be 'storage', 'atlas_doc_format', or 'view'")
85
+ params = {"body-format": body_format} if body_format is not None else None
86
+ return self.put(self.get_endpoint("task_by_id", id=task_id), data={"status": status}, params=params)
@@ -0,0 +1,95 @@
1
+ """Confluence Cloud V2 whiteboard operations."""
2
+
3
+ from typing import Any, Dict, List, Optional
4
+
5
+ from ...confluence_base import ConfluenceBase
6
+
7
+
8
+ class WhiteboardOperations(ConfluenceBase):
9
+ """Base component implementing Confluence Cloud whiteboard endpoints."""
10
+
11
+ def create_whiteboard(
12
+ self,
13
+ space_id: str,
14
+ title: Optional[str] = None,
15
+ parent_id: Optional[str] = None,
16
+ template_key: Optional[str] = None,
17
+ locale: Optional[str] = None,
18
+ private: Optional[bool] = None,
19
+ ) -> Optional[Dict[str, Any]]:
20
+ """Create a whiteboard in a Confluence Cloud space.
21
+
22
+ Scoped tokens require ``write:whiteboard:confluence``. ``private`` is
23
+ sent as the API query parameter; the remaining optional values are
24
+ fields in the request body.
25
+ """
26
+ data: Dict[str, str] = {"spaceId": space_id}
27
+ if title is not None:
28
+ data["title"] = title
29
+ if parent_id is not None:
30
+ data["parentId"] = parent_id
31
+ if template_key is not None:
32
+ data["templateKey"] = template_key
33
+ if locale is not None:
34
+ data["locale"] = locale
35
+ if private is None:
36
+ return self.post(self.get_endpoint("whiteboard"), data=data)
37
+ return self.post(self.get_endpoint("whiteboard"), data=data, params={"private": private})
38
+
39
+ def get_whiteboard(
40
+ self,
41
+ whiteboard_id: str,
42
+ include_collaborators: Optional[bool] = None,
43
+ include_direct_children: Optional[bool] = None,
44
+ include_operations: Optional[bool] = None,
45
+ include_properties: Optional[bool] = None,
46
+ ) -> Optional[Dict[str, Any]]:
47
+ """Return a whiteboard by ID.
48
+
49
+ Scoped tokens require ``read:whiteboard:confluence``.
50
+ """
51
+ optional_params = {
52
+ "include-collaborators": include_collaborators,
53
+ "include-direct-children": include_direct_children,
54
+ "include-operations": include_operations,
55
+ "include-properties": include_properties,
56
+ }
57
+ params = {key: value for key, value in optional_params.items() if value is not None}
58
+ endpoint = self.get_endpoint("whiteboard_by_id", id=whiteboard_id)
59
+ if not params:
60
+ return self.get(endpoint)
61
+ return self.get(endpoint, params=params)
62
+
63
+ def get_whiteboard_by_id(self, whiteboard_id: str, **kwargs) -> Optional[Dict[str, Any]]:
64
+ """Backward-compatible alias for :meth:`get_whiteboard`."""
65
+ return self.get_whiteboard(whiteboard_id, **kwargs)
66
+
67
+ def delete_whiteboard(self, whiteboard_id: str) -> Optional[Dict[str, Any]]:
68
+ """Move a whiteboard to the Confluence Cloud trash.
69
+
70
+ Scoped tokens require ``delete:whiteboard:confluence``.
71
+ """
72
+ return self.delete(self.get_endpoint("whiteboard_by_id", id=whiteboard_id))
73
+
74
+ def get_whiteboard_children(
75
+ self, whiteboard_id: str, cursor: Optional[str] = None, limit: Optional[int] = None
76
+ ) -> List[Dict[str, Any]]:
77
+ """Return every child of a whiteboard, following pagination."""
78
+ params = {key: value for key, value in {"cursor": cursor, "limit": limit}.items() if value is not None}
79
+ return list(self._get_paged(self.get_endpoint("whiteboard_children", id=whiteboard_id), params=params))
80
+
81
+ def get_whiteboard_ancestors(self, whiteboard_id: str) -> List[Dict[str, Any]]:
82
+ """Return the ancestors of a whiteboard."""
83
+ response = self.get(self.get_endpoint("whiteboard_ancestors", id=whiteboard_id))
84
+ if response is None:
85
+ return []
86
+ return response.get("results", [])
87
+
88
+ def get_space_whiteboards(
89
+ self, space_id: str, cursor: Optional[str] = None, limit: int = 25
90
+ ) -> List[Dict[str, Any]]:
91
+ """Return every whiteboard in a space, following pagination."""
92
+ params: Dict[str, Any] = {"spaceId": space_id, "limit": limit}
93
+ if cursor is not None:
94
+ params["cursor"] = cursor
95
+ return list(self._get_paged(self.get_endpoint("whiteboard"), params=params))