Skip to content

Commit f81391e

Browse files
author
Dmitrij Djachkov
authored
Confluence: add another method for getting space pages + exmpl + doc (#551)
1 parent c0c50bc commit f81391e

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

atlassian/confluence.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,43 @@ def get_space(self, space_key, expand='description.plain,homepage'):
15121512
raise
15131513
return response
15141514

1515+
def get_space_content(self, space_key, depth="all", start=0, limit=500, content_type=None, expand="body.storage"):
1516+
"""
1517+
Get space content.
1518+
You can specify which type of content want to recieve, or get all content types.
1519+
Use expand to get specific content properties or page
1520+
:param space_key: The unique space key name
1521+
:param depth: OPTIONAL: all|root
1522+
Gets all space pages or only root pages
1523+
:param start: OPTIONAL: The start point of the collection to return. Default: 0.
1524+
:param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
1525+
fixed system limits. Default: 500
1526+
:param expand: OPTIONAL: by default expands page body in confluence storage format.
1527+
See atlassian documentation for more information.
1528+
:return: Returns the space along with its ID
1529+
"""
1530+
1531+
content_type = "{}".format("/" + content_type if content_type else "")
1532+
url = 'rest/api/space/{space_key}/content{content_type}'.format(space_key=space_key, content_type=content_type)
1533+
params = {
1534+
"depth": depth,
1535+
"start": start,
1536+
"limit": limit,
1537+
}
1538+
if expand:
1539+
params["expand"] = expand
1540+
try:
1541+
response = self.get(url, params=params)
1542+
except HTTPError as e:
1543+
if e.response.status_code == 404:
1544+
# Raise ApiError as the documented reason is ambiguous
1545+
raise ApiError(
1546+
"There is no space with the given key, "
1547+
"or the calling user does not have permission to view the space",
1548+
reason=e)
1549+
raise
1550+
return response
1551+
15151552
def get_home_page_of_space(self, space_key):
15161553
"""
15171554
Get information about a space through space key

docs/confluence.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ Get spaces info
162162
# Get information about a space through space key
163163
confluence.get_space(space_key, expand='description.plain,homepage')
164164
165+
# Get space content (configuring by the expand property)
166+
confluence.get_space_content(space_key, depth="all", start=0, limit=500, content_type=None, expand="body.storage")
167+
165168
# Get Space permissions set based on json-rpc call
166169
confluence.get_space_permissions(space_key)
167170
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# coding=utf-8
2+
from atlassian import Confluence
3+
import logging
4+
from pprint import pprint
5+
6+
7+
CONFLUENCE_URL = "http://conlfuence.example.com"
8+
CONFLUENCE_LOGIN = "gonchik.tsymzhitov"
9+
CONFLUENCE_PASSWORD = "************"
10+
11+
logging.basicConfig(level=logging.DEBUG)
12+
13+
confluence = Confluence(
14+
url=CONFLUENCE_URL,
15+
username=CONFLUENCE_LOGIN,
16+
password=CONFLUENCE_PASSWORD,
17+
timeout=180)
18+
19+
pgs = confluence.get_space_content("SPACE")
20+
pprint(pgs["page"]["results"])

0 commit comments

Comments
 (0)