Forums

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

Confluence page, ajax code to change a value in the content properties

Rafer Gluyas
Contributor
June 29, 2025

Trying to get ajax to set a value in the content properties of a confluence page. This is running in Confluence on our local system ver7.13 - it is _not_ running in Cloud.

See below for a snippet of the code, first off is the code that I'm using to validate the properties in the page, literally dumping the keys and values onto the page. 

Second is the javascript/ajax for a button press which should be submitting the value to be checked, or blank depending on the previous state. This is the section of the code that I just cannot get to work!

## @noparams


#foreach ( $item in $content.getProperties().asList() )
Name/Value $item.getName() : $item.getStringValue() , <br>
#end

#set($D='$')
...
..
.
<script type="text/javascript">
AJS.toInit(function(){
AJS.$('#$uiComponent').click(function(){
AJS.${D}.ajax({
type: 'GET',
data: {
submit: 'true',
checkbox: AJS.$(this).attr('id'),
value: AJS.$(this).is(':checked') ? 'checked' : ''
},
url: "$content.getUrlPath()",
success: function(data) {
console.log(data);
},
error: function() {
console.log(data);
}
});
});
});
</script>

 

1 answer

1 accepted

0 votes
Answer accepted
Mia Tamm
Contributor
July 27, 2025

Hi @Rafer Gluyas 

You’re on the right track, but unfortunately, you can’t update content properties via AJAX directly using the page’s URL ($content.getUrlPath()).

To change content properties dynamically (e.g., when clicking a checkbox), you’ll need to create a custom REST endpoint in a Confluence plugin that accepts POST requests and updates the properties server-side.

Your current AJAX call using GET won’t update the content — it needs to send a POST to a backend endpoint that handles the update securely.

Let me know if you need an example plugin setup — happy to share a snippet.
Hope this helps!

— Mia Tamm from Simpleasyty

Rafer Gluyas
Contributor
July 27, 2025

That would be great if you could share a snippet of an example plugin thank you @Mia Tamm!

 

Mia Tamm
Contributor
July 28, 2025

Of course @Rafer Gluyas — here’s a basic example to help you get started with a Confluence plugin that updates content properties via a custom REST endpoint.

1. REST Module definition (in atlassian-plugin.xml):


<rest name="Content Property API" path="/content-prop" version="1.0">
<description>Update content properties</description>
</rest>


2. Java endpoint (example):

 

@Path("/content-prop")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class ContentPropertyResource {


@POST
@Path("/update"
public Response updateContentProperty(ContentPropertyUpdateRequest request) {
ContentEntityObject content = contentEntityManager.getById(request.getContentId());
content.getProperties().setStringProperty(request.getKey(), request.getValue());
contentEntityManager.saveContentEntity(content);
return Response.ok().build();
}
}


3. Example request payload:

 


{
"contentId": 123456,
"key": "my-custom-property",
"value": "checked"
}


This allows your frontend (e.g. via AJAX) to POST to /rest/content-prop/1.0/update with that payload, and store custom data securely.

— Mia Tamm from Simpleasyty

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events