What is the best way to update the page only if change in the content is detected?

Ondrej Šebela August 28, 2023

We have several automation scripts that run every day and generate confluence pages with various data.

What is the best way to avoid having a new page history version in case nothing has changed on the page when the script run?

  1. I was thinking about comparing two last page versions and if there is no change in the content, drop the newest one. But that needs Space admin privilege which is no go.
  2. I was thinking about caching the last processed content in the script itself and comparing it with the page content before updating. But thanks to various confluence markdown features (like _emphasis_ converts to emphasis etc) this isn't an option
  3. ???

So probably what I need is the option to simulate how the confluence HTML code would look like when the processed content is published and compare it with the existing one grabbed from the confluence page?

 

PS: I need an API approach because of the automation

PPS: Why Confluence creates a new page history version even though nothing has changed? Can this behavior be modified?

1 answer

0 votes
Andrii Maliuta
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 28, 2023

Hello @Ondrej Šebela ,

Not sure what OOB scripts of Confluence you use as usually it is up to you to control when and if you create the new version of the page.

You can just compare the body of the page before and after and if they are equal - not to create new version of the page. I suppose you can control your script and trigger changes only after comparison. 

>>> PPS: Why Confluence creates a new page history version even though nothing has changed? Can this behavior be modified?

Please clarify what script you mean ?

Ondrej Šebela August 30, 2023

So you mean retrieving current page content via: 

((Invoke-WebRequest -Method GET -Headers $header -Uri "$baseUri/rest/api/content/$pageID`?expand=body.storage").Content | ConvertFrom-Json).body.storage.value
And compare it with the new content:
"somenewcontent" | ConvertTo-ConfluenceStorageFormat
Andrii Maliuta
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 30, 2023

@Ondrej Šebela ,

Could you please elaborate on what and how this script works in general? 

So, if you have some HTML data from other source and when you get it you just get the BODY ('view' representation) of the page via REST API (in your example .NET/C#/PShell, I suppose) and compare the String of the page body and the String of the HTML you have. If they are equal , you do not create new version of the page by updating it (HTTP 'PUT').

Ondrej Šebela August 30, 2023

We have several generated confluence pages, but in general, I grab some data (like Active Directory groups), convert them to HTML via the official PowerShell command ConvertTo-ConfluenceStorageFormat which returns HTML string 1.png

 

So I guess I should compare it to the HTML retrieved via GET webrequest mentioned in previous post right?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events