How to add all Users of a Group as Watchers of a Page or Blog

Still need help?

The Atlassian Community is here for you.

Ask the community


Purpose

The ability to add an entire group as a watcher of specific content is not available in Confluence at the moment. Please check the following feature requests for more details:

With that in mind, you need to add the users one by one, which is a task that can take hours to complete if the list of users is large. As we can see on the requests, customers would like to have the option of adding a group instead of individual users in those situations.

Even though there are some plugins that add this functionality, it may not be reasonable to acquire the add-on if you are only looking to this specific feature.

Solution

If your sole purpose is to add multiple users as watchers of a page or blog post, you can achieve that through the remote APIs. We will cover the options available depending on your Confluence version in the next sections:

The scripts below are provided as is and Atlassian do not offer support for them. Make sure to test them in your staging instance before running on production.


For Confluence 5.10.0 and above

On newer versions of Confluence, we can rely on the REST API to achieve that goal. To do so, please follow the steps below:

  1. Download the Python script that will be used here: rest-add-watchers-script.py
  2. Edit the script you just downloaded and change the following lines only:
  3. BASE_URL: This should be set to the server base URL of Confluence, as in the example (make sure to include the context path, if it exists):

    BASE_URL = "https://mycompany.com"
  4. USER: Set this variable to the username that will connect to Confluence through the REST API. It can be your normal user account.

  5. PASSWD: Set this one to your password used to authenticate with the user above. Unfortunately, Confluence only supports basic auth for REST, so we need to explicitly pass the password.

  6. GROUP_NAME: Set this variable to the group name that holds the users that will be added as watchers. If the group name has spaces, replace the space character with %20 (e.g "this group" should look like "this%20group").

  7. CONTENTID: this variable must hold the content ID of the page or blog that we would like to add watchers. To find the ID, visit the page/blog and go to '... > Page Information'. Once you are in that page, you should see the CONTENT ID in the URL field of your browser as pageId=.

  8. Execute the script as follows:

    python rest-add-watchers-script.py
  9. Once the message "Finished adding users as watchers!" is printed, check the Manage Watchers section of the page in Confluence to see if the users are indeed there.

(info) This script is compatible with both Python 2 and 3 versions.

For Confluence 5.9.14 and below

On those versions, we need to use the deprecated XML RPC APIs as the /group endpoint was not yet available through REST API. Also, the XML RPC API does not include a similar method to list group members, so we need to fetch them from the database. Please follow the steps below to run the script correctly:

  1. Run the following query on your database to fetch all members of a specific group:

    SELECT user_name
    FROM cwd_user
    WHERE id IN (SELECT m.child_user_id FROM cwd_membership AS m
             JOIN cwd_group AS g ON m.parent_id = g.id
             WHERE g.group_name = '<GROUP-NAME-HERE>');
  2. Copy the output, making sure to exclude the headers (column name), and save it on a file called userlist.txt . The file should look like this:

    admin
    anotheradmin
    user
    usertwo
    jdoe
  3. Download the XML RPC Python script here: xmlrpc-add-watchers-script.py
  4. Put the script in the same directory as the file userlist.txt that we just created.
  5. Edit the script you just downloaded and change the following lines only:
  6. BASE_URL: This should be set to the server base URL of the server, as in the example (make sure to include the context path, if it exists):

    BASE_URL = "https://mycompany.com"
  7. USER: Set this variable to the username that will connect to Confluence through the REST API. It can be your normal user account.

  8. PASSWD: Set this one to your password used to authenticate with the user above. Unfortunately, Confluence only supports basic auth for REST, so we need to explicitly pass the password.

  9. CONTENTID: this variable must hold the content ID of the page or blog that we would like to add watchers. To find the ID, visit the page/blog and go to '... > Page Information'. Once you are in that page, you should see the CONTENT ID in the URL field of your browser as pageId=.

  10. Execute the script as follows:

    python xmlrpc-add-watchers-script.py
  11. Once the message "Finished adding users as watchers!" is printed, check the Manage Watchers section of the page in Confluence to see if the users are indeed there.

(info) This script is compatible with Python 3 only. Refer to the comments inside the code on how to make it Python 2 compatible if needed.


Last modified on Apr 27, 2021

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.