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

Ability to set space permissions via REST API

    XMLWordPrintable

Details

    • 911
    • 28
    • 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

      Note : The below mentioned workaround is not applicable for all version after Confluence v5.5 as the XML-RPC and SOAP APIs are deprecated since Confluence 5.5 as per Remote Confluence methods – Permissions

      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

              Unassigned Unassigned
              a7d8cf71caed Pavel Chernikov
              Votes:
              504 Vote for this issue
              Watchers:
              308 Start watching this issue

              Dates

                Created:
                Updated: