Skip to content

Commit 8b77cee

Browse files
committed
Add methods to retrieve page by title and get page ID using V2 API
1 parent 2fd696c commit 8b77cee

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

‎atlassian/confluence/cloud/cloud.py‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,46 @@ def get_pages(
248248
except Exception as e:
249249
log.error(f"Failed to retrieve pages: {e}")
250250
raise
251+
252+
def get_page_by_title(
253+
self, space_key: str, title: str, body_format: str = "storage", **kwargs
254+
) -> Dict[str, Any]:
255+
"""
256+
Get page by space key and title using the V2 API.
257+
Resolves the space key to space_id and queries the V2 page endpoint.
258+
Returns a dictionary with 'results' key containing matching pages
259+
to maintain backward compatibility with V1 callers.
260+
"""
261+
try:
262+
space = self.get_space_by_key(space_key)
263+
except Exception as e:
264+
log.error(f"Failed to retrieve space with key '{space_key}': {e}")
265+
return {"results": []}
266+
267+
if not space or "id" not in space:
268+
return {"results": []}
269+
270+
pages = self.get_pages(
271+
space_id=space["id"],
272+
title=title,
273+
status="current",
274+
body_format=body_format,
275+
limit=1,
276+
**kwargs,
277+
)
278+
return {"results": pages if isinstance(pages, list) else []}
279+
280+
281+
def get_page_id(self, space: str, title: str, type: str = "page") -> Optional[str]:
282+
"""
283+
Get page ID by space key and title using the V2 API.
284+
Returns the ID from the first result or None if not found.
285+
"""
286+
res = self.get_page_by_title(space, title)
287+
results = res.get("results", [])
288+
if results:
289+
return str(results[0]["id"])
290+
return None
251291

252292
def get_page_versions(
253293
self,

0 commit comments

Comments
 (0)