atlassian-python-api 4.0.7__py3-none-any.whl → 5.0.0__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.
- atlassian/VERSION +1 -1
- atlassian/__init__.py +18 -1
- atlassian/assets.py +1 -1
- atlassian/bamboo.py +4 -4
- atlassian/bitbucket/__init__.py +3 -3
- atlassian/bitbucket/cloud/repositories/pipelines.py +1 -1
- atlassian/bitbucket/cloud/workspaces/__init__.py +2 -2
- atlassian/bitbucket/cloud/workspaces/projects.py +1 -1
- atlassian/bitbucket/server/__init__.py +1 -1
- atlassian/bitbucket/server/projects/__init__.py +2 -1
- atlassian/bitbucket/server/projects/repos/__init__.py +1 -0
- atlassian/confluence/__init__.py +54 -4106
- atlassian/confluence/base.py +195 -0
- atlassian/confluence/cloud/__init__.py +354 -0
- atlassian/confluence/cloud/base.py +25 -0
- atlassian/confluence/cloud/cloud.py +2480 -0
- atlassian/confluence/server/__init__.py +3988 -0
- atlassian/confluence/server/base.py +25 -0
- atlassian/confluence/server/confluence_server.py +28 -0
- atlassian/confluence_base.py +281 -0
- atlassian/confluence_v2.py +7 -0
- atlassian/crowd.py +1 -1
- atlassian/insight.py +3 -2
- atlassian/jira.py +309 -16
- atlassian/jira_models.py +10 -0
- atlassian/models/__init__.py +5 -0
- atlassian/models/jira/__init__.py +109 -0
- atlassian/models/jira/adf.py +178 -0
- atlassian/models/jira/builders.py +272 -0
- atlassian/models/jira/comment.py +52 -0
- atlassian/models/jira/fields.py +236 -0
- atlassian/models/jira/issues.py +101 -0
- atlassian/models/jira/serializer.py +138 -0
- atlassian/models/jira/transition.py +78 -0
- atlassian/models/jira/update.py +179 -0
- atlassian/models/jira/validation.py +56 -0
- atlassian/models/py.typed +0 -0
- atlassian/rest_client.py +81 -15
- atlassian/service_desk.py +41 -1
- atlassian/statuspage.py +7 -6
- atlassian/tempo/__init__.py +14 -0
- atlassian/tempo/cloud/__init__.py +232 -0
- atlassian/tempo/cloud/base.py +38 -0
- atlassian/tempo/server/__init__.py +78 -0
- atlassian/tempo/server/accounts.py +38 -0
- atlassian/tempo/server/base.py +50 -0
- atlassian/tempo/server/budgets.py +42 -0
- atlassian/tempo/server/events.py +52 -0
- atlassian/tempo/server/planner.py +42 -0
- atlassian/tempo/server/servlet.py +46 -0
- atlassian/tempo/server/teams.py +50 -0
- atlassian/tempo/server/timesheets.py +54 -0
- atlassian/typehints.py +14 -2
- atlassian/xray.py +2 -0
- {atlassian_python_api-4.0.7.dist-info → atlassian_python_api-5.0.0.dist-info}/METADATA +45 -5
- atlassian_python_api-5.0.0.dist-info/RECORD +92 -0
- {atlassian_python_api-4.0.7.dist-info → atlassian_python_api-5.0.0.dist-info}/WHEEL +1 -1
- atlassian_python_api-4.0.7.dist-info/RECORD +0 -58
- {atlassian_python_api-4.0.7.dist-info → atlassian_python_api-5.0.0.dist-info}/licenses/LICENSE +0 -0
- {atlassian_python_api-4.0.7.dist-info → atlassian_python_api-5.0.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,2480 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
# mypy: disable-error-code="arg-type, assignment, call-overload, index, operator, return-value, union-attr"
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
Confluence Cloud API implementation
|
|
7
|
+
"""
|
|
8
|
+
import functools
|
|
9
|
+
import logging
|
|
10
|
+
import re
|
|
11
|
+
import warnings
|
|
12
|
+
from typing import Any, Dict, List, Optional
|
|
13
|
+
|
|
14
|
+
from ...confluence_base import ConfluenceBase
|
|
15
|
+
|
|
16
|
+
log = logging.getLogger(__name__)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ConfluenceCloud(ConfluenceBase):
|
|
20
|
+
"""
|
|
21
|
+
Confluence Cloud API implementation class
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(self, url: str, *args, **kwargs):
|
|
25
|
+
"""
|
|
26
|
+
Initialize the ConfluenceCloud instance
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
url: The Confluence Cloud URL
|
|
30
|
+
*args: Arguments to pass to ConfluenceBase
|
|
31
|
+
**kwargs: Keyword arguments to pass to ConfluenceBase
|
|
32
|
+
"""
|
|
33
|
+
# Cloud always uses V2 API
|
|
34
|
+
kwargs.setdefault("api_version", 2)
|
|
35
|
+
super().__init__(url, *args, **kwargs)
|
|
36
|
+
|
|
37
|
+
# Initialize the compatibility method mapping
|
|
38
|
+
self._compatibility_method_mapping: Dict[str, str] = {
|
|
39
|
+
"get_content_children": "get_child_pages",
|
|
40
|
+
"get_all_spaces": "get_spaces",
|
|
41
|
+
"get_space_by_name": "get_space_by_key",
|
|
42
|
+
"add_content_label": "add_page_label",
|
|
43
|
+
}
|
|
44
|
+
# Add compatibility mapping here if needed
|
|
45
|
+
# self._compatibility_method_mapping = {
|
|
46
|
+
# "old_method_name": "new_method_name"
|
|
47
|
+
# }
|
|
48
|
+
|
|
49
|
+
# Warn about V1 method usage
|
|
50
|
+
warnings.warn(
|
|
51
|
+
"V1 methods are deprecated in ConfluenceCloud. Use V2 methods instead.", DeprecationWarning, stacklevel=2
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
def __getattr__(self, name):
|
|
55
|
+
"""
|
|
56
|
+
Intercept attribute lookup to provide compatibility with v1 method names.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
name: The attribute name being looked up
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
The corresponding v2 method if a mapping exists
|
|
63
|
+
|
|
64
|
+
Raises:
|
|
65
|
+
AttributeError: If no mapping exists and the attribute isn't found
|
|
66
|
+
"""
|
|
67
|
+
if hasattr(self, "_compatibility_method_mapping") and name in self._compatibility_method_mapping:
|
|
68
|
+
v2_method_name = self._compatibility_method_mapping[name]
|
|
69
|
+
v2_method = getattr(self, v2_method_name)
|
|
70
|
+
|
|
71
|
+
@functools.wraps(v2_method)
|
|
72
|
+
def compatibility_wrapper(*args, **kwargs):
|
|
73
|
+
warnings.warn(
|
|
74
|
+
f"The method '{name}' is deprecated in ConfluenceCloud. " f"Use '{v2_method_name}' instead.",
|
|
75
|
+
DeprecationWarning,
|
|
76
|
+
stacklevel=2,
|
|
77
|
+
)
|
|
78
|
+
return v2_method(*args, **kwargs)
|
|
79
|
+
|
|
80
|
+
return compatibility_wrapper
|
|
81
|
+
|
|
82
|
+
raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'")
|
|
83
|
+
|
|
84
|
+
def get_page_space(self, page_id: str) -> Dict[str, Any]:
|
|
85
|
+
"""Return the space associated with a page (V1 compatibility helper)."""
|
|
86
|
+
if self.api_version == 1:
|
|
87
|
+
return self.get(self.get_endpoint("page_by_id", id=page_id), params={"expand": "space"})
|
|
88
|
+
page = self.get_page_by_id(page_id)
|
|
89
|
+
return page.get("space", page)
|
|
90
|
+
|
|
91
|
+
def add_label(self, page_id: str, label: str) -> Dict[str, Any]:
|
|
92
|
+
"""Add a label to a page using the selected API version."""
|
|
93
|
+
if self.api_version == 1:
|
|
94
|
+
return self.post(self.get_endpoint("page_labels", id=page_id), data=[{"name": label}])
|
|
95
|
+
return self.add_page_label(page_id, label)
|
|
96
|
+
|
|
97
|
+
def create_space(self, key: str, name: str, **kwargs) -> Dict[str, Any]:
|
|
98
|
+
"""Create a space; retained for callers migrating from the V1 API."""
|
|
99
|
+
if self.api_version == 1:
|
|
100
|
+
data = {"key": key, "name": name, **kwargs}
|
|
101
|
+
return self.post(self.get_endpoint("spaces"), data=data)
|
|
102
|
+
return self.post(self.get_endpoint("spaces"), data={"key": key, "name": name, **kwargs})
|
|
103
|
+
|
|
104
|
+
def get_page_by_id(
|
|
105
|
+
self, page_id: str, body_format: Optional[str] = None, get_body: bool = True, expand: Optional[List[str]] = None
|
|
106
|
+
) -> Dict[str, Any]:
|
|
107
|
+
"""
|
|
108
|
+
Returns a page by ID in the v2 API format.
|
|
109
|
+
|
|
110
|
+
API Version: 2 (Cloud only)
|
|
111
|
+
|
|
112
|
+
Compatibility: This method provides similar functionality to the v1 get_page_by_id
|
|
113
|
+
but with a different parameter set and response structure.
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
page_id: The ID of the page to be returned
|
|
117
|
+
body_format: (optional) The format of the page body to be returned.
|
|
118
|
+
Valid values are 'storage', 'atlas_doc_format', or 'view'
|
|
119
|
+
get_body: (optional) Whether to retrieve the page body. Default: True
|
|
120
|
+
expand: (optional) A list of properties to expand in the response
|
|
121
|
+
Valid values: 'childTypes', 'children.page.metadata', 'children.attachment.metadata',
|
|
122
|
+
'children.comment.metadata', 'children', 'history', 'ancestors',
|
|
123
|
+
'body.atlas_doc_format', 'body.storage', 'body.view', 'version'
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
The page object in v2 API format
|
|
127
|
+
|
|
128
|
+
Raises:
|
|
129
|
+
HTTPError: If the API call fails
|
|
130
|
+
ApiError: If the page does not exist or the user doesn't have permission to view it
|
|
131
|
+
"""
|
|
132
|
+
endpoint = self.get_endpoint("page_by_id", id=page_id)
|
|
133
|
+
params = {}
|
|
134
|
+
|
|
135
|
+
if body_format:
|
|
136
|
+
if body_format not in ("storage", "atlas_doc_format", "view"):
|
|
137
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', or 'view'")
|
|
138
|
+
params["body-format"] = body_format
|
|
139
|
+
|
|
140
|
+
if not get_body:
|
|
141
|
+
params["body-format"] = "none"
|
|
142
|
+
|
|
143
|
+
if expand:
|
|
144
|
+
params["expand"] = ",".join(expand)
|
|
145
|
+
|
|
146
|
+
try:
|
|
147
|
+
return self.get(endpoint, params=params)
|
|
148
|
+
except Exception as e:
|
|
149
|
+
log.error(f"Failed to retrieve page with ID {page_id}: {e}")
|
|
150
|
+
raise
|
|
151
|
+
|
|
152
|
+
def get_pages(
|
|
153
|
+
self,
|
|
154
|
+
space_id: Optional[str] = None,
|
|
155
|
+
title: Optional[str] = None,
|
|
156
|
+
status: Optional[str] = "current",
|
|
157
|
+
body_format: Optional[str] = None,
|
|
158
|
+
get_body: bool = False,
|
|
159
|
+
expand: Optional[List[str]] = None,
|
|
160
|
+
limit: int = 25,
|
|
161
|
+
sort: Optional[str] = None,
|
|
162
|
+
cursor: Optional[str] = None,
|
|
163
|
+
) -> Dict[str, Any]:
|
|
164
|
+
"""
|
|
165
|
+
Returns a list of pages based on the provided filters.
|
|
166
|
+
|
|
167
|
+
API Version: 2 (Cloud only)
|
|
168
|
+
|
|
169
|
+
Compatibility: This method is equivalent to get_all_pages_from_space in v1,
|
|
170
|
+
but uses cursor-based pagination and supports more filtering options.
|
|
171
|
+
|
|
172
|
+
Args:
|
|
173
|
+
space_id: (optional) The ID of the space to get pages from
|
|
174
|
+
title: (optional) Filter pages by title
|
|
175
|
+
status: (optional) Filter pages by status, default is 'current'.
|
|
176
|
+
Valid values: 'current', 'archived', 'draft', 'trashed', 'deleted', 'any'
|
|
177
|
+
body_format: (optional) The format of the page body to be returned.
|
|
178
|
+
Valid values are 'storage', 'atlas_doc_format', or 'view'
|
|
179
|
+
get_body: (optional) Whether to retrieve the page body. Default: False
|
|
180
|
+
expand: (optional) A list of properties to expand in the response
|
|
181
|
+
limit: (optional) Maximum number of pages to return per request. Default: 25
|
|
182
|
+
sort: (optional) Sorting of the results. Format: [field] or [-field] for descending order
|
|
183
|
+
Valid fields: 'id', 'created-date', 'modified-date', 'title'
|
|
184
|
+
cursor: (optional) Cursor for pagination. Use the cursor from _links.next in previous response
|
|
185
|
+
|
|
186
|
+
Returns:
|
|
187
|
+
Dictionary containing results list and pagination information in v2 API format
|
|
188
|
+
|
|
189
|
+
Raises:
|
|
190
|
+
HTTPError: If the API call fails
|
|
191
|
+
"""
|
|
192
|
+
endpoint = self.get_endpoint("page")
|
|
193
|
+
params = {"limit": limit}
|
|
194
|
+
|
|
195
|
+
if space_id:
|
|
196
|
+
params["space-id"] = space_id
|
|
197
|
+
|
|
198
|
+
if title:
|
|
199
|
+
params["title"] = title
|
|
200
|
+
|
|
201
|
+
if status:
|
|
202
|
+
if status not in ("current", "archived", "draft", "trashed", "deleted", "any"):
|
|
203
|
+
raise ValueError("Status must be one of 'current', 'archived', 'draft', 'trashed', 'deleted', 'any'")
|
|
204
|
+
params["status"] = status
|
|
205
|
+
|
|
206
|
+
if body_format:
|
|
207
|
+
if body_format not in ("storage", "atlas_doc_format", "view"):
|
|
208
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', or 'view'")
|
|
209
|
+
params["body-format"] = body_format
|
|
210
|
+
elif not get_body:
|
|
211
|
+
params["body-format"] = "none"
|
|
212
|
+
|
|
213
|
+
if expand:
|
|
214
|
+
params["expand"] = ",".join(expand)
|
|
215
|
+
|
|
216
|
+
if sort:
|
|
217
|
+
valid_sort_fields = [
|
|
218
|
+
"id",
|
|
219
|
+
"-id",
|
|
220
|
+
"created-date",
|
|
221
|
+
"-created-date",
|
|
222
|
+
"modified-date",
|
|
223
|
+
"-modified-date",
|
|
224
|
+
"title",
|
|
225
|
+
"-title",
|
|
226
|
+
]
|
|
227
|
+
if sort not in valid_sort_fields:
|
|
228
|
+
raise ValueError(f"Sort must be one of: {', '.join(valid_sort_fields)}")
|
|
229
|
+
params["sort"] = sort
|
|
230
|
+
|
|
231
|
+
if cursor:
|
|
232
|
+
params["cursor"] = cursor
|
|
233
|
+
|
|
234
|
+
try:
|
|
235
|
+
return list(self._get_paged(endpoint, params=params))
|
|
236
|
+
except Exception as e:
|
|
237
|
+
log.error(f"Failed to retrieve pages: {e}")
|
|
238
|
+
raise
|
|
239
|
+
|
|
240
|
+
def get_child_pages(
|
|
241
|
+
self,
|
|
242
|
+
parent_id: str,
|
|
243
|
+
status: Optional[str] = "current",
|
|
244
|
+
body_format: Optional[str] = None,
|
|
245
|
+
get_body: bool = False,
|
|
246
|
+
expand: Optional[List[str]] = None,
|
|
247
|
+
limit: int = 25,
|
|
248
|
+
sort: Optional[str] = None,
|
|
249
|
+
) -> List[Dict[str, Any]]:
|
|
250
|
+
"""
|
|
251
|
+
Returns a list of child pages for the specified parent page.
|
|
252
|
+
|
|
253
|
+
Args:
|
|
254
|
+
parent_id: The ID of the parent page
|
|
255
|
+
status: (optional) Filter pages by status, default is 'current'.
|
|
256
|
+
Valid values: 'current', 'archived', 'any'
|
|
257
|
+
body_format: (optional) The format of the page body to be returned.
|
|
258
|
+
Valid values are 'storage', 'atlas_doc_format', or 'view'
|
|
259
|
+
get_body: (optional) Whether to retrieve the page body. Default: False
|
|
260
|
+
expand: (optional) A list of properties to expand in the response
|
|
261
|
+
limit: (optional) Maximum number of pages to return per request. Default: 25
|
|
262
|
+
sort: (optional) Sorting of the results. Format: [field] or [-field] for descending order
|
|
263
|
+
Valid fields: 'id', 'created-date', 'modified-date', 'child-position'
|
|
264
|
+
|
|
265
|
+
Returns:
|
|
266
|
+
List of child page objects in v2 API format
|
|
267
|
+
|
|
268
|
+
Raises:
|
|
269
|
+
HTTPError: If the API call fails
|
|
270
|
+
"""
|
|
271
|
+
endpoint = self.get_endpoint("child_pages", id=parent_id)
|
|
272
|
+
params = {"limit": limit}
|
|
273
|
+
|
|
274
|
+
if status:
|
|
275
|
+
# For child pages, only 'current', 'archived', and 'any' are valid
|
|
276
|
+
if status not in ("current", "archived", "any"):
|
|
277
|
+
raise ValueError("Status must be one of 'current', 'archived', 'any'")
|
|
278
|
+
params["status"] = status
|
|
279
|
+
|
|
280
|
+
if not get_body:
|
|
281
|
+
params["body-format"] = "none"
|
|
282
|
+
elif body_format:
|
|
283
|
+
if body_format not in ("storage", "atlas_doc_format", "view"):
|
|
284
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', or 'view'")
|
|
285
|
+
params["body-format"] = body_format
|
|
286
|
+
|
|
287
|
+
if expand:
|
|
288
|
+
params["expand"] = ",".join(expand)
|
|
289
|
+
|
|
290
|
+
if sort:
|
|
291
|
+
valid_sort_fields = [
|
|
292
|
+
"id",
|
|
293
|
+
"-id",
|
|
294
|
+
"created-date",
|
|
295
|
+
"-created-date",
|
|
296
|
+
"modified-date",
|
|
297
|
+
"-modified-date",
|
|
298
|
+
"child-position",
|
|
299
|
+
"-child-position",
|
|
300
|
+
]
|
|
301
|
+
if sort not in valid_sort_fields:
|
|
302
|
+
raise ValueError(f"Sort must be one of: {', '.join(valid_sort_fields)}")
|
|
303
|
+
params["sort"] = sort
|
|
304
|
+
|
|
305
|
+
try:
|
|
306
|
+
return list(self._get_paged(endpoint, params=params))
|
|
307
|
+
except Exception as e:
|
|
308
|
+
log.error(f"Failed to retrieve child pages: {e}")
|
|
309
|
+
raise
|
|
310
|
+
|
|
311
|
+
def create_page(
|
|
312
|
+
self,
|
|
313
|
+
space_id: Optional[str] = None,
|
|
314
|
+
title: str = "",
|
|
315
|
+
body: str = "",
|
|
316
|
+
parent_id: Optional[str] = None,
|
|
317
|
+
body_format: str = "storage",
|
|
318
|
+
status: str = "current",
|
|
319
|
+
representation: Optional[str] = None,
|
|
320
|
+
space: Optional[str] = None,
|
|
321
|
+
) -> Dict[str, Any]:
|
|
322
|
+
"""
|
|
323
|
+
Creates a new page in Confluence.
|
|
324
|
+
|
|
325
|
+
API Version: 2 (Cloud only)
|
|
326
|
+
|
|
327
|
+
Compatibility: This method is equivalent to create_page in v1, but with parameter
|
|
328
|
+
differences: space_id instead of space, simplified body format, and no content type.
|
|
329
|
+
|
|
330
|
+
Args:
|
|
331
|
+
space_id: The ID of the space where the page will be created
|
|
332
|
+
title: The title of the page
|
|
333
|
+
body: The content of the page
|
|
334
|
+
parent_id: (optional) The ID of the parent page
|
|
335
|
+
body_format: (optional) The format of the body. Default is 'storage'.
|
|
336
|
+
Valid values: 'storage', 'atlas_doc_format', 'wiki'
|
|
337
|
+
status: (optional) The status of the page. Default is 'current'.
|
|
338
|
+
Valid values: 'current', 'draft'
|
|
339
|
+
representation: (optional) The content representation - used only for wiki format.
|
|
340
|
+
Valid value: 'wiki'
|
|
341
|
+
|
|
342
|
+
Returns:
|
|
343
|
+
The created page object in v2 API format
|
|
344
|
+
|
|
345
|
+
Raises:
|
|
346
|
+
HTTPError: If the API call fails
|
|
347
|
+
ValueError: If invalid parameters are provided
|
|
348
|
+
"""
|
|
349
|
+
space_id = space_id or space
|
|
350
|
+
if not space_id:
|
|
351
|
+
raise ValueError("space_id or space is required")
|
|
352
|
+
endpoint = self.get_endpoint("page")
|
|
353
|
+
|
|
354
|
+
if body_format not in ("storage", "atlas_doc_format", "wiki"):
|
|
355
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', 'wiki'")
|
|
356
|
+
|
|
357
|
+
if status not in ("current", "draft"):
|
|
358
|
+
raise ValueError("status must be one of 'current', 'draft'")
|
|
359
|
+
|
|
360
|
+
if body_format == "wiki" and representation != "wiki":
|
|
361
|
+
raise ValueError("representation must be 'wiki' when body_format is 'wiki'")
|
|
362
|
+
|
|
363
|
+
data = {
|
|
364
|
+
"spaceId": space_id,
|
|
365
|
+
"status": status,
|
|
366
|
+
"title": title,
|
|
367
|
+
"body": {body_format: {"value": body, "representation": representation}},
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
# Remove representation field if None
|
|
371
|
+
if representation is None:
|
|
372
|
+
del data["body"][body_format]["representation"]
|
|
373
|
+
|
|
374
|
+
# Add parent ID if provided
|
|
375
|
+
if parent_id:
|
|
376
|
+
data["parentId"] = parent_id
|
|
377
|
+
|
|
378
|
+
try:
|
|
379
|
+
return self.post(endpoint, data=data)
|
|
380
|
+
except Exception as e:
|
|
381
|
+
log.error(f"Failed to create page: {e}")
|
|
382
|
+
raise
|
|
383
|
+
|
|
384
|
+
def update_page(
|
|
385
|
+
self,
|
|
386
|
+
page_id: str,
|
|
387
|
+
title: Optional[str] = None,
|
|
388
|
+
body: Optional[str] = None,
|
|
389
|
+
body_format: str = "storage",
|
|
390
|
+
status: Optional[str] = None,
|
|
391
|
+
version: Optional[int] = None,
|
|
392
|
+
representation: Optional[str] = None,
|
|
393
|
+
) -> Dict[str, Any]:
|
|
394
|
+
"""
|
|
395
|
+
Updates an existing page.
|
|
396
|
+
|
|
397
|
+
API Version: 2 (Cloud only)
|
|
398
|
+
|
|
399
|
+
Compatibility: This method is equivalent to update_page in v1, but requires
|
|
400
|
+
the version number and uses a simplified body format. The v2 update requires
|
|
401
|
+
at least one field (title, body, or status) to be provided.
|
|
402
|
+
|
|
403
|
+
Args:
|
|
404
|
+
page_id: The ID of the page to update
|
|
405
|
+
title: (optional) The new title of the page
|
|
406
|
+
body: (optional) The new content of the page
|
|
407
|
+
body_format: (optional) The format of the body. Default is 'storage'.
|
|
408
|
+
Valid values: 'storage', 'atlas_doc_format', 'wiki'
|
|
409
|
+
status: (optional) The new status of the page.
|
|
410
|
+
Valid values: 'current', 'draft', 'archived'
|
|
411
|
+
version: (optional) The version number for concurrency control
|
|
412
|
+
If not provided, the current version will be incremented
|
|
413
|
+
representation: (optional) The content representation - used only for wiki format.
|
|
414
|
+
Valid value: 'wiki'
|
|
415
|
+
|
|
416
|
+
Returns:
|
|
417
|
+
The updated page object in v2 API format
|
|
418
|
+
|
|
419
|
+
Raises:
|
|
420
|
+
HTTPError: If the API call fails
|
|
421
|
+
ValueError: If invalid parameters are provided
|
|
422
|
+
"""
|
|
423
|
+
endpoint = self.get_endpoint("page_by_id", id=page_id)
|
|
424
|
+
|
|
425
|
+
# Validate parameters
|
|
426
|
+
if body and body_format not in ("storage", "atlas_doc_format", "wiki"):
|
|
427
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', 'wiki'")
|
|
428
|
+
|
|
429
|
+
if status and status not in ("current", "draft", "archived"):
|
|
430
|
+
raise ValueError("status must be one of 'current', 'draft', 'archived'")
|
|
431
|
+
|
|
432
|
+
if body_format == "wiki" and representation != "wiki":
|
|
433
|
+
raise ValueError("representation must be 'wiki' when body_format is 'wiki'")
|
|
434
|
+
|
|
435
|
+
# First, get the current page to get its version
|
|
436
|
+
if version is None:
|
|
437
|
+
try:
|
|
438
|
+
current_page = self.get_page_by_id(page_id, get_body=False)
|
|
439
|
+
version = current_page.get("version", {}).get("number", 1)
|
|
440
|
+
except Exception as e:
|
|
441
|
+
log.error(f"Failed to retrieve page for update: {e}")
|
|
442
|
+
raise
|
|
443
|
+
|
|
444
|
+
# Prepare update data
|
|
445
|
+
data = {
|
|
446
|
+
"id": page_id,
|
|
447
|
+
"version": {"number": version + 1, "message": "Updated via Python API"}, # Increment the version
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
# Add optional fields
|
|
451
|
+
if title:
|
|
452
|
+
data["title"] = title
|
|
453
|
+
|
|
454
|
+
if status:
|
|
455
|
+
data["status"] = status
|
|
456
|
+
|
|
457
|
+
if body:
|
|
458
|
+
data["body"] = {body_format: {"value": body}}
|
|
459
|
+
if representation:
|
|
460
|
+
data["body"][body_format]["representation"] = representation
|
|
461
|
+
|
|
462
|
+
try:
|
|
463
|
+
return self.put(endpoint, data=data)
|
|
464
|
+
except Exception as e:
|
|
465
|
+
log.error(f"Failed to update page: {e}")
|
|
466
|
+
raise
|
|
467
|
+
|
|
468
|
+
def delete_page(self, page_id: str) -> bool:
|
|
469
|
+
"""
|
|
470
|
+
Deletes a page.
|
|
471
|
+
|
|
472
|
+
Args:
|
|
473
|
+
page_id: The ID of the page to delete
|
|
474
|
+
|
|
475
|
+
Returns:
|
|
476
|
+
True if the page was successfully deleted, False otherwise
|
|
477
|
+
|
|
478
|
+
Raises:
|
|
479
|
+
HTTPError: If the API call fails
|
|
480
|
+
"""
|
|
481
|
+
endpoint = self.get_endpoint("page_by_id", id=page_id)
|
|
482
|
+
|
|
483
|
+
try:
|
|
484
|
+
self.delete(endpoint)
|
|
485
|
+
return True
|
|
486
|
+
except Exception as e:
|
|
487
|
+
log.error(f"Failed to delete page: {e}")
|
|
488
|
+
raise
|
|
489
|
+
|
|
490
|
+
def search(
|
|
491
|
+
self,
|
|
492
|
+
query: str,
|
|
493
|
+
cql: Optional[str] = None,
|
|
494
|
+
cursor: Optional[str] = None,
|
|
495
|
+
limit: int = 25,
|
|
496
|
+
excerpt: bool = True,
|
|
497
|
+
body_format: Optional[str] = None,
|
|
498
|
+
) -> Dict[str, Any]:
|
|
499
|
+
"""
|
|
500
|
+
Search for content in Confluence.
|
|
501
|
+
|
|
502
|
+
Args:
|
|
503
|
+
query: Text to search for
|
|
504
|
+
cql: (optional) Confluence Query Language (CQL) expression to filter by
|
|
505
|
+
cursor: (optional) Cursor to start searching from for pagination
|
|
506
|
+
limit: (optional) Maximum number of results to return per request. Default: 25
|
|
507
|
+
excerpt: (optional) Whether to include excerpts in the response. Default: True
|
|
508
|
+
body_format: (optional) The format for the excerpt if excerpts are included.
|
|
509
|
+
Valid values: 'view', 'storage', or 'atlas_doc_format'
|
|
510
|
+
|
|
511
|
+
Returns:
|
|
512
|
+
Dictionary with search results
|
|
513
|
+
|
|
514
|
+
Raises:
|
|
515
|
+
HTTPError: If the API call fails
|
|
516
|
+
ValueError: If invalid parameters are provided
|
|
517
|
+
"""
|
|
518
|
+
endpoint = self.get_endpoint("search")
|
|
519
|
+
params = {"limit": limit}
|
|
520
|
+
|
|
521
|
+
# We need at least a text query or CQL
|
|
522
|
+
if not query and not cql:
|
|
523
|
+
raise ValueError("Either 'query' or 'cql' must be provided")
|
|
524
|
+
|
|
525
|
+
if query:
|
|
526
|
+
params["query"] = query
|
|
527
|
+
|
|
528
|
+
if cql:
|
|
529
|
+
params["cql"] = cql
|
|
530
|
+
|
|
531
|
+
if cursor:
|
|
532
|
+
params["cursor"] = cursor
|
|
533
|
+
|
|
534
|
+
if not excerpt:
|
|
535
|
+
params["excerpt"] = "false"
|
|
536
|
+
|
|
537
|
+
if body_format:
|
|
538
|
+
if body_format not in ("view", "storage", "atlas_doc_format"):
|
|
539
|
+
raise ValueError("body_format must be one of 'view', 'storage', or 'atlas_doc_format'")
|
|
540
|
+
params["body-format"] = body_format
|
|
541
|
+
|
|
542
|
+
try:
|
|
543
|
+
return self.get(endpoint, params=params)
|
|
544
|
+
except Exception as e:
|
|
545
|
+
log.error(f"Failed to perform search: {e}")
|
|
546
|
+
raise
|
|
547
|
+
|
|
548
|
+
def search_content(
|
|
549
|
+
self,
|
|
550
|
+
query: str,
|
|
551
|
+
type: Optional[str] = None,
|
|
552
|
+
space_id: Optional[str] = None,
|
|
553
|
+
status: Optional[str] = "current",
|
|
554
|
+
limit: int = 25,
|
|
555
|
+
) -> List[Dict[str, Any]]:
|
|
556
|
+
"""
|
|
557
|
+
Search for content with specific filters. This is a convenience method
|
|
558
|
+
that builds a CQL query and calls the search method.
|
|
559
|
+
|
|
560
|
+
Args:
|
|
561
|
+
query: Text to search for
|
|
562
|
+
_type: (optional) Content type to filter by. Valid values: 'page', 'blogpost', 'comment'
|
|
563
|
+
space_id: (optional) Space ID to restrict search to
|
|
564
|
+
status: (optional) Content status. Valid values: 'current', 'archived', 'draft', 'any'
|
|
565
|
+
limit: (optional) Maximum number of results to return per request. Default: 25
|
|
566
|
+
|
|
567
|
+
Returns:
|
|
568
|
+
List of content items matching the search criteria
|
|
569
|
+
|
|
570
|
+
Raises:
|
|
571
|
+
HTTPError: If the API call fails
|
|
572
|
+
ValueError: If invalid parameters are provided
|
|
573
|
+
"""
|
|
574
|
+
cql_parts = []
|
|
575
|
+
|
|
576
|
+
# Add text query
|
|
577
|
+
cql_parts.append(f'text ~ "{query}"')
|
|
578
|
+
|
|
579
|
+
# Add type filter
|
|
580
|
+
if type:
|
|
581
|
+
valid_types = ["page", "blogpost", "comment"]
|
|
582
|
+
if type not in valid_types:
|
|
583
|
+
raise ValueError(f"Type must be one of: {', '.join(valid_types)}")
|
|
584
|
+
cql_parts.append(f'type = "{type}"')
|
|
585
|
+
|
|
586
|
+
# Add space filter
|
|
587
|
+
if space_id:
|
|
588
|
+
cql_parts.append(f'space.id = "{space_id}"')
|
|
589
|
+
|
|
590
|
+
# Add status filter
|
|
591
|
+
if status:
|
|
592
|
+
valid_statuses = ["current", "archived", "draft", "any"]
|
|
593
|
+
if status not in valid_statuses:
|
|
594
|
+
raise ValueError(f"Status must be one of: {', '.join(valid_statuses)}")
|
|
595
|
+
if status != "any":
|
|
596
|
+
cql_parts.append(f'status = "{status}"')
|
|
597
|
+
|
|
598
|
+
# Combine all CQL parts
|
|
599
|
+
cql = " AND ".join(cql_parts)
|
|
600
|
+
|
|
601
|
+
# Call the main search method
|
|
602
|
+
result = self.search(query="", cql=cql, limit=limit)
|
|
603
|
+
|
|
604
|
+
# Return just the results array
|
|
605
|
+
return result.get("results", [])
|
|
606
|
+
|
|
607
|
+
def get_spaces(
|
|
608
|
+
self,
|
|
609
|
+
ids: Optional[List[str]] = None,
|
|
610
|
+
keys: Optional[List[str]] = None,
|
|
611
|
+
type: Optional[str] = None,
|
|
612
|
+
status: Optional[str] = None,
|
|
613
|
+
labels: Optional[List[str]] = None,
|
|
614
|
+
sort: Optional[str] = None,
|
|
615
|
+
cursor: Optional[str] = None,
|
|
616
|
+
limit: int = 25,
|
|
617
|
+
) -> List[Dict[str, Any]]:
|
|
618
|
+
"""
|
|
619
|
+
Returns all spaces, optionally filtered by provided parameters.
|
|
620
|
+
|
|
621
|
+
Args:
|
|
622
|
+
ids: (optional) List of space IDs to filter by
|
|
623
|
+
keys: (optional) List of space keys to filter by
|
|
624
|
+
_type: (optional) Type of spaces to filter by. Valid values: 'global', 'personal'
|
|
625
|
+
status: (optional) Status of spaces to filter by. Valid values: 'current', 'archived'
|
|
626
|
+
labels: (optional) List of labels to filter by (matches any)
|
|
627
|
+
sort: (optional) Sort order. Format: [field] or [-field] for descending
|
|
628
|
+
Valid fields: 'id', 'key', 'name', 'type', 'status'
|
|
629
|
+
cursor: (optional) Cursor for pagination
|
|
630
|
+
limit: (optional) Maximum number of spaces to return per request. Default: 25
|
|
631
|
+
|
|
632
|
+
Returns:
|
|
633
|
+
List of space objects
|
|
634
|
+
|
|
635
|
+
Raises:
|
|
636
|
+
HTTPError: If the API call fails
|
|
637
|
+
ValueError: If invalid parameters are provided
|
|
638
|
+
"""
|
|
639
|
+
endpoint = self.get_endpoint("spaces")
|
|
640
|
+
params = {"limit": limit}
|
|
641
|
+
|
|
642
|
+
# Add optional filters
|
|
643
|
+
if ids:
|
|
644
|
+
params["id"] = ",".join(ids)
|
|
645
|
+
|
|
646
|
+
if keys:
|
|
647
|
+
params["key"] = ",".join(keys)
|
|
648
|
+
|
|
649
|
+
if type:
|
|
650
|
+
if type not in ("global", "personal"):
|
|
651
|
+
raise ValueError("Type must be one of 'global', 'personal'")
|
|
652
|
+
params["type"] = type
|
|
653
|
+
|
|
654
|
+
if status:
|
|
655
|
+
if status not in ("current", "archived"):
|
|
656
|
+
raise ValueError("Status must be one of 'current', 'archived'")
|
|
657
|
+
params["status"] = status
|
|
658
|
+
|
|
659
|
+
if labels:
|
|
660
|
+
params["label"] = ",".join(labels)
|
|
661
|
+
|
|
662
|
+
if sort:
|
|
663
|
+
valid_sort_fields = ["id", "-id", "key", "-key", "name", "-name", "type", "-type", "status", "-status"]
|
|
664
|
+
if sort not in valid_sort_fields:
|
|
665
|
+
raise ValueError(f"Sort must be one of: {', '.join(valid_sort_fields)}")
|
|
666
|
+
params["sort"] = sort
|
|
667
|
+
|
|
668
|
+
if cursor:
|
|
669
|
+
params["cursor"] = cursor
|
|
670
|
+
|
|
671
|
+
try:
|
|
672
|
+
if self.api_version == 1:
|
|
673
|
+
return self.get(endpoint, params=params)
|
|
674
|
+
return list(self._get_paged(endpoint, params=params))
|
|
675
|
+
except Exception as e:
|
|
676
|
+
log.error(f"Failed to retrieve spaces: {e}")
|
|
677
|
+
raise
|
|
678
|
+
|
|
679
|
+
def get_space(self, space_id: str) -> Dict[str, Any]:
|
|
680
|
+
"""
|
|
681
|
+
Returns a specific space by ID.
|
|
682
|
+
|
|
683
|
+
Args:
|
|
684
|
+
space_id: The ID of the space to retrieve
|
|
685
|
+
|
|
686
|
+
Returns:
|
|
687
|
+
Space object with details
|
|
688
|
+
|
|
689
|
+
Raises:
|
|
690
|
+
HTTPError: If the API call fails or the space doesn't exist
|
|
691
|
+
"""
|
|
692
|
+
endpoint = self.get_endpoint("space_by_id", id=space_id)
|
|
693
|
+
|
|
694
|
+
try:
|
|
695
|
+
return self.get(endpoint)
|
|
696
|
+
except Exception as e:
|
|
697
|
+
log.error(f"Failed to retrieve space with ID {space_id}: {e}")
|
|
698
|
+
raise
|
|
699
|
+
|
|
700
|
+
def get_space_by_key(self, space_key: str) -> Dict[str, Any]:
|
|
701
|
+
"""
|
|
702
|
+
Returns a specific space by key.
|
|
703
|
+
This uses the get_spaces method with a key filter and returns the first match.
|
|
704
|
+
|
|
705
|
+
Args:
|
|
706
|
+
space_key: The key of the space to retrieve
|
|
707
|
+
|
|
708
|
+
Returns:
|
|
709
|
+
Space object with details
|
|
710
|
+
|
|
711
|
+
Raises:
|
|
712
|
+
HTTPError: If the API call fails
|
|
713
|
+
ValueError: If no space with the specified key exists
|
|
714
|
+
"""
|
|
715
|
+
try:
|
|
716
|
+
spaces = self.get_spaces(keys=[space_key], limit=1)
|
|
717
|
+
if not spaces:
|
|
718
|
+
raise ValueError(f"No space found with key '{space_key}'")
|
|
719
|
+
return spaces[0]
|
|
720
|
+
except Exception as e:
|
|
721
|
+
log.error(f"Failed to retrieve space with key {space_key}: {e}")
|
|
722
|
+
raise
|
|
723
|
+
|
|
724
|
+
def get_space_content(
|
|
725
|
+
self, space_id: str, depth: Optional[str] = None, sort: Optional[str] = None, limit: int = 25
|
|
726
|
+
) -> List[Dict[str, Any]]:
|
|
727
|
+
"""
|
|
728
|
+
Returns the content of a space using the search method.
|
|
729
|
+
This is a convenience method that builds a CQL query.
|
|
730
|
+
|
|
731
|
+
Args:
|
|
732
|
+
space_id: The ID of the space
|
|
733
|
+
depth: (optional) Depth of the search. Valid values: 'root', 'all'
|
|
734
|
+
sort: (optional) Sort order. Format: [field] or [-field] for descending
|
|
735
|
+
Valid fields: 'created', 'modified'
|
|
736
|
+
limit: (optional) Maximum number of items to return. Default: 25
|
|
737
|
+
|
|
738
|
+
Returns:
|
|
739
|
+
List of content items in the space
|
|
740
|
+
|
|
741
|
+
Raises:
|
|
742
|
+
HTTPError: If the API call fails
|
|
743
|
+
"""
|
|
744
|
+
cql_parts = [f'space.id = "{space_id}"']
|
|
745
|
+
|
|
746
|
+
# Add depth filter
|
|
747
|
+
if depth == "root":
|
|
748
|
+
cql_parts.append("ancestor = root")
|
|
749
|
+
|
|
750
|
+
# Combine CQL parts
|
|
751
|
+
cql = " AND ".join(cql_parts)
|
|
752
|
+
|
|
753
|
+
# Define sort for the search
|
|
754
|
+
search_params = {"cql": cql, "limit": limit}
|
|
755
|
+
|
|
756
|
+
if sort:
|
|
757
|
+
# Map sort fields to CQL sort fields
|
|
758
|
+
sort_mappings = {
|
|
759
|
+
"created": "created asc",
|
|
760
|
+
"-created": "created desc",
|
|
761
|
+
"modified": "lastmodified asc",
|
|
762
|
+
"-modified": "lastmodified desc",
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
if sort in sort_mappings:
|
|
766
|
+
search_params["cql"] += f" order by {sort_mappings[sort]}"
|
|
767
|
+
else:
|
|
768
|
+
valid_sorts = list(sort_mappings.keys())
|
|
769
|
+
raise ValueError(f"Sort must be one of: {', '.join(valid_sorts)}")
|
|
770
|
+
|
|
771
|
+
# Call search method
|
|
772
|
+
result = self.search(query="", **search_params)
|
|
773
|
+
|
|
774
|
+
# Return just the results array
|
|
775
|
+
return result.get("results", [])
|
|
776
|
+
|
|
777
|
+
def archive_space(self, space_key: str) -> Dict[str, Any]:
|
|
778
|
+
"""
|
|
779
|
+
Archive a space.
|
|
780
|
+
|
|
781
|
+
Args:
|
|
782
|
+
space_key: The key of the space to archive
|
|
783
|
+
|
|
784
|
+
Returns:
|
|
785
|
+
Response from the API
|
|
786
|
+
|
|
787
|
+
Raises:
|
|
788
|
+
HTTPError: If the API call fails or the space doesn't exist
|
|
789
|
+
"""
|
|
790
|
+
endpoint = f"rest/api/space/{space_key}/archive"
|
|
791
|
+
|
|
792
|
+
try:
|
|
793
|
+
return self.put(endpoint, absolute=False)
|
|
794
|
+
except Exception as e:
|
|
795
|
+
log.error(f"Failed to archive space {space_key}: {e}")
|
|
796
|
+
raise
|
|
797
|
+
|
|
798
|
+
def get_trashed_contents_by_space(
|
|
799
|
+
self, space_key: str, cursor: Optional[str] = None, expand: Optional[List[str]] = None, limit: int = 100
|
|
800
|
+
) -> Dict[str, Any]:
|
|
801
|
+
"""
|
|
802
|
+
Get trashed contents by space.
|
|
803
|
+
|
|
804
|
+
Args:
|
|
805
|
+
space_key: The key of the space
|
|
806
|
+
cursor: (optional) Cursor for pagination
|
|
807
|
+
expand: (optional) List of properties to expand
|
|
808
|
+
limit: (optional) Maximum number of results to return. Default: 100
|
|
809
|
+
|
|
810
|
+
Returns:
|
|
811
|
+
Response containing trashed content items
|
|
812
|
+
|
|
813
|
+
Raises:
|
|
814
|
+
HTTPError: If the API call fails
|
|
815
|
+
"""
|
|
816
|
+
endpoint = f"rest/api/space/{space_key}/content/trash"
|
|
817
|
+
params = {"limit": limit}
|
|
818
|
+
|
|
819
|
+
if cursor:
|
|
820
|
+
params["cursor"] = cursor
|
|
821
|
+
|
|
822
|
+
if expand:
|
|
823
|
+
params["expand"] = ",".join(expand)
|
|
824
|
+
|
|
825
|
+
try:
|
|
826
|
+
return self.get(endpoint, params=params, absolute=False)
|
|
827
|
+
except Exception as e:
|
|
828
|
+
log.error(f"Failed to get trashed contents for space {space_key}: {e}")
|
|
829
|
+
raise
|
|
830
|
+
|
|
831
|
+
# --------------------------------------------------
|
|
832
|
+
# Page Property Methods (Phase 3)
|
|
833
|
+
# --------------------------------------------------
|
|
834
|
+
|
|
835
|
+
def get_page_properties(self, page_id: str, cursor: Optional[str] = None, limit: int = 25) -> List[Dict[str, Any]]:
|
|
836
|
+
"""
|
|
837
|
+
Returns all properties for a page.
|
|
838
|
+
|
|
839
|
+
Args:
|
|
840
|
+
page_id: The ID of the page
|
|
841
|
+
cursor: (optional) Cursor for pagination
|
|
842
|
+
limit: (optional) Maximum number of properties to return per request. Default: 25
|
|
843
|
+
|
|
844
|
+
Returns:
|
|
845
|
+
List of page property objects
|
|
846
|
+
|
|
847
|
+
Raises:
|
|
848
|
+
HTTPError: If the API call fails
|
|
849
|
+
"""
|
|
850
|
+
endpoint = self.get_endpoint("page_properties", id=page_id)
|
|
851
|
+
params = {"limit": limit}
|
|
852
|
+
|
|
853
|
+
if cursor:
|
|
854
|
+
params["cursor"] = cursor
|
|
855
|
+
|
|
856
|
+
try:
|
|
857
|
+
if self.api_version == 1:
|
|
858
|
+
return self.get(endpoint, params=params)
|
|
859
|
+
return list(self._get_paged(endpoint, params=params))
|
|
860
|
+
except Exception as e:
|
|
861
|
+
log.error(f"Failed to retrieve properties for page {page_id}: {e}")
|
|
862
|
+
raise
|
|
863
|
+
|
|
864
|
+
def get_page_property_by_key(self, page_id: str, property_key: str) -> Dict[str, Any]:
|
|
865
|
+
"""
|
|
866
|
+
Returns a page property by key.
|
|
867
|
+
|
|
868
|
+
Args:
|
|
869
|
+
page_id: The ID of the page
|
|
870
|
+
property_key: The key of the property to retrieve
|
|
871
|
+
|
|
872
|
+
Returns:
|
|
873
|
+
The page property object
|
|
874
|
+
|
|
875
|
+
Raises:
|
|
876
|
+
HTTPError: If the API call fails or the property doesn't exist
|
|
877
|
+
"""
|
|
878
|
+
endpoint = self.get_endpoint("page_property_by_key", id=page_id, key=property_key)
|
|
879
|
+
|
|
880
|
+
try:
|
|
881
|
+
return self.get(endpoint)
|
|
882
|
+
except Exception as e:
|
|
883
|
+
log.error(f"Failed to retrieve property {property_key} for page {page_id}: {e}")
|
|
884
|
+
raise
|
|
885
|
+
|
|
886
|
+
def create_page_property(self, page_id: str, property_key: str, property_value: Any) -> Dict[str, Any]:
|
|
887
|
+
"""
|
|
888
|
+
Creates a new property for a page.
|
|
889
|
+
|
|
890
|
+
Args:
|
|
891
|
+
page_id: The ID of the page
|
|
892
|
+
key: The key of the property to create. Must only contain alphanumeric
|
|
893
|
+
characters and periods
|
|
894
|
+
value: The value of the property. Can be any JSON-serializable value
|
|
895
|
+
|
|
896
|
+
Returns:
|
|
897
|
+
The created property object
|
|
898
|
+
|
|
899
|
+
Raises:
|
|
900
|
+
HTTPError: If the API call fails
|
|
901
|
+
ValueError: If the key has invalid characters
|
|
902
|
+
"""
|
|
903
|
+
# Validate key format
|
|
904
|
+
if not re.match(r"^[a-zA-Z0-9.]+$", property_key):
|
|
905
|
+
raise ValueError("Property key must only contain alphanumeric characters and periods.")
|
|
906
|
+
|
|
907
|
+
endpoint = self.get_endpoint("page_properties", id=page_id)
|
|
908
|
+
|
|
909
|
+
data = {"key": property_key, "value": property_value}
|
|
910
|
+
|
|
911
|
+
try:
|
|
912
|
+
return self.post(endpoint, data=data)
|
|
913
|
+
except Exception as e:
|
|
914
|
+
log.error(f"Failed to create property {property_key} for page {page_id}: {e}")
|
|
915
|
+
raise
|
|
916
|
+
|
|
917
|
+
def update_page_property(
|
|
918
|
+
self, page_id: str, property_key: str, property_value: Any, version: Optional[int] = None
|
|
919
|
+
) -> Dict[str, Any]:
|
|
920
|
+
"""
|
|
921
|
+
Updates an existing property for a page.
|
|
922
|
+
|
|
923
|
+
Args:
|
|
924
|
+
page_id: The ID of the page
|
|
925
|
+
property_key: The key of the property to update
|
|
926
|
+
property_value: The new value of the property. Can be any JSON-serializable value
|
|
927
|
+
version: (optional) The version number of the property for concurrency control.
|
|
928
|
+
If not provided, the current version will be retrieved and incremented
|
|
929
|
+
|
|
930
|
+
Returns:
|
|
931
|
+
The updated page property object
|
|
932
|
+
|
|
933
|
+
Raises:
|
|
934
|
+
HTTPError: If the API call fails
|
|
935
|
+
ValueError: If the property doesn't exist
|
|
936
|
+
"""
|
|
937
|
+
endpoint = self.get_endpoint("page_property_by_key", id=page_id, key=property_key)
|
|
938
|
+
|
|
939
|
+
# Get current version if not provided
|
|
940
|
+
if version is None:
|
|
941
|
+
try:
|
|
942
|
+
current_property = self.get_page_property_by_key(page_id, property_key)
|
|
943
|
+
version = current_property.get("version", {}).get("number", 1)
|
|
944
|
+
except Exception as e:
|
|
945
|
+
raise ValueError(f"Property {property_key} doesn't exist for page {page_id}") from e
|
|
946
|
+
|
|
947
|
+
data = {
|
|
948
|
+
"key": property_key,
|
|
949
|
+
"value": property_value,
|
|
950
|
+
"version": {"number": version + 1, "message": "Updated via Python API"},
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
try:
|
|
954
|
+
return self.put(endpoint, data=data)
|
|
955
|
+
except Exception as e:
|
|
956
|
+
log.error(f"Failed to update property {property_key} for page {page_id}: {e}")
|
|
957
|
+
raise
|
|
958
|
+
|
|
959
|
+
def delete_page_property(self, page_id: str, property_key: str) -> bool:
|
|
960
|
+
"""
|
|
961
|
+
Deletes a property from a page.
|
|
962
|
+
|
|
963
|
+
Args:
|
|
964
|
+
page_id: The ID of the page
|
|
965
|
+
property_key: The key of the property to delete
|
|
966
|
+
|
|
967
|
+
Returns:
|
|
968
|
+
True if the property was successfully deleted, False otherwise
|
|
969
|
+
|
|
970
|
+
Raises:
|
|
971
|
+
HTTPError: If the API call fails
|
|
972
|
+
"""
|
|
973
|
+
endpoint = self.get_endpoint("page_property_by_key", id=page_id, key=property_key)
|
|
974
|
+
|
|
975
|
+
try:
|
|
976
|
+
self.delete(endpoint)
|
|
977
|
+
return True
|
|
978
|
+
except Exception as e:
|
|
979
|
+
log.error(f"Failed to delete property {property_key} for page {page_id}: {e}")
|
|
980
|
+
raise
|
|
981
|
+
|
|
982
|
+
# --------------------------------------------------
|
|
983
|
+
# Label Methods (Phase 3)
|
|
984
|
+
# --------------------------------------------------
|
|
985
|
+
|
|
986
|
+
def get_page_labels(
|
|
987
|
+
self, page_id: str, prefix: Optional[str] = None, cursor: Optional[str] = None, limit: int = 25
|
|
988
|
+
) -> List[Dict[str, Any]]:
|
|
989
|
+
"""
|
|
990
|
+
Returns all labels for a page.
|
|
991
|
+
|
|
992
|
+
Args:
|
|
993
|
+
page_id: The ID of the page
|
|
994
|
+
prefix: (optional) Filter the results to labels with a specific prefix
|
|
995
|
+
cursor: (optional) Cursor for pagination
|
|
996
|
+
limit: (optional) Maximum number of labels to return per request. Default: 25
|
|
997
|
+
|
|
998
|
+
Returns:
|
|
999
|
+
List of label objects
|
|
1000
|
+
|
|
1001
|
+
Raises:
|
|
1002
|
+
HTTPError: If the API call fails
|
|
1003
|
+
"""
|
|
1004
|
+
endpoint = self.get_endpoint("page_labels", id=page_id)
|
|
1005
|
+
params = {"limit": limit}
|
|
1006
|
+
|
|
1007
|
+
if prefix:
|
|
1008
|
+
params["prefix"] = prefix
|
|
1009
|
+
|
|
1010
|
+
if cursor:
|
|
1011
|
+
params["cursor"] = cursor
|
|
1012
|
+
|
|
1013
|
+
try:
|
|
1014
|
+
if self.api_version == 1:
|
|
1015
|
+
return self.get(endpoint, params=params)
|
|
1016
|
+
return list(self._get_paged(endpoint, params=params))
|
|
1017
|
+
except Exception as e:
|
|
1018
|
+
log.error(f"Failed to retrieve labels for page {page_id}: {e}")
|
|
1019
|
+
raise
|
|
1020
|
+
|
|
1021
|
+
def add_page_label(self, page_id: str, label: str) -> Dict[str, Any]:
|
|
1022
|
+
"""
|
|
1023
|
+
Adds a label to a page.
|
|
1024
|
+
|
|
1025
|
+
Args:
|
|
1026
|
+
page_id: The ID of the page
|
|
1027
|
+
label: The label to add
|
|
1028
|
+
|
|
1029
|
+
Returns:
|
|
1030
|
+
The created label object
|
|
1031
|
+
|
|
1032
|
+
Raises:
|
|
1033
|
+
HTTPError: If the API call fails
|
|
1034
|
+
ValueError: If the label is invalid
|
|
1035
|
+
"""
|
|
1036
|
+
if not label:
|
|
1037
|
+
raise ValueError("Label cannot be empty")
|
|
1038
|
+
|
|
1039
|
+
endpoint = self.get_endpoint("page_labels", id=page_id)
|
|
1040
|
+
|
|
1041
|
+
data = {"name": label}
|
|
1042
|
+
|
|
1043
|
+
try:
|
|
1044
|
+
return self.post(endpoint, data=data)
|
|
1045
|
+
except Exception as e:
|
|
1046
|
+
log.error(f"Failed to add label '{label}' to page {page_id}: {e}")
|
|
1047
|
+
raise
|
|
1048
|
+
|
|
1049
|
+
def add_page_labels(self, page_id: str, labels: List[str]) -> List[Dict[str, Any]]:
|
|
1050
|
+
"""
|
|
1051
|
+
Adds multiple labels to a page.
|
|
1052
|
+
|
|
1053
|
+
Args:
|
|
1054
|
+
page_id: The ID of the page
|
|
1055
|
+
labels: List of labels to add
|
|
1056
|
+
|
|
1057
|
+
Returns:
|
|
1058
|
+
List of created label objects
|
|
1059
|
+
|
|
1060
|
+
Raises:
|
|
1061
|
+
HTTPError: If the API call fails
|
|
1062
|
+
ValueError: If any of the labels are invalid
|
|
1063
|
+
"""
|
|
1064
|
+
if not labels:
|
|
1065
|
+
raise ValueError("Labels list cannot be empty")
|
|
1066
|
+
|
|
1067
|
+
endpoint = self.get_endpoint("page_labels", id=page_id)
|
|
1068
|
+
|
|
1069
|
+
data = [{"name": label} for label in labels]
|
|
1070
|
+
|
|
1071
|
+
try:
|
|
1072
|
+
return self.post(endpoint, data=data)
|
|
1073
|
+
except Exception as e:
|
|
1074
|
+
log.error(f"Failed to add labels {labels} to page {page_id}: {e}")
|
|
1075
|
+
raise
|
|
1076
|
+
|
|
1077
|
+
def delete_page_label(self, page_id: str, label: str) -> bool:
|
|
1078
|
+
"""
|
|
1079
|
+
Deletes a label from a page.
|
|
1080
|
+
|
|
1081
|
+
Args:
|
|
1082
|
+
page_id: The ID of the page
|
|
1083
|
+
label: The label to delete
|
|
1084
|
+
|
|
1085
|
+
Returns:
|
|
1086
|
+
True if the label was successfully deleted, False otherwise
|
|
1087
|
+
|
|
1088
|
+
Raises:
|
|
1089
|
+
HTTPError: If the API call fails
|
|
1090
|
+
"""
|
|
1091
|
+
if not label:
|
|
1092
|
+
raise ValueError("Label cannot be empty")
|
|
1093
|
+
|
|
1094
|
+
endpoint = self.get_endpoint("page_labels", id=page_id)
|
|
1095
|
+
params = {"name": label}
|
|
1096
|
+
|
|
1097
|
+
try:
|
|
1098
|
+
self.delete(endpoint, params=params)
|
|
1099
|
+
return True
|
|
1100
|
+
except Exception as e:
|
|
1101
|
+
log.error(f"Failed to delete label '{label}' from page {page_id}: {e}")
|
|
1102
|
+
raise
|
|
1103
|
+
|
|
1104
|
+
def get_space_labels(
|
|
1105
|
+
self, space_id: str, prefix: Optional[str] = None, cursor: Optional[str] = None, limit: int = 25
|
|
1106
|
+
) -> List[Dict[str, Any]]:
|
|
1107
|
+
"""
|
|
1108
|
+
Returns all labels for a space.
|
|
1109
|
+
|
|
1110
|
+
Args:
|
|
1111
|
+
space_id: The ID of the space
|
|
1112
|
+
prefix: (optional) Filter the results to labels with a specific prefix
|
|
1113
|
+
cursor: (optional) Cursor for pagination
|
|
1114
|
+
limit: (optional) Maximum number of labels to return per request. Default: 25
|
|
1115
|
+
|
|
1116
|
+
Returns:
|
|
1117
|
+
List of label objects
|
|
1118
|
+
|
|
1119
|
+
Raises:
|
|
1120
|
+
HTTPError: If the API call fails
|
|
1121
|
+
"""
|
|
1122
|
+
endpoint = self.get_endpoint("space_labels", id=space_id)
|
|
1123
|
+
params = {"limit": limit}
|
|
1124
|
+
|
|
1125
|
+
if prefix:
|
|
1126
|
+
params["prefix"] = prefix
|
|
1127
|
+
|
|
1128
|
+
if cursor:
|
|
1129
|
+
params["cursor"] = cursor
|
|
1130
|
+
|
|
1131
|
+
try:
|
|
1132
|
+
return list(self._get_paged(endpoint, params=params))
|
|
1133
|
+
except Exception as e:
|
|
1134
|
+
log.error(f"Failed to retrieve labels for space {space_id}: {e}")
|
|
1135
|
+
raise
|
|
1136
|
+
|
|
1137
|
+
def add_space_label(self, space_id: str, label: str) -> Dict[str, Any]:
|
|
1138
|
+
"""
|
|
1139
|
+
Adds a label to a space.
|
|
1140
|
+
|
|
1141
|
+
Args:
|
|
1142
|
+
space_id: The ID of the space
|
|
1143
|
+
label: The label to add
|
|
1144
|
+
|
|
1145
|
+
Returns:
|
|
1146
|
+
The created label object
|
|
1147
|
+
|
|
1148
|
+
Raises:
|
|
1149
|
+
HTTPError: If the API call fails
|
|
1150
|
+
ValueError: If the label is invalid
|
|
1151
|
+
"""
|
|
1152
|
+
if not label:
|
|
1153
|
+
raise ValueError("Label cannot be empty")
|
|
1154
|
+
|
|
1155
|
+
endpoint = self.get_endpoint("space_labels", id=space_id)
|
|
1156
|
+
|
|
1157
|
+
data = {"name": label}
|
|
1158
|
+
|
|
1159
|
+
try:
|
|
1160
|
+
return self.post(endpoint, data=data)
|
|
1161
|
+
except Exception as e:
|
|
1162
|
+
log.error(f"Failed to add label '{label}' to space {space_id}: {e}")
|
|
1163
|
+
raise
|
|
1164
|
+
|
|
1165
|
+
def add_space_labels(self, space_id: str, labels: List[str]) -> List[Dict[str, Any]]:
|
|
1166
|
+
"""
|
|
1167
|
+
Adds multiple labels to a space.
|
|
1168
|
+
|
|
1169
|
+
Args:
|
|
1170
|
+
space_id: The ID of the space
|
|
1171
|
+
labels: List of labels to add
|
|
1172
|
+
|
|
1173
|
+
Returns:
|
|
1174
|
+
List of created label objects
|
|
1175
|
+
|
|
1176
|
+
Raises:
|
|
1177
|
+
HTTPError: If the API call fails
|
|
1178
|
+
ValueError: If any of the labels are invalid
|
|
1179
|
+
"""
|
|
1180
|
+
if not labels:
|
|
1181
|
+
raise ValueError("Labels list cannot be empty")
|
|
1182
|
+
|
|
1183
|
+
endpoint = self.get_endpoint("space_labels", id=space_id)
|
|
1184
|
+
|
|
1185
|
+
data = [{"name": label} for label in labels]
|
|
1186
|
+
|
|
1187
|
+
try:
|
|
1188
|
+
return self.post(endpoint, data=data)
|
|
1189
|
+
except Exception as e:
|
|
1190
|
+
log.error(f"Failed to add labels {labels} to space {space_id}: {e}")
|
|
1191
|
+
raise
|
|
1192
|
+
|
|
1193
|
+
def delete_space_label(self, space_id: str, label: str) -> bool:
|
|
1194
|
+
"""
|
|
1195
|
+
Delete a label from a space.
|
|
1196
|
+
|
|
1197
|
+
Args:
|
|
1198
|
+
space_id: The ID of the space
|
|
1199
|
+
label: The name of the label to delete
|
|
1200
|
+
|
|
1201
|
+
Returns:
|
|
1202
|
+
True if successful
|
|
1203
|
+
|
|
1204
|
+
Raises:
|
|
1205
|
+
HTTPError: If the API call fails
|
|
1206
|
+
"""
|
|
1207
|
+
endpoint = self.get_endpoint("space_labels", id=space_id)
|
|
1208
|
+
|
|
1209
|
+
try:
|
|
1210
|
+
self.delete(f"{endpoint}/{label}")
|
|
1211
|
+
return True
|
|
1212
|
+
except Exception as e:
|
|
1213
|
+
log.error(f"Failed to delete label '{label}' from space {space_id}: {e}")
|
|
1214
|
+
raise
|
|
1215
|
+
|
|
1216
|
+
# Comment methods
|
|
1217
|
+
|
|
1218
|
+
def get_page_footer_comments(
|
|
1219
|
+
self,
|
|
1220
|
+
page_id: str,
|
|
1221
|
+
body_format: Optional[str] = None,
|
|
1222
|
+
cursor: Optional[str] = None,
|
|
1223
|
+
limit: int = 25,
|
|
1224
|
+
sort: Optional[str] = None,
|
|
1225
|
+
) -> List[Dict[str, Any]]:
|
|
1226
|
+
"""
|
|
1227
|
+
Get footer comments for a page.
|
|
1228
|
+
|
|
1229
|
+
Args:
|
|
1230
|
+
page_id: ID of the page
|
|
1231
|
+
body_format: (optional) Format of the body to be returned.
|
|
1232
|
+
Valid values: 'storage', 'atlas_doc_format', 'view'
|
|
1233
|
+
cursor: (optional) Cursor to use for pagination
|
|
1234
|
+
limit: (optional) Maximum number of comments to return per request. Default: 25
|
|
1235
|
+
sort: (optional) Sort order for comments
|
|
1236
|
+
Valid values: 'created-date', '-created-date', 'modified-date', '-modified-date'
|
|
1237
|
+
|
|
1238
|
+
Returns:
|
|
1239
|
+
List of footer comments
|
|
1240
|
+
|
|
1241
|
+
Raises:
|
|
1242
|
+
HTTPError: If the API call fails
|
|
1243
|
+
"""
|
|
1244
|
+
endpoint = self.get_endpoint("page_footer_comments", id=page_id)
|
|
1245
|
+
params = {"limit": limit}
|
|
1246
|
+
|
|
1247
|
+
if body_format:
|
|
1248
|
+
if body_format not in ("storage", "atlas_doc_format", "view"):
|
|
1249
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', or 'view'")
|
|
1250
|
+
params["body-format"] = body_format
|
|
1251
|
+
|
|
1252
|
+
if cursor:
|
|
1253
|
+
params["cursor"] = cursor
|
|
1254
|
+
|
|
1255
|
+
if sort:
|
|
1256
|
+
valid_sort_fields = ["created-date", "-created-date", "modified-date", "-modified-date"]
|
|
1257
|
+
if sort not in valid_sort_fields:
|
|
1258
|
+
raise ValueError(f"Sort must be one of: {', '.join(valid_sort_fields)}")
|
|
1259
|
+
params["sort"] = sort
|
|
1260
|
+
|
|
1261
|
+
try:
|
|
1262
|
+
return list(self._get_paged(endpoint, params=params))
|
|
1263
|
+
except Exception as e:
|
|
1264
|
+
log.error(f"Failed to get footer comments for page {page_id}: {e}")
|
|
1265
|
+
raise
|
|
1266
|
+
|
|
1267
|
+
def get_page_inline_comments(
|
|
1268
|
+
self,
|
|
1269
|
+
page_id: str,
|
|
1270
|
+
body_format: Optional[str] = None,
|
|
1271
|
+
cursor: Optional[str] = None,
|
|
1272
|
+
limit: int = 25,
|
|
1273
|
+
sort: Optional[str] = None,
|
|
1274
|
+
) -> List[Dict[str, Any]]:
|
|
1275
|
+
"""
|
|
1276
|
+
Get inline comments for a page.
|
|
1277
|
+
|
|
1278
|
+
Args:
|
|
1279
|
+
page_id: ID of the page
|
|
1280
|
+
body_format: (optional) Format of the body to be returned.
|
|
1281
|
+
Valid values: 'storage', 'atlas_doc_format', 'view'
|
|
1282
|
+
cursor: (optional) Cursor to use for pagination
|
|
1283
|
+
limit: (optional) Maximum number of comments to return per request. Default: 25
|
|
1284
|
+
sort: (optional) Sort order for comments
|
|
1285
|
+
Valid values: 'created-date', '-created-date', 'modified-date', '-modified-date'
|
|
1286
|
+
|
|
1287
|
+
Returns:
|
|
1288
|
+
List of inline comments
|
|
1289
|
+
|
|
1290
|
+
Raises:
|
|
1291
|
+
HTTPError: If the API call fails
|
|
1292
|
+
"""
|
|
1293
|
+
endpoint = self.get_endpoint("page_inline_comments", id=page_id)
|
|
1294
|
+
params = {"limit": limit}
|
|
1295
|
+
|
|
1296
|
+
if body_format:
|
|
1297
|
+
if body_format not in ("storage", "atlas_doc_format", "view"):
|
|
1298
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', or 'view'")
|
|
1299
|
+
params["body-format"] = body_format
|
|
1300
|
+
|
|
1301
|
+
if cursor:
|
|
1302
|
+
params["cursor"] = cursor
|
|
1303
|
+
|
|
1304
|
+
if sort:
|
|
1305
|
+
valid_sort_fields = ["created-date", "-created-date", "modified-date", "-modified-date"]
|
|
1306
|
+
if sort not in valid_sort_fields:
|
|
1307
|
+
raise ValueError(f"Sort must be one of: {', '.join(valid_sort_fields)}")
|
|
1308
|
+
params["sort"] = sort
|
|
1309
|
+
|
|
1310
|
+
try:
|
|
1311
|
+
return list(self._get_paged(endpoint, params=params))
|
|
1312
|
+
except Exception as e:
|
|
1313
|
+
log.error(f"Failed to get inline comments for page {page_id}: {e}")
|
|
1314
|
+
raise
|
|
1315
|
+
|
|
1316
|
+
def get_blogpost_footer_comments(
|
|
1317
|
+
self,
|
|
1318
|
+
blogpost_id: str,
|
|
1319
|
+
body_format: Optional[str] = None,
|
|
1320
|
+
cursor: Optional[str] = None,
|
|
1321
|
+
limit: int = 25,
|
|
1322
|
+
sort: Optional[str] = None,
|
|
1323
|
+
) -> List[Dict[str, Any]]:
|
|
1324
|
+
"""
|
|
1325
|
+
Get footer comments for a blog post.
|
|
1326
|
+
|
|
1327
|
+
Args:
|
|
1328
|
+
blogpost_id: ID of the blog post
|
|
1329
|
+
body_format: (optional) Format of the body to be returned.
|
|
1330
|
+
Valid values: 'storage', 'atlas_doc_format', 'view'
|
|
1331
|
+
cursor: (optional) Cursor to use for pagination
|
|
1332
|
+
limit: (optional) Maximum number of comments to return per request. Default: 25
|
|
1333
|
+
sort: (optional) Sort order for comments
|
|
1334
|
+
Valid values: 'created-date', '-created-date', 'modified-date', '-modified-date'
|
|
1335
|
+
|
|
1336
|
+
Returns:
|
|
1337
|
+
List of footer comments
|
|
1338
|
+
|
|
1339
|
+
Raises:
|
|
1340
|
+
HTTPError: If the API call fails
|
|
1341
|
+
"""
|
|
1342
|
+
endpoint = self.get_endpoint("blogpost_footer_comments", id=blogpost_id)
|
|
1343
|
+
params = {"limit": limit}
|
|
1344
|
+
|
|
1345
|
+
if body_format:
|
|
1346
|
+
if body_format not in ("storage", "atlas_doc_format", "view"):
|
|
1347
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', or 'view'")
|
|
1348
|
+
params["body-format"] = body_format
|
|
1349
|
+
|
|
1350
|
+
if cursor:
|
|
1351
|
+
params["cursor"] = cursor
|
|
1352
|
+
|
|
1353
|
+
if sort:
|
|
1354
|
+
valid_sort_fields = ["created-date", "-created-date", "modified-date", "-modified-date"]
|
|
1355
|
+
if sort not in valid_sort_fields:
|
|
1356
|
+
raise ValueError(f"Sort must be one of: {', '.join(valid_sort_fields)}")
|
|
1357
|
+
params["sort"] = sort
|
|
1358
|
+
|
|
1359
|
+
try:
|
|
1360
|
+
return list(self._get_paged(endpoint, params=params))
|
|
1361
|
+
except Exception as e:
|
|
1362
|
+
log.error(f"Failed to get footer comments for blog post {blogpost_id}: {e}")
|
|
1363
|
+
raise
|
|
1364
|
+
|
|
1365
|
+
def get_blogpost_inline_comments(
|
|
1366
|
+
self,
|
|
1367
|
+
blogpost_id: str,
|
|
1368
|
+
body_format: Optional[str] = None,
|
|
1369
|
+
cursor: Optional[str] = None,
|
|
1370
|
+
limit: int = 25,
|
|
1371
|
+
sort: Optional[str] = None,
|
|
1372
|
+
) -> List[Dict[str, Any]]:
|
|
1373
|
+
"""
|
|
1374
|
+
Get inline comments for a blog post.
|
|
1375
|
+
|
|
1376
|
+
Args:
|
|
1377
|
+
blogpost_id: ID of the blog post
|
|
1378
|
+
body_format: (optional) Format of the body to be returned.
|
|
1379
|
+
Valid values: 'storage', 'atlas_doc_format', 'view'
|
|
1380
|
+
cursor: (optional) Cursor to use for pagination
|
|
1381
|
+
limit: (optional) Maximum number of comments to return per request. Default: 25
|
|
1382
|
+
sort: (optional) Sort order for comments
|
|
1383
|
+
Valid values: 'created-date', '-created-date', 'modified-date', '-modified-date'
|
|
1384
|
+
|
|
1385
|
+
Returns:
|
|
1386
|
+
List of inline comments
|
|
1387
|
+
|
|
1388
|
+
Raises:
|
|
1389
|
+
HTTPError: If the API call fails
|
|
1390
|
+
"""
|
|
1391
|
+
endpoint = self.get_endpoint("blogpost_inline_comments", id=blogpost_id)
|
|
1392
|
+
params = {"limit": limit}
|
|
1393
|
+
|
|
1394
|
+
if body_format:
|
|
1395
|
+
if body_format not in ("storage", "atlas_doc_format", "view"):
|
|
1396
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', or 'view'")
|
|
1397
|
+
params["body-format"] = body_format
|
|
1398
|
+
|
|
1399
|
+
if cursor:
|
|
1400
|
+
params["cursor"] = cursor
|
|
1401
|
+
|
|
1402
|
+
if sort:
|
|
1403
|
+
valid_sort_fields = ["created-date", "-created-date", "modified-date", "-modified-date"]
|
|
1404
|
+
if sort not in valid_sort_fields:
|
|
1405
|
+
raise ValueError(f"Sort must be one of: {', '.join(valid_sort_fields)}")
|
|
1406
|
+
params["sort"] = sort
|
|
1407
|
+
|
|
1408
|
+
try:
|
|
1409
|
+
return list(self._get_paged(endpoint, params=params))
|
|
1410
|
+
except Exception as e:
|
|
1411
|
+
log.error(f"Failed to get inline comments for blog post {blogpost_id}: {e}")
|
|
1412
|
+
raise
|
|
1413
|
+
|
|
1414
|
+
def get_attachment_comments(
|
|
1415
|
+
self,
|
|
1416
|
+
attachment_id: str,
|
|
1417
|
+
body_format: Optional[str] = None,
|
|
1418
|
+
cursor: Optional[str] = None,
|
|
1419
|
+
limit: int = 25,
|
|
1420
|
+
sort: Optional[str] = None,
|
|
1421
|
+
) -> List[Dict[str, Any]]:
|
|
1422
|
+
"""
|
|
1423
|
+
Get comments for an attachment.
|
|
1424
|
+
|
|
1425
|
+
Args:
|
|
1426
|
+
attachment_id: ID of the attachment
|
|
1427
|
+
body_format: (optional) Format of the body to be returned.
|
|
1428
|
+
Valid values: 'storage', 'atlas_doc_format', 'view'
|
|
1429
|
+
cursor: (optional) Cursor to use for pagination
|
|
1430
|
+
limit: (optional) Maximum number of comments to return per request. Default: 25
|
|
1431
|
+
sort: (optional) Sort order for comments
|
|
1432
|
+
Valid values: 'created-date', '-created-date', 'modified-date', '-modified-date'
|
|
1433
|
+
|
|
1434
|
+
Returns:
|
|
1435
|
+
List of comments
|
|
1436
|
+
|
|
1437
|
+
Raises:
|
|
1438
|
+
HTTPError: If the API call fails
|
|
1439
|
+
"""
|
|
1440
|
+
endpoint = self.get_endpoint("attachment_comments", id=attachment_id)
|
|
1441
|
+
params = {"limit": limit}
|
|
1442
|
+
|
|
1443
|
+
if body_format:
|
|
1444
|
+
if body_format not in ("storage", "atlas_doc_format", "view"):
|
|
1445
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', or 'view'")
|
|
1446
|
+
params["body-format"] = body_format
|
|
1447
|
+
|
|
1448
|
+
if cursor:
|
|
1449
|
+
params["cursor"] = cursor
|
|
1450
|
+
|
|
1451
|
+
if sort:
|
|
1452
|
+
valid_sort_fields = ["created-date", "-created-date", "modified-date", "-modified-date"]
|
|
1453
|
+
if sort not in valid_sort_fields:
|
|
1454
|
+
raise ValueError(f"Sort must be one of: {', '.join(valid_sort_fields)}")
|
|
1455
|
+
params["sort"] = sort
|
|
1456
|
+
|
|
1457
|
+
try:
|
|
1458
|
+
return list(self._get_paged(endpoint, params=params))
|
|
1459
|
+
except Exception as e:
|
|
1460
|
+
log.error(f"Failed to get comments for attachment {attachment_id}: {e}")
|
|
1461
|
+
raise
|
|
1462
|
+
|
|
1463
|
+
def get_custom_content_comments(
|
|
1464
|
+
self,
|
|
1465
|
+
custom_content_id: str,
|
|
1466
|
+
body_format: Optional[str] = None,
|
|
1467
|
+
cursor: Optional[str] = None,
|
|
1468
|
+
limit: int = 25,
|
|
1469
|
+
sort: Optional[str] = None,
|
|
1470
|
+
) -> List[Dict[str, Any]]:
|
|
1471
|
+
"""
|
|
1472
|
+
Get comments for custom content.
|
|
1473
|
+
|
|
1474
|
+
Args:
|
|
1475
|
+
custom_content_id: ID of the custom content
|
|
1476
|
+
body_format: (optional) Format of the body to be returned.
|
|
1477
|
+
Valid values: 'storage', 'atlas_doc_format', 'view'
|
|
1478
|
+
cursor: (optional) Cursor to use for pagination
|
|
1479
|
+
limit: (optional) Maximum number of comments to return per request. Default: 25
|
|
1480
|
+
sort: (optional) Sort order for comments
|
|
1481
|
+
Valid values: 'created-date', '-created-date', 'modified-date', '-modified-date'
|
|
1482
|
+
|
|
1483
|
+
Returns:
|
|
1484
|
+
List of comments
|
|
1485
|
+
|
|
1486
|
+
Raises:
|
|
1487
|
+
HTTPError: If the API call fails
|
|
1488
|
+
"""
|
|
1489
|
+
endpoint = self.get_endpoint("custom_content_comments", id=custom_content_id)
|
|
1490
|
+
params = {"limit": limit}
|
|
1491
|
+
|
|
1492
|
+
if body_format:
|
|
1493
|
+
if body_format not in ("storage", "atlas_doc_format", "view"):
|
|
1494
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', or 'view'")
|
|
1495
|
+
params["body-format"] = body_format
|
|
1496
|
+
|
|
1497
|
+
if cursor:
|
|
1498
|
+
params["cursor"] = cursor
|
|
1499
|
+
|
|
1500
|
+
if sort:
|
|
1501
|
+
valid_sort_fields = ["created-date", "-created-date", "modified-date", "-modified-date"]
|
|
1502
|
+
if sort not in valid_sort_fields:
|
|
1503
|
+
raise ValueError(f"Sort must be one of: {', '.join(valid_sort_fields)}")
|
|
1504
|
+
params["sort"] = sort
|
|
1505
|
+
|
|
1506
|
+
try:
|
|
1507
|
+
return list(self._get_paged(endpoint, params=params))
|
|
1508
|
+
except Exception as e:
|
|
1509
|
+
log.error(f"Failed to get comments for custom content {custom_content_id}: {e}")
|
|
1510
|
+
raise
|
|
1511
|
+
|
|
1512
|
+
def get_comment_children(
|
|
1513
|
+
self,
|
|
1514
|
+
comment_id: str,
|
|
1515
|
+
body_format: Optional[str] = None,
|
|
1516
|
+
cursor: Optional[str] = None,
|
|
1517
|
+
limit: int = 25,
|
|
1518
|
+
sort: Optional[str] = None,
|
|
1519
|
+
) -> List[Dict[str, Any]]:
|
|
1520
|
+
"""
|
|
1521
|
+
Get child comments for a comment.
|
|
1522
|
+
|
|
1523
|
+
Args:
|
|
1524
|
+
comment_id: ID of the parent comment
|
|
1525
|
+
body_format: (optional) Format of the body to be returned.
|
|
1526
|
+
Valid values: 'storage', 'atlas_doc_format', 'view'
|
|
1527
|
+
cursor: (optional) Cursor to use for pagination
|
|
1528
|
+
limit: (optional) Maximum number of comments to return per request. Default: 25
|
|
1529
|
+
sort: (optional) Sort order for comments
|
|
1530
|
+
Valid values: 'created-date', '-created-date', 'modified-date', '-modified-date'
|
|
1531
|
+
|
|
1532
|
+
Returns:
|
|
1533
|
+
List of child comments
|
|
1534
|
+
|
|
1535
|
+
Raises:
|
|
1536
|
+
HTTPError: If the API call fails
|
|
1537
|
+
"""
|
|
1538
|
+
endpoint = self.get_endpoint("comment_children", id=comment_id)
|
|
1539
|
+
params = {"limit": limit}
|
|
1540
|
+
|
|
1541
|
+
if body_format:
|
|
1542
|
+
if body_format not in ("storage", "atlas_doc_format", "view"):
|
|
1543
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', or 'view'")
|
|
1544
|
+
params["body-format"] = body_format
|
|
1545
|
+
|
|
1546
|
+
if cursor:
|
|
1547
|
+
params["cursor"] = cursor
|
|
1548
|
+
|
|
1549
|
+
if sort:
|
|
1550
|
+
valid_sort_fields = ["created-date", "-created-date", "modified-date", "-modified-date"]
|
|
1551
|
+
if sort not in valid_sort_fields:
|
|
1552
|
+
raise ValueError(f"Sort must be one of: {', '.join(valid_sort_fields)}")
|
|
1553
|
+
params["sort"] = sort
|
|
1554
|
+
|
|
1555
|
+
try:
|
|
1556
|
+
return list(self._get_paged(endpoint, params=params))
|
|
1557
|
+
except Exception as e:
|
|
1558
|
+
log.error(f"Failed to get child comments for comment {comment_id}: {e}")
|
|
1559
|
+
raise
|
|
1560
|
+
|
|
1561
|
+
def get_comment_by_id(
|
|
1562
|
+
self, comment_id: str, body_format: Optional[str] = None, version: Optional[int] = None
|
|
1563
|
+
) -> Dict[str, Any]:
|
|
1564
|
+
"""
|
|
1565
|
+
Get a comment by ID.
|
|
1566
|
+
|
|
1567
|
+
Args:
|
|
1568
|
+
comment_id: ID of the comment
|
|
1569
|
+
body_format: (optional) Format of the body to be returned.
|
|
1570
|
+
Valid values: 'storage', 'atlas_doc_format', 'view'
|
|
1571
|
+
version: (optional) Version number to retrieve
|
|
1572
|
+
|
|
1573
|
+
Returns:
|
|
1574
|
+
Comment details
|
|
1575
|
+
|
|
1576
|
+
Raises:
|
|
1577
|
+
HTTPError: If the API call fails
|
|
1578
|
+
"""
|
|
1579
|
+
endpoint = self.get_endpoint("comment_by_id", id=comment_id)
|
|
1580
|
+
params = {}
|
|
1581
|
+
|
|
1582
|
+
if body_format:
|
|
1583
|
+
if body_format not in ("storage", "atlas_doc_format", "view"):
|
|
1584
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', or 'view'")
|
|
1585
|
+
params["body-format"] = body_format
|
|
1586
|
+
|
|
1587
|
+
if version:
|
|
1588
|
+
params["version"] = version
|
|
1589
|
+
|
|
1590
|
+
try:
|
|
1591
|
+
return self.get(endpoint, params=params)
|
|
1592
|
+
except Exception as e:
|
|
1593
|
+
log.error(f"Failed to get comment {comment_id}: {e}")
|
|
1594
|
+
raise
|
|
1595
|
+
|
|
1596
|
+
def create_page_footer_comment(self, page_id: str, body: str, body_format: str = "storage") -> Dict[str, Any]:
|
|
1597
|
+
"""
|
|
1598
|
+
Create a footer comment on a page.
|
|
1599
|
+
|
|
1600
|
+
Args:
|
|
1601
|
+
page_id: ID of the page
|
|
1602
|
+
body: Body of the comment
|
|
1603
|
+
body_format: (optional) Format of the comment body.
|
|
1604
|
+
Valid values: 'storage', 'atlas_doc_format', 'wiki'
|
|
1605
|
+
|
|
1606
|
+
Returns:
|
|
1607
|
+
The created comment
|
|
1608
|
+
|
|
1609
|
+
Raises:
|
|
1610
|
+
HTTPError: If the API call fails
|
|
1611
|
+
"""
|
|
1612
|
+
endpoint = self.get_endpoint("comment")
|
|
1613
|
+
|
|
1614
|
+
if body_format not in ("storage", "atlas_doc_format", "wiki"):
|
|
1615
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', 'wiki'")
|
|
1616
|
+
|
|
1617
|
+
data = {"pageId": page_id, "body": {body_format: {"representation": body_format, "value": body}}}
|
|
1618
|
+
|
|
1619
|
+
try:
|
|
1620
|
+
return self.post(endpoint, data=data)
|
|
1621
|
+
except Exception as e:
|
|
1622
|
+
log.error(f"Failed to create footer comment on page {page_id}: {e}")
|
|
1623
|
+
raise
|
|
1624
|
+
|
|
1625
|
+
def create_page_inline_comment(
|
|
1626
|
+
self, page_id: str, body: str, inline_comment_properties: Dict[str, Any], body_format: str = "storage"
|
|
1627
|
+
) -> Dict[str, Any]:
|
|
1628
|
+
"""
|
|
1629
|
+
Create an inline comment on a page.
|
|
1630
|
+
|
|
1631
|
+
Args:
|
|
1632
|
+
page_id: ID of the page
|
|
1633
|
+
body: Body of the comment
|
|
1634
|
+
inline_comment_properties: Properties for inline comment, e.g.:
|
|
1635
|
+
{
|
|
1636
|
+
"textSelection": "text to highlight",
|
|
1637
|
+
"textSelectionMatchCount": 3,
|
|
1638
|
+
"textSelectionMatchIndex": 1
|
|
1639
|
+
}
|
|
1640
|
+
body_format: (optional) Format of the comment body.
|
|
1641
|
+
Valid values: 'storage', 'atlas_doc_format', 'wiki'
|
|
1642
|
+
|
|
1643
|
+
Returns:
|
|
1644
|
+
The created comment
|
|
1645
|
+
|
|
1646
|
+
Raises:
|
|
1647
|
+
HTTPError: If the API call fails
|
|
1648
|
+
"""
|
|
1649
|
+
endpoint = self.get_endpoint("comment")
|
|
1650
|
+
|
|
1651
|
+
if body_format not in ("storage", "atlas_doc_format", "wiki"):
|
|
1652
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', 'wiki'")
|
|
1653
|
+
|
|
1654
|
+
required_props = ["textSelection", "textSelectionMatchCount", "textSelectionMatchIndex"]
|
|
1655
|
+
for prop in required_props:
|
|
1656
|
+
if prop not in inline_comment_properties:
|
|
1657
|
+
raise ValueError(f"inline_comment_properties must contain '{prop}'")
|
|
1658
|
+
|
|
1659
|
+
data = {
|
|
1660
|
+
"pageId": page_id,
|
|
1661
|
+
"body": {body_format: {"representation": body_format, "value": body}},
|
|
1662
|
+
"inlineCommentProperties": inline_comment_properties,
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
try:
|
|
1666
|
+
return self.post(endpoint, data=data)
|
|
1667
|
+
except Exception as e:
|
|
1668
|
+
log.error(f"Failed to create inline comment on page {page_id}: {e}")
|
|
1669
|
+
raise
|
|
1670
|
+
|
|
1671
|
+
def create_blogpost_footer_comment(
|
|
1672
|
+
self, blogpost_id: str, body: str, body_format: str = "storage"
|
|
1673
|
+
) -> Dict[str, Any]:
|
|
1674
|
+
"""
|
|
1675
|
+
Create a footer comment on a blog post.
|
|
1676
|
+
|
|
1677
|
+
Args:
|
|
1678
|
+
blogpost_id: ID of the blog post
|
|
1679
|
+
body: Body of the comment
|
|
1680
|
+
body_format: (optional) Format of the comment body.
|
|
1681
|
+
Valid values: 'storage', 'atlas_doc_format', 'wiki'
|
|
1682
|
+
|
|
1683
|
+
Returns:
|
|
1684
|
+
The created comment
|
|
1685
|
+
|
|
1686
|
+
Raises:
|
|
1687
|
+
HTTPError: If the API call fails
|
|
1688
|
+
"""
|
|
1689
|
+
endpoint = self.get_endpoint("comment")
|
|
1690
|
+
|
|
1691
|
+
if body_format not in ("storage", "atlas_doc_format", "wiki"):
|
|
1692
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', 'wiki'")
|
|
1693
|
+
|
|
1694
|
+
data = {"blogPostId": blogpost_id, "body": {body_format: {"representation": body_format, "value": body}}}
|
|
1695
|
+
|
|
1696
|
+
try:
|
|
1697
|
+
return self.post(endpoint, data=data)
|
|
1698
|
+
except Exception as e:
|
|
1699
|
+
log.error(f"Failed to create footer comment on blog post {blogpost_id}: {e}")
|
|
1700
|
+
raise
|
|
1701
|
+
|
|
1702
|
+
def create_custom_content_comment(
|
|
1703
|
+
self, custom_content_id: str, body: str, body_format: str = "storage"
|
|
1704
|
+
) -> Dict[str, Any]:
|
|
1705
|
+
"""
|
|
1706
|
+
Create a comment on custom content.
|
|
1707
|
+
|
|
1708
|
+
Args:
|
|
1709
|
+
custom_content_id: ID of the custom content
|
|
1710
|
+
body: Body of the comment
|
|
1711
|
+
body_format: (optional) Format of the comment body.
|
|
1712
|
+
Valid values: 'storage', 'atlas_doc_format', 'wiki'
|
|
1713
|
+
|
|
1714
|
+
Returns:
|
|
1715
|
+
The created comment
|
|
1716
|
+
|
|
1717
|
+
Raises:
|
|
1718
|
+
HTTPError: If the API call fails
|
|
1719
|
+
"""
|
|
1720
|
+
endpoint = self.get_endpoint("comment")
|
|
1721
|
+
|
|
1722
|
+
if body_format not in ("storage", "atlas_doc_format", "wiki"):
|
|
1723
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', 'wiki'")
|
|
1724
|
+
|
|
1725
|
+
data = {
|
|
1726
|
+
"customContentId": custom_content_id,
|
|
1727
|
+
"body": {body_format: {"representation": body_format, "value": body}},
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
try:
|
|
1731
|
+
return self.post(endpoint, data=data)
|
|
1732
|
+
except Exception as e:
|
|
1733
|
+
log.error(f"Failed to create comment on custom content {custom_content_id}: {e}")
|
|
1734
|
+
raise
|
|
1735
|
+
|
|
1736
|
+
def create_attachment_comment(self, attachment_id: str, body: str, body_format: str = "storage") -> Dict[str, Any]:
|
|
1737
|
+
"""
|
|
1738
|
+
Create a comment on an attachment.
|
|
1739
|
+
|
|
1740
|
+
Args:
|
|
1741
|
+
attachment_id: ID of the attachment
|
|
1742
|
+
body: Body of the comment
|
|
1743
|
+
body_format: (optional) Format of the comment body.
|
|
1744
|
+
Valid values: 'storage', 'atlas_doc_format', 'wiki'
|
|
1745
|
+
|
|
1746
|
+
Returns:
|
|
1747
|
+
The created comment
|
|
1748
|
+
|
|
1749
|
+
Raises:
|
|
1750
|
+
HTTPError: If the API call fails
|
|
1751
|
+
"""
|
|
1752
|
+
endpoint = self.get_endpoint("comment")
|
|
1753
|
+
|
|
1754
|
+
if body_format not in ("storage", "atlas_doc_format", "wiki"):
|
|
1755
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', 'wiki'")
|
|
1756
|
+
|
|
1757
|
+
data = {"attachmentId": attachment_id, "body": {body_format: {"representation": body_format, "value": body}}}
|
|
1758
|
+
|
|
1759
|
+
try:
|
|
1760
|
+
return self.post(endpoint, data=data)
|
|
1761
|
+
except Exception as e:
|
|
1762
|
+
log.error(f"Failed to create comment on attachment {attachment_id}: {e}")
|
|
1763
|
+
raise
|
|
1764
|
+
|
|
1765
|
+
def create_comment_reply(self, parent_comment_id: str, body: str, body_format: str = "storage") -> Dict[str, Any]:
|
|
1766
|
+
"""
|
|
1767
|
+
Create a reply to an existing comment.
|
|
1768
|
+
|
|
1769
|
+
Args:
|
|
1770
|
+
parent_comment_id: ID of the parent comment
|
|
1771
|
+
body: Body of the comment
|
|
1772
|
+
body_format: (optional) Format of the comment body.
|
|
1773
|
+
Valid values: 'storage', 'atlas_doc_format', 'wiki'
|
|
1774
|
+
|
|
1775
|
+
Returns:
|
|
1776
|
+
The created comment
|
|
1777
|
+
|
|
1778
|
+
Raises:
|
|
1779
|
+
HTTPError: If the API call fails
|
|
1780
|
+
"""
|
|
1781
|
+
endpoint = self.get_endpoint("comment")
|
|
1782
|
+
|
|
1783
|
+
if body_format not in ("storage", "atlas_doc_format", "wiki"):
|
|
1784
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', 'wiki'")
|
|
1785
|
+
|
|
1786
|
+
data = {
|
|
1787
|
+
"parentCommentId": parent_comment_id,
|
|
1788
|
+
"body": {body_format: {"representation": body_format, "value": body}},
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
try:
|
|
1792
|
+
return self.post(endpoint, data=data)
|
|
1793
|
+
except Exception as e:
|
|
1794
|
+
log.error(f"Failed to create reply to comment {parent_comment_id}: {e}")
|
|
1795
|
+
raise
|
|
1796
|
+
|
|
1797
|
+
def update_comment(
|
|
1798
|
+
self, comment_id: str, body: str, version: int, body_format: str = "storage", resolved: Optional[bool] = None
|
|
1799
|
+
) -> Dict[str, Any]:
|
|
1800
|
+
"""
|
|
1801
|
+
Update an existing comment.
|
|
1802
|
+
|
|
1803
|
+
Args:
|
|
1804
|
+
comment_id: ID of the comment
|
|
1805
|
+
body: Updated body of the comment
|
|
1806
|
+
version: Current version number of the comment (will increment by 1)
|
|
1807
|
+
body_format: (optional) Format of the comment body.
|
|
1808
|
+
Valid values: 'storage', 'atlas_doc_format', 'wiki'
|
|
1809
|
+
resolved: (optional) For inline comments - whether to mark as resolved
|
|
1810
|
+
|
|
1811
|
+
Returns:
|
|
1812
|
+
The updated comment
|
|
1813
|
+
|
|
1814
|
+
Raises:
|
|
1815
|
+
HTTPError: If the API call fails
|
|
1816
|
+
"""
|
|
1817
|
+
endpoint = self.get_endpoint("comment_by_id", id=comment_id)
|
|
1818
|
+
|
|
1819
|
+
if body_format not in ("storage", "atlas_doc_format", "wiki"):
|
|
1820
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', 'wiki'")
|
|
1821
|
+
|
|
1822
|
+
data = {
|
|
1823
|
+
"version": {"number": version + 1},
|
|
1824
|
+
"body": {body_format: {"representation": body_format, "value": body}},
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
if resolved is not None:
|
|
1828
|
+
data["resolved"] = resolved
|
|
1829
|
+
|
|
1830
|
+
try:
|
|
1831
|
+
return self.put(endpoint, data=data)
|
|
1832
|
+
except Exception as e:
|
|
1833
|
+
log.error(f"Failed to update comment {comment_id}: {e}")
|
|
1834
|
+
raise
|
|
1835
|
+
|
|
1836
|
+
def delete_comment(self, comment_id: str) -> bool:
|
|
1837
|
+
"""
|
|
1838
|
+
Delete a comment.
|
|
1839
|
+
|
|
1840
|
+
Args:
|
|
1841
|
+
comment_id: ID of the comment to delete
|
|
1842
|
+
|
|
1843
|
+
Returns:
|
|
1844
|
+
True if successful
|
|
1845
|
+
|
|
1846
|
+
Raises:
|
|
1847
|
+
HTTPError: If the API call fails
|
|
1848
|
+
"""
|
|
1849
|
+
endpoint = self.get_endpoint("comment_by_id", id=comment_id)
|
|
1850
|
+
|
|
1851
|
+
try:
|
|
1852
|
+
self.delete(endpoint)
|
|
1853
|
+
return True
|
|
1854
|
+
except Exception as e:
|
|
1855
|
+
log.error(f"Failed to delete comment {comment_id}: {e}")
|
|
1856
|
+
raise
|
|
1857
|
+
|
|
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
|
+
"""
|
|
2039
|
+
##############################################################################################
|
|
2040
|
+
# Confluence Custom Content API (Cloud only) #
|
|
2041
|
+
##############################################################################################
|
|
2042
|
+
"""
|
|
2043
|
+
|
|
2044
|
+
def create_custom_content(
|
|
2045
|
+
self,
|
|
2046
|
+
type: str,
|
|
2047
|
+
title: str,
|
|
2048
|
+
body: str,
|
|
2049
|
+
space_id: Optional[str] = None,
|
|
2050
|
+
page_id: Optional[str] = None,
|
|
2051
|
+
blog_post_id: Optional[str] = None,
|
|
2052
|
+
custom_content_id: Optional[str] = None,
|
|
2053
|
+
status: str = "current",
|
|
2054
|
+
body_format: str = "storage",
|
|
2055
|
+
) -> Dict[str, Any]:
|
|
2056
|
+
"""
|
|
2057
|
+
Creates a new custom content.
|
|
2058
|
+
|
|
2059
|
+
Args:
|
|
2060
|
+
type: Type of custom content
|
|
2061
|
+
title: Title of the custom content
|
|
2062
|
+
body: Content body in the specified format
|
|
2063
|
+
space_id: (optional) ID of the containing space
|
|
2064
|
+
page_id: (optional) ID of the containing page
|
|
2065
|
+
blog_post_id: (optional) ID of the containing blog post
|
|
2066
|
+
custom_content_id: (optional) ID of the containing custom content
|
|
2067
|
+
status: (optional) Status of the custom content, default is "current".
|
|
2068
|
+
Valid values are "current" or "draft"
|
|
2069
|
+
body_format: (optional) Format of the body. Default is "storage".
|
|
2070
|
+
Valid values are "storage", "atlas_doc_format", or "raw"
|
|
2071
|
+
|
|
2072
|
+
Returns:
|
|
2073
|
+
Created custom content data
|
|
2074
|
+
|
|
2075
|
+
Raises:
|
|
2076
|
+
HTTPError: If the API call fails
|
|
2077
|
+
ValueError: If invalid parameters are provided
|
|
2078
|
+
"""
|
|
2079
|
+
endpoint = self.get_endpoint("custom_content")
|
|
2080
|
+
|
|
2081
|
+
if body_format not in ("storage", "atlas_doc_format", "raw"):
|
|
2082
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', 'raw'")
|
|
2083
|
+
|
|
2084
|
+
if status not in ("current", "draft"):
|
|
2085
|
+
raise ValueError("status must be one of 'current', 'draft'")
|
|
2086
|
+
|
|
2087
|
+
# At least one container ID must be provided
|
|
2088
|
+
if not any([space_id, page_id, blog_post_id, custom_content_id]):
|
|
2089
|
+
raise ValueError(
|
|
2090
|
+
"At least one container ID (space_id, page_id, blog_post_id, or custom_content_id) must be provided"
|
|
2091
|
+
)
|
|
2092
|
+
|
|
2093
|
+
data = {
|
|
2094
|
+
"type": type,
|
|
2095
|
+
"title": title,
|
|
2096
|
+
"body": {body_format: {"representation": body_format, "value": body}},
|
|
2097
|
+
"status": status,
|
|
2098
|
+
}
|
|
2099
|
+
|
|
2100
|
+
if space_id:
|
|
2101
|
+
data["spaceId"] = space_id
|
|
2102
|
+
if page_id:
|
|
2103
|
+
data["pageId"] = page_id
|
|
2104
|
+
if blog_post_id:
|
|
2105
|
+
data["blogPostId"] = blog_post_id
|
|
2106
|
+
if custom_content_id:
|
|
2107
|
+
data["customContentId"] = custom_content_id
|
|
2108
|
+
|
|
2109
|
+
try:
|
|
2110
|
+
return self.post(endpoint, data=data)
|
|
2111
|
+
except Exception as e:
|
|
2112
|
+
log.error(f"Failed to create custom content: {e}")
|
|
2113
|
+
raise
|
|
2114
|
+
|
|
2115
|
+
def get_custom_content_by_id(self, custom_content_id: str, body_format: Optional[str] = None) -> Dict[str, Any]:
|
|
2116
|
+
"""
|
|
2117
|
+
Get custom content by its ID.
|
|
2118
|
+
|
|
2119
|
+
Args:
|
|
2120
|
+
custom_content_id: ID of the custom content to retrieve
|
|
2121
|
+
body_format: (optional) Format to retrieve the body in.
|
|
2122
|
+
Valid values: "storage", "atlas_doc_format", "raw", "view"
|
|
2123
|
+
|
|
2124
|
+
Returns:
|
|
2125
|
+
Custom content data
|
|
2126
|
+
|
|
2127
|
+
Raises:
|
|
2128
|
+
HTTPError: If the API call fails
|
|
2129
|
+
"""
|
|
2130
|
+
endpoint = self.get_endpoint("custom_content_by_id", id=custom_content_id)
|
|
2131
|
+
|
|
2132
|
+
params = {}
|
|
2133
|
+
if body_format:
|
|
2134
|
+
if body_format not in ("storage", "atlas_doc_format", "raw", "view"):
|
|
2135
|
+
raise ValueError("body_format must be one of 'storage', 'atlas_doc_format', 'raw', 'view'")
|
|
2136
|
+
params["body-format"] = body_format
|
|
2137
|
+
|
|
2138
|
+
try:
|
|
2139
|
+
return self.get(endpoint, params=params)
|
|
2140
|
+
except Exception as e:
|
|
2141
|
+
log.error(f"Failed to get custom content {custom_content_id}: {e}")
|
|
2142
|
+
raise
|
|
2143
|
+
|
|
2144
|
+
def get_custom_content(
|
|
2145
|
+
self,
|
|
2146
|
+
type: Optional[str] = None,
|
|
2147
|
+
space_id: Optional[str] = None,
|
|
2148
|
+
page_id: Optional[str] = None,
|
|
2149
|
+
blog_post_id: Optional[str] = None,
|
|
2150
|
+
custom_content_id: Optional[str] = None,
|
|
2151
|
+
ids: Optional[List[str]] = None,
|
|
2152
|
+
status: Optional[str] = None,
|
|
2153
|
+
body_format: Optional[str] = None,
|
|
2154
|
+
sort: Optional[str] = None,
|
|
2155
|
+
cursor: Optional[str] = None,
|
|
2156
|
+
limit: Optional[int] = None,
|
|
2157
|
+
) -> List[Dict[str, Any]]:
|
|
2158
|
+
"""
|
|
2159
|
+
Get custom content with optional filtering.
|
|
2160
|
+
|
|
2161
|
+
Args:
|
|
2162
|
+
_type: (optional) Filter by custom content type
|
|
2163
|
+
space_id: (optional) Filter by space ID
|
|
2164
|
+
page_id: (optional) Filter by page ID
|
|
2165
|
+
blog_post_id: (optional) Filter by blog post ID
|
|
2166
|
+
custom_content_id: (optional) Filter by parent custom content ID
|
|
2167
|
+
ids: (optional) List of custom content IDs to filter by
|
|
2168
|
+
status: (optional) Filter by status. Valid values: "current", "draft", "archived", "trashed", "deleted", "any"
|
|
2169
|
+
body_format: (optional) Format to retrieve the body in.
|
|
2170
|
+
Valid values: "storage", "atlas_doc_format", "raw", "view"
|
|
2171
|
+
sort: (optional) Sort order. Example: "id", "-created-date"
|
|
2172
|
+
cursor: (optional) Cursor for pagination
|
|
2173
|
+
limit: (optional) Maximum number of results to return
|
|
2174
|
+
|
|
2175
|
+
Returns:
|
|
2176
|
+
List of custom content
|
|
2177
|
+
|
|
2178
|
+
Raises:
|
|
2179
|
+
HTTPError: If the API call fails
|
|
2180
|
+
"""
|
|
2181
|
+
endpoint = self.get_endpoint("custom_content")
|
|
2182
|
+
|
|
2183
|
+
params = {}
|
|
2184
|
+
if type:
|
|
2185
|
+
params["type"] = type
|
|
2186
|
+
if space_id:
|
|
2187
|
+
params["space-id"] = space_id
|
|
2188
|
+
if page_id:
|
|
2189
|
+
params["page-id"] = page_id
|
|
2190
|
+
if blog_post_id:
|
|
2191
|
+
params["blog-post-id"] = blog_post_id
|
|
2192
|
+
if custom_content_id:
|
|
2193
|
+
params["custom-content-id"] = custom_content_id
|
|
2194
|
+
if ids:
|
|
2195
|
+
params["id"] = ",".join(ids)
|
|
2196
|
+
if status:
|
|
2197
|
+
params["status"] = status
|
|
2198
|
+
if body_format:
|
|
2199
|
+
params["body-format"] = body_format
|
|
2200
|
+
if sort:
|
|
2201
|
+
params["sort"] = sort
|
|
2202
|
+
if limit:
|
|
2203
|
+
params["limit"] = limit
|
|
2204
|
+
if cursor:
|
|
2205
|
+
params["cursor"] = cursor
|
|
2206
|
+
|
|
2207
|
+
try:
|
|
2208
|
+
return list(self._get_paged(endpoint, params=params))
|
|
2209
|
+
except Exception as e:
|
|
2210
|
+
log.error(f"Failed to retrieve custom content: {e}")
|
|
2211
|
+
raise
|
|
2212
|
+
|
|
2213
|
+
def add_custom_content_label(self, custom_content_id: str, label: str, prefix: str = "global") -> Dict[str, Any]:
|
|
2214
|
+
"""
|
|
2215
|
+
Adds a label to custom content.
|
|
2216
|
+
|
|
2217
|
+
Args:
|
|
2218
|
+
custom_content_id: The ID of the custom content
|
|
2219
|
+
label: The label to add
|
|
2220
|
+
prefix: (optional) The prefix of the label. Default is "global"
|
|
2221
|
+
|
|
2222
|
+
Returns:
|
|
2223
|
+
The created label object
|
|
2224
|
+
|
|
2225
|
+
Raises:
|
|
2226
|
+
HTTPError: If the API call fails
|
|
2227
|
+
ValueError: If the label is invalid
|
|
2228
|
+
"""
|
|
2229
|
+
if not label:
|
|
2230
|
+
raise ValueError("Label cannot be empty")
|
|
2231
|
+
|
|
2232
|
+
endpoint = self.get_endpoint("custom_content_labels", id=custom_content_id)
|
|
2233
|
+
|
|
2234
|
+
data = {"name": label, "prefix": prefix}
|
|
2235
|
+
|
|
2236
|
+
try:
|
|
2237
|
+
return self.post(endpoint, data=data)
|
|
2238
|
+
except Exception as e:
|
|
2239
|
+
log.error(f"Failed to add label '{label}' to custom content {custom_content_id}: {e}")
|
|
2240
|
+
raise
|
|
2241
|
+
|
|
2242
|
+
def delete_custom_content_label(self, custom_content_id: str, label: str, prefix: str = "global") -> bool:
|
|
2243
|
+
"""
|
|
2244
|
+
Delete a label from custom content.
|
|
2245
|
+
|
|
2246
|
+
Args:
|
|
2247
|
+
custom_content_id: The ID of the custom content
|
|
2248
|
+
label: The label to delete
|
|
2249
|
+
prefix: (optional) The prefix of the label. Default is "global"
|
|
2250
|
+
|
|
2251
|
+
Returns:
|
|
2252
|
+
True if the label was successfully deleted, False otherwise
|
|
2253
|
+
|
|
2254
|
+
Raises:
|
|
2255
|
+
HTTPError: If the API call fails
|
|
2256
|
+
ValueError: If the label is invalid
|
|
2257
|
+
"""
|
|
2258
|
+
if not label:
|
|
2259
|
+
raise ValueError("Label cannot be empty")
|
|
2260
|
+
|
|
2261
|
+
endpoint = self.get_endpoint("custom_content_labels", id=custom_content_id)
|
|
2262
|
+
params = {"name": label, "prefix": prefix}
|
|
2263
|
+
|
|
2264
|
+
try:
|
|
2265
|
+
self.delete(endpoint, params=params)
|
|
2266
|
+
return True
|
|
2267
|
+
except Exception as e:
|
|
2268
|
+
log.error(f"Failed to delete label '{label}' from custom content {custom_content_id}: {e}")
|
|
2269
|
+
raise
|
|
2270
|
+
|
|
2271
|
+
def get_custom_content_labels(
|
|
2272
|
+
self,
|
|
2273
|
+
custom_content_id: str,
|
|
2274
|
+
prefix: Optional[str] = None,
|
|
2275
|
+
cursor: Optional[str] = None,
|
|
2276
|
+
sort: Optional[str] = None,
|
|
2277
|
+
limit: int = 25,
|
|
2278
|
+
) -> List[Dict[str, Any]]:
|
|
2279
|
+
"""
|
|
2280
|
+
Returns all labels for custom content.
|
|
2281
|
+
|
|
2282
|
+
Args:
|
|
2283
|
+
custom_content_id: The ID of the custom content
|
|
2284
|
+
prefix: (optional) Filter the results to labels with a specific prefix
|
|
2285
|
+
cursor: (optional) Cursor for pagination
|
|
2286
|
+
sort: (optional) Sort order for the results. Valid values: 'name', '-name'
|
|
2287
|
+
limit: (optional) Maximum number of labels to return per request. Default: 25
|
|
2288
|
+
|
|
2289
|
+
Returns:
|
|
2290
|
+
List of label objects
|
|
2291
|
+
|
|
2292
|
+
Raises:
|
|
2293
|
+
HTTPError: If the API call fails
|
|
2294
|
+
"""
|
|
2295
|
+
endpoint = self.get_endpoint("custom_content_labels", id=custom_content_id)
|
|
2296
|
+
params = {"limit": limit}
|
|
2297
|
+
|
|
2298
|
+
if prefix:
|
|
2299
|
+
params["prefix"] = prefix
|
|
2300
|
+
|
|
2301
|
+
if cursor:
|
|
2302
|
+
params["cursor"] = cursor
|
|
2303
|
+
|
|
2304
|
+
if sort:
|
|
2305
|
+
if sort not in ("name", "-name"):
|
|
2306
|
+
raise ValueError("Sort must be one of 'name', '-name'")
|
|
2307
|
+
params["sort"] = sort
|
|
2308
|
+
|
|
2309
|
+
try:
|
|
2310
|
+
return list(self._get_paged(endpoint, params=params))
|
|
2311
|
+
except Exception as e:
|
|
2312
|
+
log.error(f"Failed to retrieve labels for custom content {custom_content_id}: {e}")
|
|
2313
|
+
raise
|
|
2314
|
+
|
|
2315
|
+
def create_custom_content_property(self, custom_content_id: str, key: str, value: Any) -> Dict[str, Any]:
|
|
2316
|
+
"""
|
|
2317
|
+
Creates a new property for custom content.
|
|
2318
|
+
|
|
2319
|
+
Args:
|
|
2320
|
+
custom_content_id: The ID of the custom content
|
|
2321
|
+
key: The key of the property to create. Must only contain alphanumeric
|
|
2322
|
+
characters, periods, and hyphens
|
|
2323
|
+
value: The value of the property. Can be any JSON-serializable value
|
|
2324
|
+
|
|
2325
|
+
Returns:
|
|
2326
|
+
The created property object
|
|
2327
|
+
|
|
2328
|
+
Raises:
|
|
2329
|
+
HTTPError: If the API call fails
|
|
2330
|
+
ValueError: If the key has invalid characters
|
|
2331
|
+
"""
|
|
2332
|
+
# Validate key format
|
|
2333
|
+
if not re.match(r"^[a-zA-Z0-9.\-]+$", key):
|
|
2334
|
+
raise ValueError("Property key must only contain alphanumeric characters, periods, and hyphens.")
|
|
2335
|
+
|
|
2336
|
+
endpoint = self.get_endpoint("custom_content_properties", id=custom_content_id)
|
|
2337
|
+
|
|
2338
|
+
data = {"key": key, "value": value}
|
|
2339
|
+
|
|
2340
|
+
try:
|
|
2341
|
+
return self.post(endpoint, data=data)
|
|
2342
|
+
except Exception as e:
|
|
2343
|
+
log.error(f"Failed to create property {key} for custom content {custom_content_id}: {e}")
|
|
2344
|
+
raise
|
|
2345
|
+
|
|
2346
|
+
def update_custom_content_property(
|
|
2347
|
+
self, custom_content_id: str, key: str, value: Any, version_number: int, version_message: str = ""
|
|
2348
|
+
) -> Dict[str, Any]:
|
|
2349
|
+
"""
|
|
2350
|
+
Updates an existing property for custom content.
|
|
2351
|
+
|
|
2352
|
+
Args:
|
|
2353
|
+
custom_content_id: The ID of the custom content
|
|
2354
|
+
key: The key of the property to update
|
|
2355
|
+
value: The new value of the property. Can be any JSON-serializable value
|
|
2356
|
+
version_number: The version number for concurrency control
|
|
2357
|
+
version_message: (optional) A message describing the change
|
|
2358
|
+
|
|
2359
|
+
Returns:
|
|
2360
|
+
The updated property object
|
|
2361
|
+
|
|
2362
|
+
Raises:
|
|
2363
|
+
HTTPError: If the API call fails
|
|
2364
|
+
"""
|
|
2365
|
+
endpoint = self.get_endpoint("custom_content_property_by_key", id=custom_content_id, key=key)
|
|
2366
|
+
|
|
2367
|
+
data = {
|
|
2368
|
+
"key": key,
|
|
2369
|
+
"value": value,
|
|
2370
|
+
"version": {"number": version_number, "message": version_message},
|
|
2371
|
+
}
|
|
2372
|
+
|
|
2373
|
+
try:
|
|
2374
|
+
return self.put(endpoint, data=data)
|
|
2375
|
+
except Exception as e:
|
|
2376
|
+
log.error(f"Failed to update property {key} for custom content {custom_content_id}: {e}")
|
|
2377
|
+
raise
|
|
2378
|
+
|
|
2379
|
+
def delete_custom_content_property(self, custom_content_id: str, key: str) -> bool:
|
|
2380
|
+
"""
|
|
2381
|
+
Deletes a property from custom content.
|
|
2382
|
+
|
|
2383
|
+
Args:
|
|
2384
|
+
custom_content_id: The ID of the custom content
|
|
2385
|
+
key: The key of the property to delete
|
|
2386
|
+
|
|
2387
|
+
Returns:
|
|
2388
|
+
True if the property was successfully deleted, False otherwise
|
|
2389
|
+
|
|
2390
|
+
Raises:
|
|
2391
|
+
HTTPError: If the API call fails
|
|
2392
|
+
"""
|
|
2393
|
+
endpoint = self.get_endpoint("custom_content_property_by_key", id=custom_content_id, key=key)
|
|
2394
|
+
|
|
2395
|
+
try:
|
|
2396
|
+
self.delete(endpoint)
|
|
2397
|
+
return True
|
|
2398
|
+
except Exception as e:
|
|
2399
|
+
log.error(f"Failed to delete property {key} for custom content {custom_content_id}: {e}")
|
|
2400
|
+
raise
|
|
2401
|
+
|
|
2402
|
+
def update_custom_content(
|
|
2403
|
+
self,
|
|
2404
|
+
custom_content_id: str,
|
|
2405
|
+
type: str,
|
|
2406
|
+
title: str,
|
|
2407
|
+
body: str,
|
|
2408
|
+
status: str,
|
|
2409
|
+
version_number: int,
|
|
2410
|
+
space_id: str,
|
|
2411
|
+
version_message: Optional[str] = None,
|
|
2412
|
+
) -> Dict[str, Any]:
|
|
2413
|
+
"""Update a custom-content item."""
|
|
2414
|
+
data = {
|
|
2415
|
+
"id": custom_content_id,
|
|
2416
|
+
"type": type,
|
|
2417
|
+
"title": title,
|
|
2418
|
+
"body": {"storage": {"representation": "storage", "value": body}},
|
|
2419
|
+
"status": status,
|
|
2420
|
+
"version": {"number": version_number, "message": version_message},
|
|
2421
|
+
"spaceId": space_id,
|
|
2422
|
+
}
|
|
2423
|
+
return self.put(self.get_endpoint("custom_content_by_id", id=custom_content_id), data=data)
|
|
2424
|
+
|
|
2425
|
+
def get_custom_content_properties(self, custom_content_id: str, sort: Optional[str] = None, limit: int = 25):
|
|
2426
|
+
"""Return all properties attached to a custom-content item."""
|
|
2427
|
+
return self._get_paged(
|
|
2428
|
+
self.get_endpoint("custom_content_properties", id=custom_content_id), params={"sort": sort, "limit": limit}
|
|
2429
|
+
)
|
|
2430
|
+
|
|
2431
|
+
def get_custom_content_property_by_key(self, custom_content_id: str, property_key: str):
|
|
2432
|
+
"""Return a custom-content property by key."""
|
|
2433
|
+
return self.get(self.get_endpoint("custom_content_property_by_key", id=custom_content_id, key=property_key))
|
|
2434
|
+
|
|
2435
|
+
def delete_custom_content(self, custom_content_id: str):
|
|
2436
|
+
"""Delete a custom-content item."""
|
|
2437
|
+
return self.delete(self.get_endpoint("custom_content_by_id", id=custom_content_id))
|
|
2438
|
+
|
|
2439
|
+
def get_custom_content_children(self, custom_content_id: str, cursor: Optional[str] = None, limit: int = 25):
|
|
2440
|
+
return self._get_paged(
|
|
2441
|
+
self.get_endpoint("custom_content_children", id=custom_content_id),
|
|
2442
|
+
params={"cursor": cursor, "limit": limit},
|
|
2443
|
+
)
|
|
2444
|
+
|
|
2445
|
+
def get_custom_content_ancestors(self, custom_content_id: str):
|
|
2446
|
+
response = self.get(self.get_endpoint("custom_content_ancestors", id=custom_content_id))
|
|
2447
|
+
return response.get("results", []) if response else []
|
|
2448
|
+
|
|
2449
|
+
def get_content_by_id(self, content_id: str, **kwargs) -> Dict[str, Any]:
|
|
2450
|
+
"""Deprecated v1-compatible alias for :meth:`get_page_by_id`."""
|
|
2451
|
+
warnings.warn("get_content_by_id is deprecated; use get_page_by_id", DeprecationWarning, stacklevel=2)
|
|
2452
|
+
return self.get_page_by_id(content_id, **kwargs)
|
|
2453
|
+
|
|
2454
|
+
def get_content(self, **kwargs):
|
|
2455
|
+
"""Deprecated v1-compatible alias for :meth:`get_pages`."""
|
|
2456
|
+
warnings.warn("get_content is deprecated; use get_pages", DeprecationWarning, stacklevel=2)
|
|
2457
|
+
return self.get_pages(**kwargs)
|
|
2458
|
+
|
|
2459
|
+
def get_content_property(self, content_id: str, key: str) -> Dict[str, Any]:
|
|
2460
|
+
"""Deprecated v1-compatible alias for a page property lookup."""
|
|
2461
|
+
warnings.warn(
|
|
2462
|
+
"get_content_property is deprecated; use get_page_property_by_key",
|
|
2463
|
+
DeprecationWarning,
|
|
2464
|
+
stacklevel=2,
|
|
2465
|
+
)
|
|
2466
|
+
return self.get_page_property_by_key(content_id, key)
|
|
2467
|
+
|
|
2468
|
+
def create_content(self, **kwargs):
|
|
2469
|
+
warnings.warn("create_content is deprecated; use create_page", DeprecationWarning, stacklevel=2)
|
|
2470
|
+
return self.create_page(**kwargs)
|
|
2471
|
+
|
|
2472
|
+
def update_content(self, content_id: Optional[str] = None, **kwargs):
|
|
2473
|
+
warnings.warn("update_content is deprecated; use update_page", DeprecationWarning, stacklevel=2)
|
|
2474
|
+
if content_id is not None:
|
|
2475
|
+
kwargs["page_id"] = content_id
|
|
2476
|
+
return self.update_page(**kwargs)
|
|
2477
|
+
|
|
2478
|
+
def delete_content(self, content_id: str):
|
|
2479
|
+
warnings.warn("delete_content is deprecated; use delete_page", DeprecationWarning, stacklevel=2)
|
|
2480
|
+
return self.delete_page(content_id)
|