Uploaded image for project: 'Confluence Server and Data Center'
  1. Confluence Server and Data Center
  2. CONFSERVER-44329

Ability to set space permissions via REST API

    XMLWordPrintable

    Details

    • UIS:
      575
    • Support reference count:
      28
    • Feedback Policy:
      We collect Confluence feedback from various sources, and we evaluate what we've collected when planning our product roadmap. To understand how this piece of feedback will be reviewed, see our Implementation of New Features Policy.

      Description

      NOTE: This suggestion is for Confluence Server. Using Confluence Cloud? See the corresponding suggestion.

      We have dozens of spaces and need ability to programmatically update space permissions. Otherwise it's a really wasteful manual effort.

      Workaround

      While this is not possible through the REST API, Confluence users and administrators can still use the legacy RPC API to administrate Space Permissions.
      The following document describes the JSON-RPC API: Confluence JSON-RPC APIs.
      The following document highlights all the methods available in the RPC API to manage Space Permissions: Remote Confluence methods – Permissions.
      The following link will send you to a mapping about each space permission string and their related permission: Remote Confluence methods – Space Permissions.

      Below are a few examples of how to use this API to perform Space Permissions operations.
      This is using Shell Script just as an example, since it can be ported to your preferred coding language.
      In these examples, the jq library is used to filter and format the raw output.

      Get all permissions associated to a Space
      #######
      # Attributes to set
      #######
      ADMIN_USRNAME=<username to perform basic authentication>
      ADMIN_USRPWD=<password to perform basic authentication>
      CONFLUENCE_BASE_URL=<Confluence Base URL>
      SPACE_KEY=<Target Space Key>
      
      ####### Run the API method
      API_METHOD=getSpacePermissionSets
      curl --user $ADMIN_USRNAME:$ADMIN_USRPWD -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{ "jsonrpc" : "2.0", "method" : "'${API_METHOD}'", "params" : ["'${SPACE_KEY}'"], "id": 7 }' ${CONFLUENCE_BASE_URL}/rpc/json-rpc/confluenceservice-v2?os_authType=basic 2>/dev/null | jq -r '.result[]'
      

      Running example and output excerpt:

      Get users and groups assigned as Space Administrators to a Space
      #######
      # Attributes to set
      #######
      ADMIN_USRNAME=<username to perform basic authentication>
      ADMIN_USRPWD=<password to perform basic authentication>
      CONFLUENCE_BASE_URL=<Confluence Base URL>
      SPACE_KEY=<Target Space Key>
      PERMISSION_TYPE=<permission type string>
      
      ####### Run the API method
      API_METHOD=getSpacePermissionSet
      curl --user $ADMIN_USRNAME:$ADMIN_USRPWD -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{ "jsonrpc" : "2.0", "method" : "'${API_METHOD}'", "params" : ["'${SPACE_KEY}'", "'${PERMISSION_TYPE}'"], "id": 7 }' ${CONFLUENCE_BASE_URL}/rpc/json-rpc/confluenceservice-v2?os_authType=basic 2>/dev/null | jq -r '.result[]'
      

      Running example and output excerpt:

      Set Add Page permission to a specific group in a Space
      #######
      # Attributes to set
      #######
      ADMIN_USRNAME=<username to perform basic authentication>
      ADMIN_USRPWD=<password to perform basic authentication>
      CONFLUENCE_BASE_URL=<Confluence Base URL>
      SPACE_KEY=<Target Space Key>
      GROUP_NAME=<Target Group Name>
      PERMISSION_TYPE=EDITSPACE
      
      ####### Run the API method
      API_METHOD=addPermissionToSpace
      curl --user $ADMIN_USRNAME:$ADMIN_USRPWD -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{ "jsonrpc" : "2.0", "method" : "'${API_METHOD}'", "params" : ["'${PERMISSION_TYPE}'", "'${GROUP_NAME}'", "'${SPACE_KEY}'"], "id": 7 }' ${CONFLUENCE_BASE_URL}/rpc/json-rpc/confluenceservice-v2?os_authType=basic 2>/dev/null | jq -r '.'
      

      Running example and output excerpt:

      Set Delete Attachments to a specific user in a Space
      #######
      # Attributes to set
      #######
      ADMIN_USRNAME=<username to perform basic authentication>
      ADMIN_USRPWD=<password to perform basic authentication>
      CONFLUENCE_BASE_URL=<Confluence Base URL>
      SPACE_KEY=<Target Space Key>
      USER_NAME=<Target Username>
      PERMISSION_TYPE=<permission type string>
      
      ####### Run the API method
      API_METHOD=addPermissionToSpace
      curl --user $ADMIN_USRNAME:$ADMIN_USRPWD -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{ "jsonrpc" : "2.0", "method" : "'${API_METHOD}'", "params" : ["'${PERMISSION_TYPE}'", "'${USER_NAME}'", "'${SPACE_KEY}'"], "id": 7 }' ${CONFLUENCE_BASE_URL}/rpc/json-rpc/confluenceservice-v2?os_authType=basic 2>/dev/null | jq -r '.'
      

      Running example and output excerpt:

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              pchernik Pavel Chernikov
              Votes:
              269 Vote for this issue
              Watchers:
              177 Start watching this issue

                Dates

                Created:
                Updated: