Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Unpublished Changes to page when trying to update it by Scriptrunner and Rest Api from Jira?

Hi all, 

I normally code some scripts in scriptrunner to get information that I then copy into pages in confluence, to obtain personalized reports, etc... Nothing strange.

In the last days, I had issues with a script in particular, when it seems that under some circumstances I'm not getting a new published pages, but only creating a draft.

The following is a modified version of the code I'm using, to explain what happens.


import groovy.xml.MarkupBuilder

//Manage Link with Confluence
import com.atlassian.applinks.api.ApplicationLink
import com.atlassian.applinks.api.ApplicationLinkService
import com.atlassian.applinks.api.application.confluence.ConfluenceApplicationType
import com.atlassian.sal.api.component.ComponentLocator
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper

//My own library to get info on space pages (number of pages in spaces, existence, current version, etc...)
import com.omt.jira.SpaziOMT

//define first option for page content
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)

//define second option for page content
def writer2 = new StringWriter()
def xml2 = new MarkupBuilder(writer2)

//Create just some text
h3("Test Update new")

//Create a table
xml2.table(class: "aui") {
thead {
tr {

// Space where to search for the page
def spaceOutput="PMO"
// Title of the page to be updated
def pageTitle = "Monthly-Worklog-Date-Expl"

//Define an object to handle methods for getting info on pages
def spaziOMT=new SpaziOMT()
//Get info on number of pages included in the space
def quantePagine=spaziOMT.quantePagine(spaceOutput)
def numPagine=quantePagine.toInteger()
//Get the id of the page to be updated
def idp=spaziOMT.idPagina(spaceOutput, pageTitle, numPagine)
//Get the version of the page to be updated
def versione=spaziOMT.versionePagina(spaceOutput, pageTitle, numPagine)
def pageVersion=versione.toInteger()

I had initially doubts on the use of an external class/method, as I'm new to this
but it actually works, I'm getting always the right page id and version,
so I know then how to build the next call by confluence api to update the page to a new version

//New connection with Confluence
def ApplicationLink getPrimaryConfluenceLink() {
def applicationLinkService = ComponentLocator.getComponent(ApplicationLinkService.class)
final ApplicationLink conflLink = applicationLinkService.getPrimaryApplicationLink(ConfluenceApplicationType.class)
def confluenceLink = getPrimaryConfluenceLink()
assert confluenceLink // must have a working app link set up
def authenticatedRequestFactory = confluenceLink.createImpersonatingAuthenticatedRequestFactory()

//Proceed just in case the page exists
if (pageVersion>=0){
//define the new version
def newPageVersion=pageVersion+1

log.warn('Versione iniziale pagina: '+ versione)
log.warn ('Versione finale pagina: '+newPageVersion)

//Params for the call
def params = [
type: "page",
version: [
title: pageTitle,
body: [
storage: [
value: writer.toString(),
//value: writer2.toString(),
representation: "storage"

.createRequest(Request.MethodType.PUT, "rest/api/content/"+idp+"?status=current") // Here you need to edit to your URL
.addHeader("Content-Type", "application/json")
.setRequestBody(new JsonBuilder(params).toString())
.execute(new ResponseHandler<Response>() {
void handle(Response response) throws ResponseException {

} else {
//La pagina non esiste, non faccio nulla
log.warn("Page doesn't exists")

return writer


If I get to the console, and run it, I get something like


which is what I need. OK, it works.

If I click another time I get 93>94, another time and get 94>95, etc... OK Almost stupid would say... :-)

But here the issue, then.

If I modify the code and simply move from

 body: [
storage: [
value: writer.toString(),
//value: writer2.toString(),
representation: "storage"


 body: [
storage: [
//value: writer.toString(),
value: writer2.toString(),
representation: "storage"

which in the end it means that I try to insert a simple table instead that some text, I'll be able to update the page just once.

The logs will show moving from 95 to 96 version, and then no more changes, even if I continue running the code. No errors, but no more updates.

If I look at the page it shows


More strange, if I modify again the code and send again the first writer to the page, it start again updating.

I'm getting crazy.

2 answers

Update. I did it in the most stupid way for now, that means I run the update twice. The first one to send text content (it makes just a blank page), and the second one to send the table.

In this way I move 2 versions forward instead than just one, but it works.

I pray for suggestions on how to write a better code... :-)

I face the exact same error as @Andrea Boerio . May anyone check this issue?

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Confluence

What do you think is the most *delightful* Confluence feature? Comment for a prize!

- Create your own custom emoji 🔥 - "Shake for Feedback" on mobile 📱 - An endless supply of GIFs via GIPHY 🤩 Is there anything quite as nice as a pleasant surprise? Comment below with what...

429 views 23 9
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you