How can I create a confluence space using an api?

and tried to create a confluence space using an Api: https://orosreto.atlassian.net/wiki/rest/api/space
but I always get an error this is the json body

‘{
“key”: “”,
“name”: “”,
“description”: {
“plain”: {
“value”: “”,
“representation”: “”
}
},
“permissions”: [
{
“subjects”: {
“user”: {
“results”: [
{
“type”: “known”,
“username”: “”,
“userKey”: “”,
“accountId”: “”,
“accountType”: “atlassian”,
“email”: “”,
“publicName”: “”,
“profilePicture”: {
“path”: “”,
“width”: 2154,
“height”: 2154,
“isDefault”: true
},
“displayName”: “”,
“operations”: [
{
“operation”: “administer”,
“targetType”: “application”
}
],
“details”: {},
“personalSpace”: {
“id”: 2154,
“key”: “”,
“name”: “”,
“type”: “”,
“status”: “”,
“_expandable”: {},
“_links”: {}
},
“_expandable”: {
“operations”: “”,
“details”: “”,
“personalSpace”: “”
},
“_links”: {}
}
],
“size”: 2154
},
“group”: {
“results”: [
{
“type”: “group”,
“name”: “”,
“id”: “”,
“_links”: {}
}
],
“size”: 2154
},
“_expandable”: {
“user”: “”,
“group”: “”
}
},
“operation”: {
“operation”: “administer”,
“targetType”: “application”
},
“anonymousAccess”: true,
“unlicensedAccess”: true
}
]
}’

Hi @DanielTobon ,
Can you share the error you’re getting - it’ll help to understand the problem.
Cheers,
Melissa

Hello @mpaisley
I was checking the body and it is using a curl format, and I’m looking for the body in JSON format to create a confluence space, could you help me with it since I can’t find it anywhere.

Hey @DanielTobon,
The Rest API docs have examples of the body in a range of different formats - see https://developer.atlassian.com/cloud/confluence/rest/api-group-space/#api-api-space-post
In the cURL example, the JSON body is sent as –data
hope that helps.
Mel

So for me, I created this one using POSTMAN:

POST /wiki/rest/api/space HTTP/1.1
Host: <MYURL>.atlassian.net
Authorization: Basic <OMITTED> 
Accept: application/json
Content-Type: application/json
Cache-Control: no-cache

{ "key": "APITEST3", "name": "Test Space 3", "description": { "plain": { "value": "a test space", "representation": "plain" } } }

In my example, the permissions are set based on the default ones specified in my Confluence instance. The rest docs i linked above go into much more detail about how to set the permissions for the space you’re creating.

1 Like