Forums

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

unable to create Confluence page through REST API but web UI

Sam Lee May 22, 2019

I can create a Confluence page through the web portal(https://XXX.atlassian.net/wiki/). I was able to create a Confluence page through REST API until 2019-Apr-24.

 

I have not changed any credential and am returned an error code below:

{
"statusCode": 403,
"data": {
"authorized": false,
"valid": true,
"errors": [],
"successful": false
},
"message": "com.atlassian.confluence.api.service.exceptions.PermissionException: Could not create content with type page"
}

 

source code:

public static void postConfluence(String title, String ancestorId, String content) throws Exception
{
HttpClient httpClient = HttpClientBuilder.create().build(); //Use this instead

try {

HttpPost request = new HttpPost("https://XXX.atlassian.net/wiki/rest/api/content/");

byte[] encodedBytes = Base64.encodeBase64((Util.getApplicationProperty("report.atlassian.acc") + ":" + Util.getApplicationProperty("report.atlassian.pass")).getBytes());
String base64Auth = new String(encodedBytes);
System.out.println("encodedBytes: " + base64Auth);
request.addHeader("Authorization", "Basic " + base64Auth);
request.addHeader("Content-Type", "application/json");
request.addHeader("X-Atlassian-Token", "no-check");
System.out.println("executing request " + request.getRequestLine());

StringEntity params =new StringEntity("{\"type\":\"page\",\"title\":\"" + title + "\",\"ancestors\":[{\"id\":" + ancestorId + "}],\"space\":{\"key\":\"YYY\"},\"body\":{\"storage\":{\"value\":\"" + content + "\",\"representation\":\"storage\"}}}");
request.setEntity(params);
HttpResponse response = httpClient.execute(request);

System.out.println("executing request " + response.toString());

//handle response here...

}catch (Exception ex) {

//handle exception here

} finally {
//Deprecated
//httpClient.getConnectionManager().shutdown();
}
}

 

I had researched this problem. Some said it might be due to permission. If so, which file or configuration I have to check?

 

Update: 2019-07-22

We had checked the Key is correct and matches with the value from the JSON returned from https://XXX.atlassian.net/wiki/rest/api/space?limit=250&start=0

 

2 answers

0 votes
Sam Lee June 2, 2019

Anybody gives me a helping hand?

0 votes
sara
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.
May 22, 2019

Hi,

 

Are you able to create the same page in the space from UI now?.

Sam Lee May 22, 2019

sure

lordkortex
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 20, 2019

Hi, I had same issue. In my case the problem was the ket attribute on space property:

 

StringEntity params =new StringEntity("{\"type\":\"page\",\"title\":\"" + title + "\",\"ancestors\":[{\"id\":" + ancestorId + "}],\"space\":{\"key\":\"YYY\"},\"body\":{\"storage\":{\"value\":\"" + content + "\",\"representation\":\"storage\"}}}");

 

Verify this YYY value is correct . You can check which containers workspace you have at this url

https://YOURDOMAIN.atlassian.net/wiki/rest/api/space

It return a JSON, search for value on  "key":"YOURWORSPACE". Replace this value on  your variable

StringEntity params =new StringEntity("{\"type\":\"page\",\"title\":\"" + title + "\",\"ancestors\":[{\"id\":" + ancestorId + "}],\"space\":{\"key\":\"YOURWORSPACE\"},\"body\":{\"storage\":{\"value\":\"" + content + "\",\"representation\":\"storage\"}}}");

 

I hope it helps.

Like Imesha Kuruppu likes this
Sam Lee July 21, 2019

I had checked that the Key is correct(match with the value returned by JSON)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events