I'm using Confluence for business, but I wondered if I could manage to create pages automatically, so I searched for an API, so I immediately tried using it. Below is a sample API, which is curl but you can try it out right away. Confluence REST API Examples See here [https://docs.atlassian.com/atlassian-confluence/REST/latest/)
First, try making it with curl as shown in the sample.
curl -u username:password -X POST -H 'Content-Type: application/json' -d'{"type":"page","title":"new page","space":{"key":"TST"},"body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}}' http://your_confluence_domain/rest/api/content/
If you want to make it as a child page somewhere, here
curl -u username:password -X POST -H 'Content-Type: application/json' -d'{"type":"page","title":"new page", "ancestors":[{"id":1234}], "space":{"key":"TST"},"body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}}' http://your_confluence_domain/rest/api/content/
Apparently, the parent page is specified by " ancestors ": [{" id ": 1234}]
.
The parameters to be specified are the same as for curl. ※Excerpt
import requests
def main():
payload = {
'type': 'page',
'title': 'new page',
'space': {
'key': 'TST'
},
'ancestors': [{'id': 1234}],
'body': {
'storage': {
'value': '<p>This is a new page</p>,
'representation': "storage"
}
}
}
headers = {
'Content-Type': 'application/json',
'Authorization': 'Basic ' + base64.b64encode('username:password')
}
url = 'http://your_confluence_domain/rest/api/content/'
response = requests.post(url, data = json.dumps(reqdata), headers = headers)
response.raise_for_status()
Recommended Posts