Any API to check if current user is watching a space

We have got multiple spaces in our environment and we are looking for single page where we show current users subscription.

Do we have any API using which we can check if current user is watching the space or not.

We are using v5.8.16

3 answers

0 votes

Hi Devinder,

Using User Macro you can check this Documentation for knowledge, some examples, $action.remoteUser.fullName

{run-now} $current_user_name{run-now}

#set( $username = "$req.getRemoteUser()" )

There is Google Analytics Plugin for Confuence as well.

It depends which API you are talking about.  For the internal Java API, there is the notificationManager:

I wrote a user macro using this that show all watches for a particular user and lets administrators see/change the watches for other users:

If you're talking about the remote API, it is currently only available in the XML/JSON RPC API:



Sorry if i was not clear with my problem statement. I am looking for API using which i can find if user is watching a specified space or not. e.g. If we have 3 space (say with Key S1, S2, S3), i want to make a call (something like /isUserWatching/SpaceKey=S1) and expect a return value true/false from api (based on if user is watching S1 space or not). My end goal is to make a page where i could display: S1 - Watching [api would have returned true] S2 - Not Watching [api would have returned false] S1 - Watching [api would have returned true] P.S. Seems xml/json is deprecated and we are expected to use rest based api. Is there any in rest based?

Hi Devinder,

I understood what you were asking for, but unfortunately there is not any REST API that I am aware of that does what you are asking.  Although the xml/json-rpc API is deprecated, it is still very much in use until the new REST API can cover the features.

Since you are embedding it in a page, however, there seems to be no need to call an external API.  Why not just use a user macro and call the internal API?  It's a lot faster and everything loads on page load.

## @noparams
#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 ( $notificationManager = $containerContext.getComponent('notificationManager') )

#set ( $Integer = 0 )
#if ( $Integer.parseInt($generalUtil.getBuildNumber()) > 4300 )
  #set ( $user = $userAccessor.getUserByName($req.getRemoteUser()) )
  #set ( $user = $userAccessor.getUser($req.getRemoteUser()) )

#foreach( $confluenceSpace in $spaceManager.getAllSpaces() )
  #if ( $confluenceSpace.isGlobal() )
    #if ( $notificationManager.getNotificationByUserAndSpace($user, $confluenceSpace.key) )
      #set ( $isWatching = '<span class="aui-lozenge aui-lozenge-success">Watching</span>' )
      #set ( $isWatching = '<span class="aui-lozenge">Not Watching</span>' )
    <p><a href="$confluenceSpace.homePage.urlPath">$</a> ($confluenceSpace.key) - $isWatching </p>

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Dec 18, 2018 in Confluence Cloud

Happy holidays from our team to yours!

Hi Community!  2018 was filled with changes for our team, both big and small, and we've taken a lot of time to both celebrate our wins and recognize areas of improvement. One thing that we're a...

475 views 3 18
Read article

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