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

**URL:** <https://community.developer.atlassian.com/t/how-to-update-a-page-in-user-macro-using-javascript-without-changing-page-content/25147>\
**Category:** Confluence Server\
**Tags:** javascript, user-macro, macro, rest-api\
**Created:** [November 21, 2018, 9:04am UTC](https://community.developer.atlassian.com/t/how-to-update-a-page-in-user-macro-using-javascript-without-changing-page-content/25147 "2018-11-21T09:04:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabian](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/fabian/32/37078_2.png) [@fabian](https://community.developer.atlassian.com/u/fabian)\
**Post date:** [November 21, 2018, 9:04am UTC](https://community.developer.atlassian.com/t/how-to-update-a-page-in-user-macro-using-javascript-without-changing-page-content/25147/1 "2018-11-21T09:04:34Z")

</div>

Hi,

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

```auto
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

---

<div class="post-metadata">

**Author:** ![ppasler](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/ppasler/32/49174_2.png) [@ppasler](https://community.developer.atlassian.com/u/ppasler)\
**Post date:** [November 21, 2018, 11:24am UTC](https://community.developer.atlassian.com/t/how-to-update-a-page-in-user-macro-using-javascript-without-changing-page-content/25147/2 "2018-11-21T11:24:14Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![fabian](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/fabian/32/37078_2.png) [@fabian](https://community.developer.atlassian.com/u/fabian)\
**Post date:** [November 21, 2018, 1:41pm UTC](https://community.developer.atlassian.com/t/how-to-update-a-page-in-user-macro-using-javascript-without-changing-page-content/25147/3 "2018-11-21T13:41:07Z")

</div>

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.

```auto
## @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
