How to update a page in user macro using JavaScript without changing page content

javascript
macro
user-macro
rest
rest-api

#1

Hi,

is there a possibility to update a page with REST to generate a new version while keeping the whole page content.

PUT /rest/content/{contentId}

{
  "version": {
    "message": "version comment", 
    "number": 2
  },
  "title": "KEEP EXISTING TITLE",
  "type": "page",
  "body": {
    "storage": {
      "value": "KEEP EXISTING CONTENT",
      "representation": "storage"
    }
  }
}

I’ve noticed that no new version is created unless the title or content changes.
I want to create a new page version triggered by the click on a checkbox, but keep the complete content. I just want to set a version message.

On the UI, when saving the page, this is possible.

Cheers,
Fabian


#2

I am not quite sure, if this is even possible.

A workaround might be to add a “space” (or any other small sign) to the existing content.

"body": {
    "storage": {
      "value": "KEEP EXISTING CONTENT" + " ",
      "representation": "storage"
    }
  }

#3

Hi,

thanks for the feedback.
Such a workaround would be good, but honestly, I’m not sure how to get the latest content.
I tried the following for the REST but have not been successful with the “value”. I want to keep the content as it is. To add a “space” (or any other small sign) to the existing content would be ok.

## @param LabelPickerId:title=Unique ID|type=string|required=true|default=1|desc=If more than one label picker in page, change this to a unique name. 

#set ( $labelPickerId = "lpid-" + $paramLabelPickerId )

<script type="text/javascript">
	AJS.toInit(function ($){
		//every label checkbox on the page
		jQuery(".custom_label_to_add.$labelPickerId").click(function() {
			var labelComment = jQuery(this).val();
			jQuery.ajax({
				url: contextPath + "/rest/api/content/$content.id",
				contentType: 'application/json',
				type: 'PUT',
				data: JSON.stringify({
					"version": {
						"message": "version comment: " + labelComment, 
						"number": $content.version + 1
					},
					"title": "$content.title",
					"type": "page",
					"body": {
						"storage": {
							"value": "",
							"representation": "storage"
						}
					}
				}),
				success: function(postresponse) {
					console.log(postresponse);
				}
			});
		});	
	});
</script>

Cheers,
Fabian