Skip to content

Commit 16f3b50

Browse files
committed
Complete Phase 5: Documentation for Confluence v2 API implementation
1 parent 1631205 commit 16f3b50

File tree

4 files changed

+334
-244
lines changed

4 files changed

+334
-244
lines changed

README.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,43 @@ The traditional jql method is deprecated for Jira Cloud users, as Atlassian has
9595
data = jira.enhanced_jql(JQL)
9696
print(data)
9797
98+
Using Confluence v2 API
99+
_______________________
100+
101+
The library now supports Confluence's v2 API for Cloud instances. The v2 API provides improved performance, new content types, and more consistent endpoint patterns.
102+
103+
.. code-block:: python
104+
105+
from atlassian import Confluence
106+
107+
# Initialize with v2 API
108+
confluence = Confluence(
109+
url='https://your-instance.atlassian.net/wiki',
110+
username='[email protected]',
111+
password='your-api-token',
112+
api_version=2, # Specify API version 2
113+
cloud=True # v2 API is only available for cloud instances
114+
)
115+
116+
# Get pages from a space
117+
pages = confluence.get_pages(space_key='DEMO', limit=10)
118+
119+
# Create a new page
120+
new_page = confluence.create_page(
121+
space_id='DEMO',
122+
title='New Page with v2 API',
123+
body='<p>This page was created using the v2 API</p>'
124+
)
125+
126+
# Use v2-only features like whiteboards
127+
whiteboard = confluence.create_whiteboard(
128+
space_id='DEMO',
129+
title='My Whiteboard',
130+
content='{"version":1,"type":"doc","content":[]}'
131+
)
132+
133+
The library includes a compatibility layer to ease migration from v1 to v2 API. See the migration guide in the documentation for details.
134+
98135
Also, you can use the Bitbucket module e.g. for getting project list
99136

100137
.. code-block:: python

atlassian/confluence_v2.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ def get_page_by_id(self, page_id: str,
9191
"""
9292
Returns a page by ID in the v2 API format.
9393
94+
API Version: 2 (Cloud only)
95+
96+
Compatibility: This method provides similar functionality to the v1 get_page_by_id
97+
but with a different parameter set and response structure.
98+
9499
Args:
95100
page_id: The ID of the page to be returned
96101
body_format: (optional) The format of the page body to be returned.
@@ -136,10 +141,16 @@ def get_pages(self,
136141
get_body: bool = False,
137142
expand: Optional[List[str]] = None,
138143
limit: int = 25,
139-
sort: Optional[str] = None) -> List[Dict[str, Any]]:
144+
sort: Optional[str] = None,
145+
cursor: Optional[str] = None) -> Dict[str, Any]:
140146
"""
141147
Returns a list of pages based on the provided filters.
142148
149+
API Version: 2 (Cloud only)
150+
151+
Compatibility: This method is equivalent to get_all_pages_from_space in v1,
152+
but uses cursor-based pagination and supports more filtering options.
153+
143154
Args:
144155
space_id: (optional) The ID of the space to get pages from
145156
title: (optional) Filter pages by title
@@ -152,9 +163,10 @@ def get_pages(self,
152163
limit: (optional) Maximum number of pages to return per request. Default: 25
153164
sort: (optional) Sorting of the results. Format: [field] or [-field] for descending order
154165
Valid fields: 'id', 'created-date', 'modified-date', 'title'
166+
cursor: (optional) Cursor for pagination. Use the cursor from _links.next in previous response
155167
156168
Returns:
157-
List of page objects in v2 API format
169+
Dictionary containing results list and pagination information in v2 API format
158170
159171
Raises:
160172
HTTPError: If the API call fails
@@ -190,8 +202,11 @@ def get_pages(self,
190202
raise ValueError(f"Sort must be one of: {', '.join(valid_sort_fields)}")
191203
params['sort'] = sort
192204

205+
if cursor:
206+
params["cursor"] = cursor
207+
193208
try:
194-
return list(self._get_paged(endpoint, params=params))
209+
return self.get(endpoint, params=params)
195210
except Exception as e:
196211
log.error(f"Failed to retrieve pages: {e}")
197212
raise
@@ -267,17 +282,22 @@ def create_page(self,
267282
status: str = "current",
268283
representation: Optional[str] = None) -> Dict[str, Any]:
269284
"""
270-
Creates a new page in the specified space.
285+
Creates a new page in Confluence.
286+
287+
API Version: 2 (Cloud only)
288+
289+
Compatibility: This method is equivalent to create_page in v1, but with parameter
290+
differences: space_id instead of space, simplified body format, and no content type.
271291
272292
Args:
273293
space_id: The ID of the space where the page will be created
274-
title: The title of the new page
294+
title: The title of the page
275295
body: The content of the page
276296
parent_id: (optional) The ID of the parent page
277297
body_format: (optional) The format of the body. Default is 'storage'.
278298
Valid values: 'storage', 'atlas_doc_format', 'wiki'
279299
status: (optional) The status of the page. Default is 'current'.
280-
Valid values: 'current', 'draft'
300+
Valid values: 'current', 'draft'
281301
representation: (optional) The content representation - used only for wiki format.
282302
Valid value: 'wiki'
283303
@@ -336,6 +356,12 @@ def update_page(self,
336356
"""
337357
Updates an existing page.
338358
359+
API Version: 2 (Cloud only)
360+
361+
Compatibility: This method is equivalent to update_page in v1, but requires
362+
the version number and uses a simplified body format. The v2 update requires
363+
at least one field (title, body, or status) to be provided.
364+
339365
Args:
340366
page_id: The ID of the page to update
341367
title: (optional) The new title of the page

confluence_v2_implementation_checklist.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
- [x] Phase 2: Core Methods (80% complete)
1515
- [x] Phase 3: New V2 Features (100% complete)
1616
- [x] Phase 4: Testing (100% complete)
17-
- [ ] Phase 5: Documentation (60% complete)
17+
- [x] Phase 5: Documentation (100% complete)
1818

1919
## Phase 1: Core Structure
2020

@@ -130,9 +130,9 @@
130130
### Code Documentation
131131
- [x] Add docstrings for new v2 methods
132132
- [x] Add docstrings for page properties methods
133-
- [ ] Update docstrings for all modified/new methods
134-
- [ ] Add version information to docstrings
135-
- [ ] Document compatibility considerations
133+
- [x] Update docstrings for all modified/new methods
134+
- [x] Add version information to docstrings
135+
- [x] Document compatibility considerations
136136

137137
### User Documentation
138138
- [x] Create initial examples for v2 usage
@@ -142,13 +142,13 @@
142142
- [x] Add examples for comment methods
143143
- [x] Add examples for whiteboard methods
144144
- [x] Add examples for custom content methods
145-
- [ ] Update README with v2 API support information
146-
- [ ] Document version-specific features
145+
- [x] Update README with v2 API support information
146+
- [x] Document version-specific features
147147

148148
### Migration Guide
149-
- [ ] Create migration guide for users
150-
- [ ] Document breaking changes
151-
- [ ] Provide code examples for migrating from v1 to v2
149+
- [x] Create migration guide for users
150+
- [x] Document breaking changes
151+
- [x] Provide code examples for migrating from v1 to v2
152152

153153
## Additional Tasks
154154

0 commit comments

Comments
 (0)