Get labels for a specific Confluence page via API

MichaelM April 14, 2013

Going over the Confluence API documention (XML-RPC specifically) there doesn't seem to be a way to get a list of labels that might be applied to a specific page. I see every other API call in regards to label managment but not on the page level.

What am I not seeing here?

thanks!

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 15, 2013

You should use this method:

  • Vector getLabelsById(String token, long objectId) - Returns all labels for the given ContentEntityObject ID

For the "objectId", supply the ID of the page.

(Reference: https://developer.atlassian.com/display/CONFDEV/Remote+Confluence+Methods#RemoteConfluenceMethods-Labels)

Bastian Kippelt
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 24, 2013

Is there a similar Method for none Remote API?

Bastian Kippelt
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 24, 2013

Is there a similar Method for none Remote API? Yes :-)

Page confPage = this.pageManager.getPage(Long.parseLong(key));
List<Label> labels = confPage .getLabels();

Khuong Vu November 29, 2017

I have adopted your suggestion, and made it work in Confluence 6.1 as a User Macro as shown below.  I put this macro at the top of the page to promote the use of labels in my organization.

## Macro title: Show Labels of a Given Page
## Macro has a body: N
## Body processing: Rendered
## Output: Selected output option
##
## Developed by: an unknown. Half of the code below was taken from a user macro, called label-mgmt., on dev server; I'm not sure where Apeksha K. found it
## Date created: 28/11/2017
## Installed by: Khuong Vu
## @noparams
## This block was taken from a user macro, called label-mgmt., on libdev3; I'm not sure where Apeksha K. found it
#set ( $containerManagerClass = $content.class.forName('com.atlassian.spring.container.ContainerManager') )
#set ( $getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null) )
#set ( $containerManager = $getInstanceMethod.invoke(null,null) )
#set ( $containerContext = $containerManager.containerContext )
#set ( $pageManager = $containerContext.getComponent('pageManager') )
#set ( $contentEntityManager = $containerContext.getComponent('contentEntityManager') )

#set ( $spaceKey = $space.key )
#set ( $pageId = $content.getIdAsString() )
## Please note that for the next 2 lines to work variable long cannot be instantiated by setting it to 0
#set ( $long = $generalUtil.getSystemStartupTime() )
#set ( $pageIdLong = $long.parseLong($pageId) )
#set ( $pageIdLongAS = $pageIdLong.toString() )
## This div block was taken from page-source view of a page in L-Space, where the li element has been replaced with ours
<div id="labels-section" class="pageSection group">
<div class="labels-section-content content-column" entityid="22751371" entitytype="page">
<div class="labels-content">

<ul class="label-list label-list-right has-pen">
#set ( $labelPage = $contentEntityManager.getById($pageIdLong) )
#foreach ( $labels in $labelPage.getLabels() )
#set ( $labelString = $labels.toString() )

<li class="aui-label " data-label-id="13008901"><a class="aui-label-split-main" href="/label/$spaceKey/$labelString" rel="tag">$labelString</a></li>
#end
<li class="labels-edit-container">
<a href="#" class="show-labels-editor" title="Edit Labels">
<span class="aui-icon aui-icon-small aui-iconfont-edit-small">Edit Labels</span>
</a>
</li>
</ul>

</div>
</div>
</div>

TAGS
AUG Leaders

Atlassian Community Events