Forums

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

Confluence page created by the REST api is getting recreated as an empty page

Ano Niempje March 28, 2025

Hello everyone. I have a Jira Automation rule. In that rule I either create a Confluence page if it doesn't exist, in Confluence. And if it does exist, I update the page. I run the rule using a cron schedule. Every morning at 06:00 from Monday through Friday.  For testing purposes I can run the rule manually by clicking "Run Rule".

After running the rule I go to the page in Confluence. The page is filled with Jira issues and a table for each issue containing the comments of that issue. Now, the issue that I am facing is a strange one.

Once the page is created at 06:00 by the cron schedule, it is re created multiple times per day, but every time the page is recreated, it is completely blank. On the page it says something like: "Created by MyName 31 minutes ago" even when I open the page at 12:00 during the day. 

When I go to the audit log of the Jira Automation rule, it says it only ran once at 06:00 which is the time it is supposed to run. After that there are no signs of execution of the rule.  So it seems to me that something strange is going on that is causing the page to get recreated every time but I have no clue what it could be.

A colleague of mine told me that once a page is created, the ID can be subject to change. Meaning that it could change and that the ID will never stay the same. Could this be something that relates to the issue? I use the ID of pages when I need to update a page.

My rule:

 

Step 1 : Trigger : Cron schedule = 0 0 6 ? * MON,TUE,WED,THU,FRI * : JQL = Sprint in openSprints() AND project = myProject

 

Step 2 : JQL condition : (updated < now() AND updated >= startOfWeek("+1d")) AND (comment ~ "anything*" OR comment !~ "anything*")

 

Step 3 : create variable ( pageTitleGET ) : smart value = 'Weekrapportage%20myProject.%20Week:{{now.weekOfYear}}%20Jaar:%20{{now.Year}}'

 

Step 4 : create variable ( pageTitlePOSTandPUT ) : smart value = Weekrapportage myProject. Week:{{now.weekOfYear}} Jaar: {{now.Year}}

 

Step 5 : Webhook GET : url = https://confluence.mycompany.nl/rest/api/content/search?cql=title={{pageTitleGET}}&limit=1 : Custom body = { "status": "current" } : Wait for response = checked

 

