Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method

def httpBuilder = new HTTPBuilder("https://my-company-confluence-site.com")
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 {
yield(rt)
}
}

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.

https://my-company-confluence-site.com/notificationpreferences/watch-descendants.action?pageId=162529323&atl_token=xxx

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:

https://my-company-confluence-site/rest/enterpriseNotificationsService/1.0/notifications/pageWatch/162529323/

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
TAGS
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

246 views 7 7
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you