Skip to content

Commit 15a9fda

Browse files
2shshRushan Kashshapov
and
Rushan Kashshapov
authored
[Confluence] Add methods for templates. Experimental API (atlassian-api#572)
* [Confluence] Add new methods. Get user template by id and get all templates from space * [Confluence] Update method docstrings Co-authored-by: Rushan Kashshapov <r.kashshapov@tinkoff.ru>
1 parent 3820176 commit 15a9fda

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

atlassian/confluence.py

+56
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,62 @@ def move_page(self, space_key, page_id, target_id=None, target_title=None, posit
632632
params["position"] = position
633633
return self.post(url, params=params, headers=self.no_check_headers)
634634

635+
def get_template_by_id(self, template_id):
636+
"""
637+
Get user template by id. Experimental API
638+
Use case is get template body and create page from that
639+
"""
640+
url = 'rest/experimental/template/{template_id}'.format(template_id=template_id)
641+
642+
try:
643+
response = self.get(url)
644+
except HTTPError as e:
645+
if e.response.status_code == 403:
646+
# Raise ApiError as the documented reason is ambiguous
647+
raise ApiError(
648+
"There is no content with the given id, "
649+
"or the calling user does not have permission to view the content",
650+
reason=e)
651+
652+
raise
653+
654+
return response
655+
656+
def get_all_templates_from_space(self, space, start=0, limit=20, expand=None):
657+
"""
658+
https://docs.atlassian.com/atlassian-confluence/1000.73.0/com/atlassian/confluence/plugins/restapi/resources/TemplateResource.html
659+
Get all users templates from space. Experimental API
660+
:param space: Space Key
661+
:param start: OPTIONAL: The start point of the collection to return. Default: None (0).
662+
:param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
663+
fixed system limits. Default: 20
664+
:param expand: OPTIONAL: expand e.g. body
665+
666+
"""
667+
url = 'rest/experimental/template/page'
668+
params = {}
669+
if space:
670+
params['spaceKey'] = space
671+
if start:
672+
params['start'] = start
673+
if limit:
674+
params['limit'] = limit
675+
if expand:
676+
params['expand'] = expand
677+
678+
try:
679+
response = self.get(url, params=params)
680+
except HTTPError as e:
681+
if e.response.status_code == 403:
682+
raise ApiPermissionError(
683+
"The calling user does not have permission to view the content",
684+
reason=e)
685+
686+
raise
687+
688+
return response.get('results')
689+
690+
635691
def get_all_spaces(self, start=0, limit=500, expand=None):
636692
"""
637693
Get all spaces with provided limit

0 commit comments

Comments
 (0)