It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Create/modify confluence property through REST API fails Edited

Attempting to create/update confluence property from a Built in Macro:

Reading(GET) of parameter works fine, but PUT/POST fails w:

Fail: {"statusCode":500,"message":"","reason":"Internal Server Error"}

During debugging the property was created using the REST API Browser, the parameter was also successfully modified using a modified response from a request.

The example from REST API manual was used:https://docs.atlassian.com/atlassian-confluence/REST/6.6.0/#content/{id}/property-create

{ "key": "example-property-key", "value": { "anything": "goes" } }

When attempting same from macro it fails (GET successful)

AJS.$(document).on('click', '#button_$paramChartID', function() {

jQuery.ajax({
contentType: 'application/json',
type: 'GET',
url: confbase + "/rest/api/content/" + AJS.params.contentId + "/property/example-property-key",
}).done(function(response) {
AJS.log("Response: " + JSON.stringify(response));
AJS.log("Response.key: " + response.key);
response.value.anything = "goes" + response.version.number;
response.version.number = response.version.number + 1;
jQuery.ajax({
contentType: 'application/json',
type: 'PUT',
data: response,
url: confbase + "/rest/api/content/" + AJS.params.contentId + "/property/example-property-key",
}).done(function(response2) {
AJS.log("Response: " + JSON.stringify(response2));
AJS.log("Response.key: " + response2.key);
}).fail(function (xhr) {
AJS.log("Fail: " + xhr.responseText);
});

}).fail(function (xhr) {
AJS.log("Fail: " + xhr.responseText);
});


});

 

Similar problems encountered using jQuery PU and POST before (unresolved/no response)

https://community.atlassian.com/t5/Jira-questions/Failing-with-jQuery-PUT-and-POST-to-JIRA-REST-API-from/qaq-p/1204907

Confluence server 6.15, JIRA Server 8.3

1 answer

0 votes
Dario Atlassian Team Tuesday

Hello @zaphnet ,

If you are using Confluence Server then the issue here seems to be with the endpoint called.

Indeed, in your script I can see:

url: confbase + "/rest/api/content/" + AJS.params.contentId + "/property/example-property-key"

 

While the correct endpoint to be called for Confluence Server (from the documentation page you are pointing to) is:

/rest/content/{id}/property/{key} (there is no '/api/' in the endpoint for Server)

 

The endpoint you are using seems to be similar to the one used in Confluence Cloud REST API

/wiki/rest/api/content/{id}/property/{key}

 

Please let me know if this helps. In case it doesn't, please try to send the same request body to the same endpoint (using the same credentials if possible) with Curl and paste the response you get in here (making sure to remove the sensitive data). 

 

Cheers,
Dario

Thanks for the response, but it did not help.

At the top of the documentation it is mentioned:

rest.PNG

Tried your suggestion, but then I only get a "page not found".

With the code above I can read the json file stored(created with postman and with "rest/api/".

AJS.toInit(function() {

jQuery.ajax({
contentType: 'application/json',
type: 'GET',
url: confbase + "/rest/api/content/" + 42238001 + "/property/example-property-key",
}).done(function(response) {
AJS.log("Response: " + JSON.stringify(response));
AJS.log("Response.key: " + response.key);
}).fail(function (xhr) {
AJS.log("Fail: " + xhr.responseText);
});
});
console:
Response.key: example-property-key

Accessing directly url:
https://confluence-test.nnn.net/rest/api/content/42238001/property/example-property-key

 

{"id":"42238003","key":"example-property-key","value":{"anything":"goes4"},"version":{"when":"2019-10-30T23:40:28.573+01:00","message":"","number":3,"minorEdit":false,"hidden":false},"_links":{"base":"https://confluence-test.nnn.net","context":"","self":"https://confluence-test.nnn.net/rest/api/content/42238001/property/example-property-key"},"_expandable":{"content":"/rest/api/content/42238001"}}

 All the edits/changes to the property has been through postman (successfully)

The PUT fails with 500 + "Internal Server Error".

In the "on click" example above I successfully read the json object, modify it and successfully use the json object with postman - but this Ajax PUT fails...

 

The confluence rest api documentation has not been updated since 6.6.0 

Hi @zaphnet , 

You are totally right, I have indeed found an old request to fix the documentation that has never been taken into account since it was reported as a suggestion instead of a bug:

I have now changed it to bug and update the description. I will get in touch with DEV soon to ask to have this fixed asap.

 

For the rest, if I understand correctly you are able to GET and PUT the endpoint using POSTMAN (or Curl) but the same action fails when you try to do so from your code. 

Can you kindly confirm this is the case?

If this is the case then it would be a good idea to run it once again and check Confluence logs if you can find more information on what is failing (you can paste the error message here making sure to remove the sensitive data).

 

P.S. Apologies for the mistake, I usually work with Jira Cloud REST API and I am now slowly starting with Confluence Server. My knowledge is not that solid yet. 

 

Cheers,
Dario 

The GET and PUT/POST Works OK from postman/curl.

Get works OK from my built in JS script code, PUT/POST fails.

I'm admin in Confluence+JIRA, but not on the servers - I will check if I can get a hold of any log-files from the Server.

I'm a novice working with JS and Ajax, mostly been working with Golang scripts when accessing the REST API.

BR

/Per

Dario Atlassian Team yesterday

Hi @zaphnet ,

As written in the other thread: 

Hopefully you can get the logs. Otherwise, in case you cannot, if the GET works and the PUT fails, we can make the assumption that there is either something wrong with the code for the PUT request or with the provided body (but that should return error 400).

In this case one option would be to ask in the developers' community to check the code:

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

273 views 1 2
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you