How can I create a new Confluence Space using REST API?

Hi,

I'm building a jira plugin which should create a confluence space.

1. The example in docs POST request of /rest/api/space is working fine, but it adds a standard content on the homepage body, which needs to be customized.

I tried something like:

{"key":"T14",
"name":"Test 14",
"homepage":{"body":{"storage":{"value":"<p>This is the updated text for the new page</p>","representation":"storage"}}},
"metadata":{}}

 

...but it doesn't work. It does not add my content into the homepage.

2. The other issue is similar to this. I want to generate a space with some pages using the zipped xml file, which I exported from confluence. There was RPC API in 5.5 version of confluence:

boolean importSpace(String token, byte[] zippedImportData) - import a space into Confluence.

According to docs it has been deprecated and I wonder if it is possible to upload zip archive of the confluence space using the new rest api. 

2 answers

1 accepted

I'd suggest you to make extra call (or just parse output after POST that creates space) to new space that you've just created and identify ID of Home page and then Update content of that page with your custom value. Don't forget to increase version number).

To be able to create child pages in space you need to use ID of Home page as ancestor and prepage storage format of your pages. Then combine it together in json and POST.

Thank you, Pavel, great explanation

It worked by identifying an id of the home page from the request and then using api/content/{contentId} rest with PUT request

The ancestor field worked as expected as well

No problem, I'm glad that it works for you.

0 vote

Hi Stanislav,

For questions like this one I recommend you to go to our Developer Community. There you'll find developers, product experts and vendors that will be able to help you with your question :)

Cheers!

Ana

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Published yesterday in Confluence

Think you know shares vs. @mentions in Confluence? Take this collab quiz.

To anyone who doubts that Atlassians are a little too obsessed with collaboration, and tools related thereto, let me describe a recent discussion we had (which took place on our internal Confluence, ...

110 views 2 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you