How do I create a new space giving admin rights to specific users, using confluence cloud API?

Using confluence cloud API, I need to create a new confluence space giving admin rights to a specific user for that new space.

I tried:

        payload = {
            "key": space_key,
            "name": space_name,
            "description":
                {
                    "plain": {
                        "value": "",
                        "representation": "plain"
                    }
                },
            "permissions":
                [
                    {
                        "operation": {
                            "operation": "administer",
                            "targetType": "space"
                        },
                        "subjects": {
                            "user":
                                [
                                    {
                                        "username": "dom"
                                    }
                                ],
                            "group": []
                        },
                        "anonymousAccess": False,
                        "unlicensedAccess": False
                    }
                ]
        }
        response = self.session.post(self.confluence_server_url + '/rest/api/space',
                                     data=json.dumps(payload), json=True,
                                     headers={'Content-Type': 'application/json'})

        response = response.json()
        print('XXX')
        print(response)

I see the following traces:

api_1       | XXX
api_1       | {'_links': {'self': 'https://elementai.atlassian.net/wiki/rest/api/space/TESTDOMA', 'webui': '/spaces/TESTDOMA', 'context': '/wiki', 'collection': '/rest/api/space', 'base': 'https://elementai.atlassian.net/wiki'}, 'permissions': [], 'id': 40337735, 'key': 'TESTDOMA', 'description': {'plain': {'embeddedContent': [], 'representation': 'plain', 'value': ''}, '_expandable': {'view': ''}}, 'status': 'current', '_expandable': {'metadata': '', 'settings': '/rest/api/space/TESTDOMA/settings', 'icon': '', 'lookAndFeel': '/rest/api/settings/lookandfeel?spaceKey=TESTDOMA', 'theme': '/rest/api/space/TESTDOMA/theme', 'operations': '', 'homepage': '/rest/api/content/40337742'}, 'type': 'global', 'name': 'test-dom-admin13'}

so I assumed the space had been created… but it turned out it wasn’t. ;(
I get a “Oops, you’ve found a dead link” when I try to access the URL where the new space should be…

Any idea what went wrong?
An working example of the above payload would greatly help me.

Thanks!

Hey dom,

I looked into it and it seems to be a bug. I created a ticket you can follow here:
https://jira.atlassian.com/browse/CONFCLOUD-57682

3 Likes
  • Resolution: Timed out

Hello from 2022!
It’s still not working.
Of course, who could possibly need to create a Space with permission in this world?
And nobody even cares about not working examples in the REST API documentation…

I’ve spent two days finding a way to make that endpoint work just to find a timed-out ticket.
It makes me go crazy once more

1 Like

Hi all - the reason this happens is: When a permission set is passed in, a space is created with and only with the permissions passed in, not in addition to the default permission set.

If you would like to add permissions on top of the default set, you can create a space with no permissions passed in (default space permissions used), then you can use the space permissions endpoints to add/remove permissions as needed.

The create space documentation should also note this: https://developer.atlassian.com/cloud/confluence/rest/v1/api-group-space/#api-wiki-rest-api-space-post

If you would like to start with a space that is only visible to the creator, you can use the create private space endpoint.

Additional explanation here: [CONFCLOUD-60439] Creating Space with Permissions Not Working (REST API) - Create and track feature requests for Atlassian products.

We realize this could be confusing, and are discussing updating this behavior for V2 of our REST APIs.

1 Like

Hi @SimonKliewer,
So seems that I faced with another issue.
The problem is about the right format of the payload.
:white_check_mark: Test case create a FPTST1 space. Without permission block it works fine 201 and space is created.
:x: Problems starts when I try to add at least one permission. Let it be “group FP_CON_ADMIN should read a space”:
POST /wiki/rest/api/space

{
  "key": "FPTST1",
  "name": "FP to be deleted",
  "description": {
    "plain": {
      "value": "To be deleted space for testing",
      "representation": "plain"
    }
  },
  "permissions": [
    {
      "operation": {
        "operation": "read",
        "targettype": "space"
      },
      "subjects": {
        "group": {
          "results": [
            {
              "type": "group",
              "name": "FP_CON_ADMIN"
            }
          ]
        }
      }
    }
  ]
}

Response:

{
  "statusCode": 500,
  "message": "java.lang.NullPointerException: null"
}

I’ve already tried a bunch of different options for a subjects element.
:x: Group ID instead of the name:

        "group": {
          "results": [
            {
              "type": "group",
              "value": "f4e7f0e0-b1a0-45a7-9c69-4a0ef4e4ecdb"
            }
          ]
        }

Response:

{
  "statusCode": 400,
  "message": "org.codehaus.jackson.map.JsonMappingException: Instantiation of [simple type, class com.atlassian.confluence.api.model.people.Group] value failed: null (through reference chain: com.atlassian.confluence.api.model.content.Space[\"permissions\"]->com.atlassian.confluence.api.model.permissions.SpacePermission[\"subjects\"])"
}

:x: W/o a results array wrapper:

        "group": {
              "type": "group",
              "name": "f4e7f0e0-b1a0-45a7-9c69-4a0ef4e4ecdb"
        }

Response:

{
  "statusCode": 500,
  "message": "java.lang.NullPointerException: null"
}

:x:With an empty user array (as in the question from the above):

        "user": [],
        "group": [
              "type": "group",
              "name": "FP_CON_ADMIN"
        ]

Response:

{
  "statusCode": 400,
  "message": "org.codehaus.jackson.map.JsonMappingException: (was java.lang.IllegalStateException) (through reference chain: com.atlassian.confluence.api.model.content.Space[\"permissions\"]->com.atlassian.confluence.api.model.permissions.SpacePermission[\"subjects\"])"
}

I would be grateful if you can provide a working format for such request,
Thank you in advance!