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
Hi,
Are you able to create the same page in the space from UI now?.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.