How to add labels to the current page in a self-written user makro?

I searched a lot, but nothing worked. There are downloadable Makros who manage to add labels you type into them, but as they´re not open source I can´t get behind that magic, which of course works, as I tested. Using the REST Api didn´t work, using the labelManager and labelUtil also lead to nothing. But I am sure there´s a way to use the labelManager to do so, maybe with the function "addLabel(Labelable content, Label label)" but there I don´t know with what to fill the parameters, beacause I have no access to the current page and I don´t know how to create a new label.

Thanks for your help

1 answer

0 vote
Stephen Deutsch Community Champion Mar 27, 2015

I've tried adding labels via user macro, and the easiest thing I've found is to use ajax and let Confluence take care of the rest of the details.  Here is a simple user macro that adds a label based on what you type into a text field.

## @noparams
var addLabel = function(label) { + "/json/addlabelactivity.action", {"entityIdString": "$", "labelString": label, "atl_token": jQuery("#atlassian-token").attr("content") }, function() {
<form class="aui" onsubmit="return false;">
  <input id="label-to-add" class="text">
  <button class="aui-button aui-button-subtle" onclick="addLabel(jQuery('#label-to-add').val());">
    <span class="aui-icon aui-icon-small aui-iconfont-add">Add </span>

thank you very much it works fine for me :)

This is great!  Thanks for posting.  

Can I use a field in my macro example "Document Number" that populates the label for the page.  I'm pretty new to this so I'm no sure how to do that yet.  

I currently have my users populating a number of fields in a macro. I wanted to use the "Document Number" field to update the label of the page. 

what should I add to do this?

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

372 views 20 10
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you