The Adaptavist Group LogoDocumentation

Run Scripts as Other Users

You can use HAPI to run scripts as other users or as an anonymous user!

Note: CQL and HAPI

Where there are CQL statements in example scripts, you can use any CQL statements to modify the scripts to work for you. Visit the CQL Guide for help with CQL.

Run script as another user

The script that follows adds a label to every page in a space as another user.

  1. To run a script as another user, use a script like this in the Script Console:
    Users.runAs("user3") {
        Pages.search("space = DS").each { page ->
            page.addLabels("2023")
        }
    }
    After running the script, the pages in the space will have 2023 added by user3.
Customize the above script
  1. You can customize this script by updating the username and label.
    Users.runAs("USERNAME") {
        Pages.search("space = DS").each { page ->
            page.addLabels("LABEL")
        }
    }

For tips on adding labels, visit Work with Labels.

Run script as anonymous user

To run this script, turn on anonymous access. To anonymously run a script to return all pages that have anonymous access, use a script like this in the Script Console:

  1. Use a script like this in the Script Console to anonymously run a script to return all pages that have anonymous access.
    Users.runAnonymously {
        Pages.search("type = page")
    }

    After running this script, you will have a list of pages that have anonymous access:

  2. To customize this script, you can change the content type ( blog, page, space, etc.) to suit your needs.
    Users.runAnonymously {
        Pages.search("type = CONTENT")
    }
Warning: A note about permissions

If you use a script that searches pages by ID, you can run the Pages.getById method even when global anonymous access is disabled.

Search documentation

Start typing to search the docs.