How to create a Confluence space

Here we will show you how to create an operation that lets your users create a new space. The operation will also store the page ID of the new spaces home page in a custom field and create a comment to inform the user about the new space. This example requires version 9.3.0 of the Issue Publisher or later.

Create the operation

On the Manage Operations page create a new Single Issue Operation. You only have to enter a name and optionally a description here.

Add the first step

The first step creates the space.

We are using the Send web request action with the Default Create Confluence Space Template here. You could also copy the default template and (for example) get the space key from a custom field instead of generating it.

{
    "key": "$!fieldHelper.getValueAsString("Space Key")",
    "name": "$issue.summary",
    "description": {
        "plain": {
            "value": "$!issue.description",
            "representation": "plain"
        }
    }
}

Add the second step

The second step stores the page ID of the new spaces home page in a custom field. You could use this in another operation (or a later step) to update the home page or create new pages under it.

We are using the $responseHelper variable to extract the page ID from the response of the create space web request.

$responseHelper.getJsonElement(".homepage.id")

Add the third step

The third step creates a comment to inform the user of the new space.

We are again using the $responseHelper variable, but this time to get the web link to the space. Since the link is relative, we are also using the $remoteServer variable to get the display URL of the server.

Created a new space: $remoteServer.getDisplayUrl()$responseHelper.getJsonElement("._links.webui")

Using the operation

After executing the operation you can see the stored page ID and the new comment with the link to the new space on the issue.