Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to update a page in confluence by java

Tian July 15, 2014

I need to update a confluence page by java. I find the documents in here https://docs.atlassian.com/atlassian-confluence/REST/latest/

But when I use them, it response with "HTTP/1.1 405 Method Not Allowed", following is my code

@Test
    public void testHttpPut() throws IOException {
        HttpClient client = new HttpClient();

        UsernamePasswordCredentials cred = new UsernamePasswordCredentials(user, passwd);

        AuthScope auth = new AuthScope(AuthScope.ANY);

        client.getState().setCredentials(auth, cred);

        HttpMethod putMethod = new PutMethod("https://confluence.XXX.com/rest/prototype/latest/content/33064104?os_authType=basic");

        putMethod.setDoAuthentication(true);

        client.executeMethod(putMethod);

        System.out.println(putMethod.getStatusLine());

        System.out.println(putMethod.getResponseBodyAsString());

        putMethod.releaseConnection();

    }

But When I use GetMethod, it response with success, Why?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Yagnesh Bhat
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 Leaders.
July 16, 2014

Hi Tian,

Try using JSON RPCs, check out the link below: https://developer.atlassian.com/display/CONFDEV/Remote+Confluence+Methods#RemoteConfluenceMethods-Pages

In this page do a search for the method : updatePage , its under the paragraph Management:

Its a method like this :

Page updatePage(String token, Page page, PageUpdateOptions pageUpdateOptions)



Tian July 20, 2014

I finally use XML RPC to achieve this

mayank shukla November 7, 2014

Hi Tian.i have same problem on confluence.i have a page on that where i have a table on which i want to add row dynamically from my code.will you please share some helpfull things by which i would solve my problem. i read out atlassian doucmentation and they said that xml-rpc has deprecated.so how to use rest api for that.

0 votes
Timothy
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 Leaders.
July 15, 2014

You might want to review what API is available using the REST API Browser.

Krishna M Digvijai February 21, 2018

@Timothy I am trying to update page content using POSTMAN . I am sending empty as ancestor id because for my test page ancestor id is blank.Getting below error 
"Instantiation of [simple type, class com.atlassian.confluence.api.model.content.id.ContentId] value failed: ContentId string must not be null or empty (through reference chain: com.atlassian.confluence.api.model.content.Content[\"ancestors\"]->com.atlassian.confluence.api.model.content.Content[\"id\"])"

What  should I pass for ancestor id if ancestor id is blank or null.

Krishna M Digvijai February 21, 2018

@Timothy I found a way to get ancestor version and my update process is working fine.

TAGS
AUG Leaders

Atlassian Community Events