How can I automatically update a Confluence page using Shell script or PYTHON
Asked by Madhu:

Could you please let me know

How can I automatically update a Confluence page using Shell script or PYTHON


Answers:
author: Dominic Lagger
body: Hi [@Madhu](/t5/user/viewprofilepage/user-id/3645865)

I'm using python with the confluence [REST API](https://docs.atlassian.com/atlassian-confluence/REST/6.6.0/). And I'm using the [requests package](https://en.wikipedia.org/wiki/Requests_(software)) for any request.

The following script just creates a new page. With this little script, you should be able to create a script, which updates some content with this [PUT request](https://docs.atlassian.com/atlassian-confluence/REST/6.6.0/#content-update).

```
newPageName = 'Atlassian Community'
url = 'URL'

user = 'user'
password = 'pw'

#-------------------------------------------------

headers = {
    'X-Atlassian-Token': 'no-check',
    'Content-Type': 'application/json'
}
auth=(user, password)


spacekey = 'key'
parentId = parentId

mypage = {"type":"page","title":""+newPageName+"","ancestors":[{"id":parentId}],"space":{"key":""+spacekey+""},"body":{"storage":{"value":"VALUE IN STORAGE FORMAT","representation":"storage"}}}
post = requests.post(url+'/rest/api/content/', data=json.dumps(mypage), auth=auth, headers=headers, verify=False)

```

If you have any questions, don't hesitate to ask.

Regards, Dominic

comments: author: Madhu
body: Will this new page added on parent page or in new location?

Could you please help.


author: Madhu
body: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: <https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings>  
warnings.warn(

This is the error which I am getting.


author: Dominic Lagger
body: The new page will be added at the location, where you defined with "*spacekey* " and "*parentID*".

The parentId is the ID from the parent page, therefore, the created page is a child of that parent page.

I don't know how to solve the problem correctly with the SSL, but you can suppress this warning with:

```
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
```


author: Madhu
body: Thanks alot for your help. I am new to python, thats why I am asking you like this.


author: Madhu
body: ```
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
```

added this too.


author: praveen.naidu
body: hi how to update confluence page in existing table can you please help on this


author: Ratnala Preethi
body: Hi @[Dominic Lagger](https://community.atlassian.com/t5/user/viewprofilepage/user-id/601600)

To update particular values in table in page, Do we need to put whole page layout in 'value' variable?

or is there any possible solution only directly put data into existing table


author: Dominic Lagger
body: You have to put the whole page into the value.

What I do, when I need to change only some values: Get the page via REST and save the storage format into a variable. Then change the storage format and put the variable into the value.


author: Ratnala Preethi
body: Thanks It helps me


Tags: questions-for-confluence

server