Forums

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

Not able to update the exisiting confluence using Java Rest API

Naveen Kumar D P
Contributor
December 16, 2019

Hi,

We are using confluence cloud instance,

we are trying to edit the existing confluence page using the page ID.I have attached the code below.

public static void main(String[] args) throws JSONException,
AuthenticationException, ClientHandlerException,
ClassNotFoundException, SQLException, ParseException, IOException {
String urlLink = "";
String auth = new String(Base64.encode(""));
String updatePage =
"{\n" +
"\"type\":\"page\",\n" +
"\"ancestors\":\n" +
" [\n" +
" {\n" +
" \"type\":\"page\",\n" +
" \"id\":1501003952\n" +
" }\n" +
" ],\n" +
"\"title\":\"Sprint Macro\",\n" +
"\"space\":\n" +
" {\n" +
" \"key\":\"LAS\"\n" +
" },\n" +
"\"body\":\n" +
" {\n" +
" \"storage\":\n" +
" {\n" +
" \"value\":\"<ac:structured-macro ac:name=\\\"attachments\\\">\n" +
" <ac:parameter ac:name=\\\"old\\\">false<\\/ac:parameter> <ac:parameter ac:name=\\\"patterns\\\">*<\\/ac:parameter> \n" +
" <ac:parameter ac:name=\\\"sortBy\\\">name<\\/ac:parameter> <ac:parameter ac:name=\\\"sortOrder\\\">ascending<\\/ac:parameter> \n" +
" <ac:parameter ac:name=\\\"labels\\\"><\\/ac:parameter> <ac:parameter ac:name=\\\"upload\\\">false<\\/ac:parameter> <\\/ac:structured-macro>\",\n" +
" \"representation\":\"storage\"\n" +
" }\n" +
" }\n" +
"}";
// rest/api/content/
// System.out.println(updatePage);
String Page = invokePostMethod(auth, urlLink ,updatePage);
}

private static String invokePostMethod(String auth, String url, String data)
throws AuthenticationException, ClientHandlerException {
Client client = Client.create();
WebResource webResource = client.resource(url);
ClientResponse response = webResource
.header("Authorization", "Basic " + auth)
.type("application/json").accept("application/json")
.post(ClientResponse.class, data);
System.out.println("Client Responce " + response);
int statusCode = response.getStatus();
System.out.println("Status Code " + statusCode);
if (statusCode == 401) {
throw new AuthenticationException("Invalid Username or Password");
}
return response.getEntity(String.class);
}
}

Please correct me if i missed anywhere in the code.

 

Thanks

Naveen

2 answers

1 accepted

0 votes
Answer accepted
Johnny Brisbane
June 11, 2015

Brilliant - thanks for the expeditious response!

Our IT guys will manage the upgrades etc. so that should not be a problem. What I was trying to confirm was in regard to Questions, Calendars etc. and the general user functionality there is no difference?

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
June 11, 2015

Nope, the end users won't see any difference. Except that Cloud will generally be a handful of versions ahead of what they've got.

Johnny Brisbane
June 11, 2015

Brilliant - thanks for the help.

1 vote
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
June 11, 2015

There's two questions here.

First, on a Confluence with no internet access, you won't be able to automatically install addons and updates to addons (there is a manual option), and you'll have to copy and paste your licences into it instead of grabbing them automatically.

Secondly, Confluence Cloud and Server are slightly different products.  On the surface, they're the same, but Cloud is managed, so you don't have to run it yourself (upgrades, and system functions are handled by Atlassian), and you can only install a strictly limited list of addons into it.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events