Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Scriptrunner Confluence Macro - Calling REST API to Watch Page and Descendants

I'm trying to create a macro in Scriptrunner for Confluence Server/DataCenter, version 7.4.7. The macro would add a link that, when clicked, would add the current user as a watcher to the current page AND its descendants. 

To do this, I am trying to make an API call to Atlassian's REST API.

The following code works with the /rest/api/accessmode API, but when I call /rest/api/user/watch/content/{page-id}, the macro fails.


import com.atlassian.confluence.xhtml.api.XhtmlContent
import com.atlassian.sal.api.component.ComponentLocator
import groovy.xml.MarkupBuilder

def httpBuilder = new HTTPBuilder("")
def xhtmlContent = ComponentLocator.getComponent(XhtmlContent)

def rt = httpBuilder.request(Method.GET, ContentType.JSON) {
uri.path = "/rest/api/user/watch/content/162529323"

def writer = new StringWriter()
def builder = new MarkupBuilder(writer)

builder.div {
p {

xhtmlContent.convertStorageToView(writer.toString(), context)

I'm modelling this macro after another macro - Watchlinks - that is being retired.

That macro is a link with the following URL. But when I try adding a link with that URL, it successfully watches the page and descendants, but doesn't allow me to un-watch the page. The link also has a couple of data tags, so there's surely some Javascript going on there too.

I also checked the normal Confluence watch button and the watch descendants checkbox. Those call the following API, which is not shown in the REST API docs:


My questions are:

1) Is calling the REST API the best way to handle this, or is there a better option?

2) Am I calling the right REST API?

3) Why is the call to /rest/api/user/watch/content/{page-id} failing / causing the macro not to load?

Any help is much appreciated.

0 answers

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events