Any API to check if current user is watching a space
Asked by Devinder Kumar:

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


Answers:
author: Stephen Deutsch
body: 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()) &gt; 4300 )  #set ( $user = $userAccessor.getUserByName($req.getRemoteUser()) )#else  #set ( $user = $userAccessor.getUser($req.getRemoteUser()) )#end#foreach( $confluenceSpace in $spaceManager.getAllSpaces() )  #if ( $confluenceSpace.isGlobal() )    #if ( $notificationManager.getNotificationByUserAndSpace($user, $confluenceSpace.key) )      #set ( $isWatching = '&lt;span class="aui-lozenge aui-lozenge-success"&gt;Watching&lt;/span&gt;' )    #else      #set ( $isWatching = '&lt;span class="aui-lozenge"&gt;Not Watching&lt;/span&gt;' )    #end    &lt;p&gt;&lt;a href="$confluenceSpace.homePage.urlPath"&gt;$confluenceSpace.name&lt;/a&gt; ($confluenceSpace.key) - $isWatching &lt;/p&gt;  #end#end
```


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

<https://docs.atlassian.com/confluence/latest/com/atlassian/confluence/mail/notification/NotificationManager.html>

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:

[https://bitbucket.org/stephendeutsch/confluence-user-macros/src/39c3a025dacc6b45abc0105f0b7a21a7375690b4/bulk%20remove%20watchers/remove%20watches%20for%20user.vm?at=master\&fileviewer=file-view-default](https://bitbucket.org/stephendeutsch/confluence-user-macros/src/39c3a025dacc6b45abc0105f0b7a21a7375690b4/bulk%20remove%20watchers/remove%20watches%20for%20user.vm?at=master&fileviewer=file-view-default)

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

<https://developer.atlassian.com/confdev/confluence-rest-api/confluence-xml-rpc-and-soap-apis/remote-confluence-methods>

Specifically:

/rpc/json-rpc/confluenceservice-v1/getWatchersForSpace

comments: author: Devinder Kumar
body: 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?


author: Artur J
body: Hi Devinder,

Using [User Macro](https://confluence.atlassian.com/doc/writing-user-macros-4485.html) you can check this [Documentation](https://developer.atlassian.com/confdev/development-resources/confluence-architecture/confluence-internals/velocity-template-overview/confluence-objects-accessible-from-velocity) 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](https://marketplace.atlassian.com/plugins/com.go2group.plugins.confluence-ga/server/overview) as well.