---
title: "How to Create a Confluence Space Using the Confluence CLI"
canonical: "https://support.appfire.com/space/SUPPORT/89139906/How%20to%20Create%20a%20Confluence%20Space%20Using%20the%20Confluence%20CLI"
format: markdown
---
> Macro (div)
> 
> ### On this page
> 
> > Macro (toc)

> Macro (include)

# Recipe overview

<span style="color: #333333">This recipe provides step-by-step instructions on how to create a Confluence space and assign appropriate permissions using the </span>[<span style="color: #333333">Confluence Command Line Utility (CLI)</span>](https://marketplace.atlassian.com/plugins/org.swift.confluence.cli)<span style="color: #333333"> add-on. This allows a Confluence Administrator to quickly, consistently and flawlessly create new spaces when requested by your users.</span>

:info:<span style="color: #333333"> It will take you approximately 5 minutes to complete this recipe.</span>

# Recipe level

> Macro (table-plus)
> 
> ![image](media://e71d607e-e841-42c9-865e-a9c2f227cc72)

# Ingredients

> Macro (table-plus)
> 
> |  |  |
> | --- | --- |
> | ![image](media://f7636dc0-9f76-4e6a-b1ff-084ba5303bbd) | [Confluence](https://bobswift.atlassian.net/wiki/spaces/recipes/pages/103613154/Confluence+Recipes) |
> | ![image](media://a12fca36-e2cc-4b40-9152-649054b41b98) | [Confluence Command Line Interface (CLI)](https://bobswift.atlassian.net/wiki/spaces/recipes/pages/104399034/Confluence+Command+Line+Interface+CLI+Recipes)<br>> Macro (legacy-content)<br>> Macro (legacy-content) |

# Preparation

- Install the latest [downloadable Confluence CLI Client](https://appfire.atlassian.net/wiki/spaces/info/pages/86081659) on your computer.
- If you have not done so already, follow all of the CLI installation instructions for [Confluence](https://appfire.atlassian.net/wiki/spaces/CSOAP/pages/68457775) <u>including the steps marked optional</u>.
- Open a  [command window](https://appfire.atlassian.net/wiki/spaces/SUPPORT/pages/89141112) you'll use to execute CLI commands.

# Steps

> Macro (table-plus)
> 
> |  |  |  |
> | --- | --- | --- |
> | ![image](media://3c39dbc7-b6c3-452d-a5b4-0ee58ed73c46) | ## Create Action File<br>> Macro (legacy-content)<br>In this step, you will be creating a text file that contains the CLI actions that will create a Confluence space and set appropriate permissions for it. This file will be invoked and executed in a later step.<br>1. Open an editor capable of producing a plain text file, such as Notepad (Windows) or TextEdit (Mac), and then paste in the contents shown to the right.
>   1. Line 1 executes the `addSpace` action to create a new Confluence space using the following parameters:
>     - `--space` defines the space key for the new space.
>     - `--name` defines the name of the new space.
>     - `--description` provides some explanation regarding the purpose or use of the new space.
>   2. Line 2 executes the `addPermissions` action to grant permissions to anonymous users.
>   3. Line 3 executes the `addPermissions` action to grant permissions to members of the confluence-users group.
>   4. Line 4 executes the `addPermissions` action to grant permissions to members of the confluence-administrators group.
>   5. Line 5 executes the `addPermissions` action to grant permissions to a user with the username of "joe" who, in our example, represents the person requesting the new space.
>   6. Lines 2 through 5 use the following parameters for the addPermissions action:
>     - `--space` defines the space key for the new space. It is using a @space@ [variable](https://appfire.atlassian.net/wiki/spaces/CSOAP/pages/68457799) that indicates to use the last referenced space key, which would be the one on Line 1's addSpace action. You could also use the same value used on Line 1 ("newSpaceKey"), but using the variable will result in you making fewer edits when using this file again to create another new space.
>     - `--userId` identifies the username of the user to whom permissions should be granted. This can be a specific person's username (as used on Line 5) or it can also be "anonymous" (as used on Line 2) to grant access to anonymous users. An 'anonymous user' is someone who has not logged in to the Confluence site.
>     - `--group` ** **identifies the group to whom permissions should be granted.
>     - `--permissions` identifies each permission to be granted to the userId or group.
> 2. Save the file under the name **CreateNewWikiSpace_actions.txt** in the same folder to which you installed the Confluence CLI client. | > Macro (anchor)
> 
> **Example action file:**<br>##### **CreateNewWikiSpace_actions.txt**<br>```plaintext
> --action addSpace --space "newSpaceKey" --name "newSpaceName" --description "This is the Space Description"
> --action addPermissions --space "@space@" --userId "anonymous"                 --permissions "viewspace" 
> --action addPermissions --space "@space@" --group  "confluence-users"          --permissions "viewspace,comment,removecomment,editspace,removepage,setpagepermissions,editblog,removeblog,createattachment,removeattachment,exportspace"
> --action addPermissions --space "@space@" --group  "confluence-administrators" --permissions "viewspace,comment,removecomment,editspace,removepage,setpagepermissions,editblog,removeblog,createattachment,removeattachment,removemail,exportspace,setspacepermissions"
> --action addPermissions --space "@space@" --userId "joe"                       --permissions "viewspace,comment,removecomment,editspace,removepage,setpagepermissions,editblog,removeblog,createattachment,removeattachment,removemail,exportspace,setspacepermissions"
> ``` |
> | --- |
> | ![image](media://ea6e2e38-659c-44ff-a207-b88c62344e54) | ## Create Confluence CLI command<br>> Macro (legacy-content)<br>In this step, you will form the command line that will invoke the Confluence CLI to execute the action file you created in the previous step.<br>The command is shown to the right.<br>- `confluence` indicates to invoke the Confluence CLI client.
> - `The ``run `[action](https://appfire.atlassian.net/wiki/display/HCLI/Reference) indicates to run actions from the file identified in the `--file` parameter. | > Macro (anchor)
> 
> **Example command:**<br>```plaintext
> confluence --action run --file CreateNewWikiSpace_actions.txt
> ``` |
> | --- |
> | ![image](media://5dfd62df-2428-453e-bf3a-af3335ed0f63) | ## Execute Confluence CLI command<br>> Macro (legacy-content)<br>In your command window, type the command from the previous step and press Enter.<br>The command will run, showing the result of executing the actions defined in the **CreateNewWikiSpace_actions.txt** file you created earlier.<br>Note that Administrator rights to the new space will  automatically be given to the user whose credentials were used when running the Confluence CLI.<br>If you go into the Space Administration screens to look at the Space Details and Permissions screens, you should see something similar to the screenshots shown to the right.<br>That's it! With one command, you've created a Confluence space and saved yourself from having to complete many steps to do it! | > Macro (anchor)
> 
> **Example output:**<br>```plaintext
> Run: --action addPermissions --space "newSpaceKey" --userId "anonymous"                 --permissions "viewspace"
> [VIEWSPACE] permissions where added to space: 'newSpaceKey' for: 'anonymous'.
> Run: --action addPermissions --space "newSpaceKey" --group  "confluence-users"          --permissions "viewspace,comment,removecomment,editspace,removepage,setpagepermissions,editblog,removeblog,createattachment,removeattachment,exportspace"
> [VIEWSPACE, COMMENT, REMOVECOMMENT, EDITSPACE, REMOVEPAGE, SETPAGEPERMISSIONS, EDITBLOG, REMOVEBLOG, CREATEATTACHMENT, REMOVEATTACHMENT, EXPORTSPACE] permissions where added to space: 'newSpaceKey' for: 'confluence-users'.
> Run: --action addPermissions --space "newSpaceKey" --group  "confluence-administrators" --permissions "viewspace,comment,removecomment,editspace,removepage,setpagepermissions,editblog,removeblog,createattachment,removeattachment,removemail,exportspace,setspacepermissions"
> [VIEWSPACE, COMMENT, REMOVECOMMENT, EDITSPACE, REMOVEPAGE, SETPAGEPERMISSIONS, EDITBLOG, REMOVEBLOG, CREATEATTACHMENT, REMOVEATTACHMENT, REMOVEMAIL, EXPORTSPACE, SETSPACEPERMISSIONS] permissions where added to space: 'newSpaceKey' for: 'confluence-administrators'.
> Run: --action addPermissions --space "newSpaceKey" --userId "joe"                       --permissions "viewspace,comment,removecomment,editspace,removepage,setpagepermissions,editblog,removeblog,createattachment,removeattachment,removemail,exportspace,setspacepermissions"
> [VIEWSPACE, COMMENT, REMOVECOMMENT, EDITSPACE, REMOVEPAGE, SETPAGEPERMISSIONS, EDITBLOG, REMOVEBLOG, CREATEATTACHMENT, REMOVEATTACHMENT, REMOVEMAIL, EXPORTSPACE, SETSPACEPERMISSIONS] permissions where added to space: 'newSpaceKey' for: 'joe'.
> Run completed successfully. 5 actions were successful from file: /usr/local/CLI/CreateNewWikiSpace_actions.txt
> ``` |
> | --- |
> | ![image](media://1fd522c3-c3be-4ce0-9b36-b97d7fb3b2fe) | ## Bonus Tip<br>> Macro (legacy-content)<br>You may have established one or more sets of "standard permissions" you use in your Confluence site, such as one for a personal space, one for a team space, and another for a public space open to everyone.<br>If this is the case, you may want to use a modified version of the **CreateNewWikiSpace_actions.txt** file as shown on the right.<br>In this modified version, Lines 2 through 5 are replaced with a single line (Line 2) that uses the `copyPermissions`` `action so that the new space is created with permissions identical to what is used in another space. The parameters used by this action are:<br>- `--space` which identifies the the space key of a space that has the permissions you want to copy
> - `--newSpace` which uses the @space@ variable to indicate it is the newly created space to which the other space's permissions should be copied. | > Macro (anchor)
> 
> **Modified action file:**<br>##### **CreateNewWikiSpace_actions.txt**<br>```plaintext
> --action addSpace --space "newSpaceKey" --name "newSpaceName" --description "This is the Space Description"
> --action copyPermissions --space "modelspace" --newSpace "@space@"
> ``` |

> Macro (include)