How can i create a space from a blueprint in Java

Maximilian June 15, 2018

Hey,

this question is very close to this one: create page from blueprint in java

the difference is that my goal is to create a space.

I created a space-blueprint in my plugin and want to create a space based on this blueprint.

 

I found the following classes but can't figure out how i can achieve my goal:

SpaceBlueprintManager  (Is not an OSGI Component - @ComponentImport doesn't work)

SpaceBlueprintService (Seems like it needs the SpaceBlueprintManager, but can't figure out how to get the manager)

 

The ContentBlueprintManager is apparently only for creating pages ..

 

any help is appreciated :)

1 answer

1 accepted

2 votes
Answer accepted
Maximilian June 18, 2018

Ok found a REST-Method, no need to use java api:

{host:port}/rest/create-dialog/latest/space-blueprint/create-space

Method: POST

Headers:

Content-Type: application/json

User-Agent: xyz      -> Just use some dummy here e.g. 'xyz' :)

Body:

{

        "name": "NAME",
        "description": "DESCRIPTION",
        "context": { },
        "permissions": "PERMISSIONS",
        "spaceBlueprintId": "ID",
        "spaceKey": "SPACE-KEY"

}

 

You can get the space Blueprint id by using this method:

Method: GET

{host:port}/rest/create-dialog/latest/space-blueprint/list

this will give you a list with all space blueprints and their ids :)

SunRiser
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 7, 2019

Thank you @Maximilian 

I tried your suggestion and it works!

The below request creates a space with Knowledge base template

curl -u admin:password -X POST -H 'Content-Type: application/json' -d'{"spaceKey":"KM","name":"KB API Test","spaceBlueprintId":"279af294-8caa-4b6d-88f8-67161c18a060","context":{"name":"KB API Test","spaceKey":"KM","spaceDesc":"REST API Space creation using Knowledge base template ","noPageTitlePrefix":"true","ContentPageTitle":"KB API Test"}}' http://localhost:8090/rest/create-dialog/1.0/space-blueprint/create-space

The key is, we need to specify the spaceBlueprintId as part of JSON payload otherwise it will just create the default blank space. We can also get the spaceBlueprintId for each space template from AO_54C900_SPACE_BLUEPRINT_AO

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events