Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Confluence REST API

Raffaele Guasco October 31, 2018

Hi All,
I'm trying to execute any call to confluence Rest Api from a java class. In the specific to create a space and then to create a page inside it.
the code to create a space is :
String spaceBody = "{ \"key\":\"RAID\", \"name\":\"Raider\",\n" +
"\"type\":\"global\", \"description\":{\"plain\": { \"value\": \"Raider Space for raiders\",\"representation\":\n" +
"\"plain\" }}}'";

String confluencePage = "https://<my-host>/wiki/confluence/rest/api/space/";

.......
URL url = new URL(confluencePage );
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Cookie", cookie);

DataOutputStream bodyPage=null;
bodyPage = new DataOutputStream(connection.getOutputStream());
bodyPage.writeBytes(spaceBody );
bodyPage.close();

I receive Ok 200 as response but I can't see any space in confluence created with that name or key.
Does someone if I need to execute any further step?
Many thanks

1 answer

1 accepted

0 votes
Answer accepted
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 12, 2018

Hello Raffaele,

That fact you are getting a Ok 200 back should mean the space was created. With that said, the permissions on the newly created Space may not be set thus only allowing Administrators access to see it within the Space directory.

You can either check your space directory or run an API call to GET space to see if a result returns. Here is how to check the Space Directory:

  1. Visit the space directory – To get to the space directory, choose Spaces > Space directory in the Confluence header.
  2. Filter the list of spaces – Type part of a space name in the Filter field at the top right. That'll quickly narrow down the list of spaces if there are a lot of them.

Here is documentation for The Space Directory.

Along with the REST API calls for Spaces.

Please let us know if you do see the space within the space directory or the GET call. If it does display there you will need to set permissions to allow others to see the newly created space.

Regards,
Stephen Sifers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events