I can find the latest API from Atlassian.
https://docs.atlassian.com/atlassian-confluence/REST/5.5.3/#d2e120
I can see that I should be able to update a page via the call "/content/{id}" PUT.
But when I try to PUT I just get a 500 back from the server. If I try a simple example like this...
Example code for trying to update a page.
String json = " { "+ " \"body\":{ "+ " \"view\":{ "+ " \"value\":\"<p>main updated</p>\", "+ " } "+ " } "+ " } "; Client client = Client.create(); WebResource webResource = client.resource("http://10.210.31.247:80/rest/api/latest/content/8226411?os_username=jeff.porter@pcmsgroup.com&os_password=patterns"); webResource.setProperty("Content-Type", "application/json"); ClientResponse response = webResource.accept("application/json").put(ClientResponse.class, json); System.out.println("Output from Server .... ["+response.getStatus()+"]"); System.out.println(response.getEntity(String.class));
I still get a 500 error back.
Output from Server.... statusCode [500]{"statusCode":500,"message":"javax.ws.rs.WebApplicationException: null"}
Can someone please give me some advice.
Below is the stacktrace from the Confluence log files...
2014-07-0210:15:57,856 WARN [http-bio-80-exec-15274][atlassian.confluence.cache.TransactionalCacheFactory] warning Transactional cache update outside transaction.All updates to this cache should be performed from a thread with a valid transaction context.2014-07-0210:15:57,856 ERROR [http-bio-80-exec-15274][rest.api.model.ExceptionConverter] convertServiceException No status code found for exception, converting to internal server error :-- url:/rest/api/content/8226411| userName: j.p@p.com javax.ws.rs.WebApplicationException at com.sun.jersey.server.impl.uri.rules.TerminatingRule.accept(TerminatingRule.java:66) at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339) at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) at com.atlassian.plugins.rest.module.RestDelegatingServletFilter$JerseyOsgiServletContainer.doFilter(RestDelegatingServletFilter.java:178) at com.sun.jersey.spi.container.servlet.ServletContainer.doFilter(ServletContainer.java:795) at com.atlassian.plugins.rest.module.RestDelegatingServletFilter.doFilter(RestDelegatingServletFilter.java:73) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:74) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:42) at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:77) at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:63) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:74) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:42) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter$1.doFilter(DelegatingPluginFilter.java:66) at com.atlassian.plugins.rest.module.servlet.RestServletUtilsUpdaterFilter.doFilterInternal(RestServletUtilsUpdaterFilter.java:26) at com.atlassian.plugins.rest.module.servlet.RestServletUtilsUpdaterFilter.doFilter(RestServletUtilsUpdaterFilter.java:40) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:74) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:42) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter$1.doFilter(DelegatingPluginFilter.java:66) at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:25) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:74) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:42) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter$1.doFilter(DelegatingPluginFilter.java:66) at com.atlassian.mywork.client.filter.ServingRequestsFilter.doFilter(ServingRequestsFilter.java:37)
Community moderators have prevented the ability to post new answers.
Here's some example code I wrote which demonstrates how to PUT a new version of a Page using the Confluence REST API: https://bitbucket.org/jaysee00/confluence-rest-api-example/src/master/src/main/java/com/atlassian/api/examples/Main.java
This is very helpful. Bookmarking this page for future reference!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just one question... In this example if the page you choose to update is a child page(i.e. located 2 levels down on the menu on the left), after the update the page it no longer a child page, but exist at the root level. Any idea what I'm doing wrong?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @jeff porter - that was an error in my example, sorry! To preserve the page's location, you need to give Confluence the page's list of ancestors when you update it. The easiest way to do this is to request the ancestors information from Confluence before you update the page, and then echo the same exact information back to it. Here's the commit I made which fixed it - https://bitbucket.org/jaysee00/confluence-rest-api-example/commits/99cee347f6630fe0937538fc3902dcf2e9cd5037
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not sure I'm following the example correctly... I run your code with my pageId (the page to update) I get the content back & increase the version number by 1. I change the storage section to have set it to "Hello World". I then PUT the document back. BUT... The page moves from being a child under On-Demand Home/ProjectA/Documentation/RestCreatedTestPage To the root level RestCreatedTestPage I've looked over the JSON from the GET & I what I PUT back is the same as I got out. Which is.... "ancestors":[ { "id":"688131", "type":"page", "title":"On-Demand Home" }, { "id":"688131", "type":"page", "title":"On-Demand Home" }, { "id":"1245225", "type":"page", "title":"ProjectA" }, { "id":"11993936", "type":"page", "title":"Documentation" } ] I'm not sure why "On-Demand Home" appear twice, or why my page jumps back to the root. It seem to just link it to the first ancestor. Any ideas?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm just removing all the ancestors apart from the one I care about. that seems to work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
JSONArray jsonArray = pageObj.getJSONArray("ancestors");
pageObj.remove("ancestors");
pageObj.append("ancestors", jsonArray.get(jsonArray.length()-1));
Perfectly will work like jeff mentioned :). Thanks to you Jeff.
Root casue:
While pushing back to confluence, "ancestors" should be a JSONObject not just a value.
Fixing this issue in my code took more time for me :)
Call me if anybody facing issue: +91-9940201018(kamanivenkat@gmail.com).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Joe!
(sorry for the delay in getting back to this task)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Check out the answer here :
https://answers.atlassian.com/questions/316106/how-to-update-a-page-in-confluence-by-java
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.