Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Confluence Server Java API for getting watchers of a page?

br0wse September 19, 2018

I want to find a confluence server java api for getting watchers of a page.

But I can't find anything useful for doing this in https://docs.atlassian.com/atlassian-confluence/6.6.0/.

And alse there is no this api in confluence server rest api.

And I don't want use this link:${base_url}/json/listwatchers.action?pageId=${page_id}.

So is there a java api for getting watchers of a page?

Thanks in advanced.

1 answer

0 votes
Prashant Mali
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.
September 19, 2018

Hi @br0wse ,

Welcome to Atlassian Community!

You can get list of watchers for particular page using below rest api

<your confluence url>/json/listwatchers.action?pageId=<pageId>

Please try and confirm.

Thanks,

Prashant

br0wse September 20, 2018

Hi @Prashant Mali,

 

I know this rest api "<your confluence url>/json/listwatchers.action?pageId=<pageId>".

But when I use groovy httpbuidler,it always return null. My code is just like below:

def a=new HTTPBuilder("http://example.confluence.com:8090")
a.setHeaders([Authorization:"Basic ${"admin:admin".bytes.encodeBase64().toString()}",Accept:"application/json"])
//a.auth.basic 'admin','admin'
def b=a.get(path:"/json/listwatchers.action?pageId=2261002")

Could you please show me a example code?

Prashant Mali
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.
September 20, 2018

Hi @br0wse ,

Please have a look on below code. and try to get business logic from the same.

Set<ConfluenceUser> users = new HashSet<>();
 
// Get users from page watches
for (Notification notification : notificationManager.getNotificationsByContent(pageCeo)) {
    users.add(notification.getReceiver());
}

// Get users from space watches
for (Notification notification : notificationManager.getNotificationsBySpaceAndType(space, null)) {
    users.add(notification.getReceiver());
}

 Thanks,

Prashant

Prashant Mali
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.
September 20, 2018

Hi @br0wse ,

When I try API on my confluence page, getting correct output for the same.

we need to check groovy code.

image.png

 

Thanks,

Prashant

br0wse September 20, 2018

Hi @Prashant Mali,

I can get the api from curl and python,but I am new to Groovy.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events