How can I use Jira Automation Send Web Request to Update an Existing Confluence Page?
Asked by Julia Casciato:

I have a Jira Automation that creates a new Confluence page and this works well, but I want to edit/add content to an existing Confluence page with a web request.

I'm running into an issue where my original content on the page is completely deleted, but I only want to add content, not remove it. Is this possible?

I'm using a PUT method with Custom data request body:  

{ "version":  
{ "number": "{{#=}}{{webResponse.body.version.number}} + 1{{/}}" },  
"type": "page",  
"status":"current",  
"title": "Test Page",  
"body": {  
"storage": {  
"value": "\<p\>sample text\</p\>{{webResponse.body.body.storage.value}}",  
"representation": "storage"  
}  
}  
}


Answers:
author: Rick Westbrock
body: From what I have seen there is no way to add content to an existing page. Instead you would have to retrieve the current body of the page into a variable, update the variable to insert the additional content then make the API call to Confluence passing the modified body content to update the page.

This is a technical constraint that we ran into in the past and it's unfortunate that they don't provide an API to append to the end of the page body.

comments: author: Julia Casciato
body: Do you know how I could retrieve the current body and set as a variable to reuse?

And I agree, it would be super useful if they had an API call for this.


author: Rick Westbrock
body: The [Get page by id](https://developer.atlassian.com/cloud/confluence/rest/v2/api-group-page/#api-pages-id-get) API will return a **body** element which has three child elements:

* storage
* atlas_doc_format
* view

Each of those children has two child elements (string):

* representation
* value

It looks like the [Get pages](https://developer.atlassian.com/cloud/confluence/rest/v2/api-group-page/#api-pages-get) API also returns the **body** element but it only has the storage and atlas_doc_format children.

I haven't personally used either of these APIs so I can't speak to how you would use the different body child elements.


author: Jyoti Mane
body: Hello [@Julia Casciato](/t5/user/viewprofilepage/user-id/5590348)

To update the existing page :-

1) you need custom field (short text type ) in your jira project to capture confluece page ID. in my case it is (issue.customfield_15715)

2)In your automation rule you first need to get the confluece page that you need to update and then PUT/update page

![automation rule to update confluence page.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/346943i66668070D6BC949A/image-size/large?v=v2&px=999 "automation rule to update confluence page.PNG")

In "PUT" web request, custom data should be like :-

{  
"id":"{{issue.customfield_15715}}",  
"version": {  
"number": {{webresponse.body.version.number.plus(1)}}  
},  
"spaceId": "space_id",  
"status": "current",  
"title": "xyz",  
"parentId":"xyz",  
"body":{  
"representation": "storage",  
"value": "\<p\> \</p\>

}

}

Also, make sure to select "Delay execution of subsequent rule actions until we've received a response for this web request"

comments: author: Julia Casciato
body: I'm not sure how to get this custom field ID for a Confluence Page. I was using the Page ID, and I realized it was missing from the second request but the same issue happens.

First request: GET

https://\[URL\].atlassian.net/wiki/rest/api/content/2641690627

Delay option is checked

Second request: PUT

https://\[URL\].atlassian.net/wiki/rest/api/content/2641690627  

{  
"id": "2641690627",  
"version": {  
"number": "{{#=}}{{webResponse.body.version.number}} + 1{{/}}"  
},  
"type": "page",  
"status":"current",  
"title": "Hotfixes 2024",  
"body": {  
"storage": {  
"value": "{{webResponse.body.body.storage.value}}\<p\>Updated Content\</p\> ",  
"representation": "storage"  
}  
}  
}


author: Rick Westbrock
body: It looks like Jyoti was suggesting that you store the Confluence page ID in the Jira custom field but I think if you already know the page ID you could just hard-code it instead.


Tags: confluence

web-request