Step 6 : create variable ( pageBody ) : smart value =  Deze weekrapportage laat alle comments op issues zien die de afgelopen week zijn gewijzigd! Als er géén wijzigingen in kaartjes zijn doorgebracht dan is deze pagina (nog) leeg! {{#issues}} key,summary,type,created,updated,due,assignee,reporter,priority,status,resolution{{key}} Klik op mij om het commentaar van de story te zien!{{#comments}}{{/}} Datum Gebruiker Commentaar {{created.format("dd-MM-yyyy HH:mm:ss")}} {{author.displayName}} {{body.jsonEncode}} {{/}}

 

Step 7 : IF statement : 2 equals conditions : = {{webhookResponse.status}} equals 200 & {{webhookResponse.body.results}} contains myCompany

 

Step 8 (inside IF) : create variable ( pageID ) : smart value = {{webhookResponse.body.results.id}}

 

Step 9 (inside IF) : Webhook GET : url = https://confluence.mycompany.nl/rest/api/content/{{pageID}}?expand=version  : Custom body = { "status":"current" } : Wait for response: Checked

 

Step 10 (inside IF) : create variable ( pageVersion ) : smart value = {{#=}}{{webhookResponse.body.version.number}} + 1{{/}}

 

Step 11 (inside IF) : Webhook PUT : url = https://confluence.mycompany.nl/rest/api/content/{{pageID}} : Custom body = {"id":"{{pageID}}", "type":"page", "title":"{{pageTitlePOSTandPUT}}", "space":{"key":"mySpace"}, "body":{"storage":{"value": "{{pageBody}}","representation":"storage"} }, "version":{"number":{{pageVersion}} }} : Wait for response: Checked

 

Step 12 : ELSE statement : Webhook POST : url = https://confluence.mycompany.nl/rest/api/content : custom body : {"type":"page","title":"{{pageTitlePOSTandPUT}}","space":{"key":"mySpace"},"ancestors":[{"id":2756609130}],"body":{"storage":{"value":"{{pageBody}}","representation":"storage"}}} : Wait for response NOT checked


And to describe what it is supposed to do in a more readable format:

1: run every morning at 06:00 from monday to Friday and find me all issues from my project that are currently in the active sprint

2: filter those issues so that I only have the issues that have been updated this week and have comments

3: create a variable that I can use in the URL of the rest api

4: create a variable that I can use in the body of the rest api

5: try to find the page by looking for the page title using the variable in step 3

6: create a variable that holds the body that displays the issues on the page that has to be created or updated

7: IF statement where we check if the response is OK and if there is a page returned that contains the word myCompany

8: inside the if we know the page exist, so create a variable that saves the pageID for the update call later on

9: search for the page with the ID we just found so that we can fetch the version of the page

10: create a variable where we increment the existing version with 1 so that we have a new version available for the update call

11: update the existing page by using the variables we created before, including the version, pageID and the body

12: inside the else we know the page does not exist, so create the page by using the title and body and create it inside the ancestor page


This is the audit log of the rule:

asdasdasdasd.png

As you can see it only runs once a day at 06:00. On the 25th I ran it manually once to see if it worked. It updated the already existing page and showed the jira items, table, comments etcetera. Only to dissapear after a few hours as a new empty page was recreated.

2 answers

1 accepted

0 votes
Answer accepted
Ano Niempje April 2, 2025

So I have been facing this issue for a while now. I have been told by my system administrator that they are facing some issues in our Confluence environment regarding caching and issues with the search function in calls such as the GET webhook in step 5 where I use search?

Also, even when disabling the Jira Automation rule AND removing the page in Confluence, the page is still getting recreated, so it seams that the rule is still running or maybe even restarting in the background as a proces maybe? I have also found that the older page is getting deleted before a new one is created because the recycle binnn was filled with hundres of the same page.

Anyways, I have now tried a different approach to step 5 using the query in a different manner like this:

https://confluence.mycompany.nl/rest/api/content/?title={{pageTitelGET}}


Instead of this:

https://confluence.mycompany.nl/rest/api/content/search?cql=title={{pageTitleGET}}

So far it seems to work. I will run the rule a couple of days to see if it actually works.
 

Ano Niempje April 3, 2025

This is the correct answer. After a POST and a PUT, the page has not recreated in more than 15 hours.

0 votes
Mirek
Community Champion
March 29, 2025

Hi @Ano Niempje 

Yes, your problem might be related to wrong PAGE ID.. 

You need to understand how PAGE ID is handled in Confluence (especially when there is a old version generated already). If you look at this topic you should get some information

https://community.atlassian.com/forums/Confluence-questions/how-to-get-the-static-Page-ID-of-the-quot-CURRENT-quot-Head/qaq-p/2859072

So the main thing is to make sure (debug) what ID is used in your automation. 

Ano Niempje March 31, 2025

Hi Mirek thanks for your answer.

Before diving into the ID's my rule uses, I did some tests. I created 5 different scenario's creating pages in Confluence and kept track of their ID's.

  • Scenario 1. I created a page manually through the Confluence GUI in the same ancestor folder my rule creates its pages. In 10 hours the page has not been recreated and still has the same page ID.
  • Scenario 2. I created an entirely new Jira Automation rule with just a trigger and a webhook action. I used a POST call to create a page using the Confluence REST API. I triggered the rule once and manually. The page has not been changed in 10 hours so the ID is still the same.
  • Scenario 3. I created another new Jira Automation rule just as in Scenario 2 but this time I used a PUT call to update an existing page. Same as before, no changes, and still the same ID.
  • Scenario 4. I created yet another new rule, using a POST call but this time it was not manually triggered but it was triggered by a cronjob. No changes, still the same ID.
  • Scenario 5. And my last one, a jira rule using PUT to update a page, using a cron schedule. And again, no changes and still the same ID. I ran this one a couple of times so that it had multiple versions. 

This leaves me wondering if these page ID's are even subject to change.

 

My Jira Automation rule (as described in the OP) was triggered at 06:00 this morning. Because its the first day of the week and there was no page yet, the rule used the POST call to create the page. This means no PUT call has yet been triggered to update the page. This will happen tomorrow morning at 06:00. This also means the page only has one version.

Or so I thought. Prior to last weekend, I placed a few logs in between the rule to check what would happen with the ID. I noticed something strange. The first GET request tries to find a page and if the page exists, it will go into the IF clause. And if it doesn't, the ELSE clause.

At 06:00 this morning, the page that was checked in step 3 ( Weekrapportage%20myProject.%20Week:{{now.weekOfYear}}%20Jaar:%20{{now.Year}} ) should not have existed yet. Since today is a new week (week 14). But, it returned back positive, even giving me a page ID. 

So it seems the GET request returns me a page that should not have existed yet. After that the page is succesfully (200, OK) updated by the PUT request.

Now I am wondering, either if the page exists already (maybe hidden) and if it does how is that even possible? Or is the GET request working differently than I am expecting? 

This is the entire response from the GET call including the page ID:

response: {results=[{id=2827223082, type=page, status=current, title=Weekrapportage myProject. Week:14 Jaar: 2025, position=0, restrictions={}, _links={webui=/spaces/myspace/pages/2827223082/Weekrapportage+myProject.+Week+14+Jaar+2025, tinyui=/x/KgCEq, self=https://confluence.mycompany.nl/rest/api/content/2827223082}, _expandable={container=, metadata=, extensions=, operations=, children=, history=/rest/api/content/2827223082/history, ancestors=, body=, version=, descendants=, space=/rest/api/space/myspace}}], start=0, limit=1, size=1, cqlQuery=title='Weekrapportage myProject. Week:14 Jaar: 2025', searchDuration=122, totalSize=1, _links={self=https://confluence.mycompany.nl/rest/api/content/search?cql=title=%27Weekrapportage%20myProject.%20Week%3A14%20Jaar%3A%202025%27, base=https://confluence.mycompany.nl, context=}}


Ano Niempje March 31, 2025

And for your information, the last time the rule ran, which was last Friday 06:00, the GET request found this page:

Weekrapportage myProject. Week:13 Jaar: 2025

And today was created:

Weekrapportage myProject. Week:14 Jaar: 2025

Ano Niempje March 31, 2025

Hi so I wrote a huge update post that just dissapeard from this topic for some reason. The main point that I found was that the GET request in step 3 finds the page on monday 06:00 that has yet to be created. Which is strange because on Friday Weekrapportage myProject. Week:13 Jaar: 2025 is created and on monday 06:00 Weekrapportage myProject. Week:14 Jaar: 2025 should be created. But at 06:00 it already finds the page that is not supposed to exists. How is that possible, any idea?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events