Create a new page in confluence with Python

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/)

Try running with curl

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}].

Create a new page in Python

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

Create a new page in confluence with Python
Create a virtual environment with conda in Python
Create a function in Python
Create a dictionary in Python
Create a directory with python
Create a fake Minecraft server in Python with Quarry
Create a DI Container in Python
Create a virtual environment with Python!
Create a binary file in Python
Create a Kubernetes Operator in Python
Create a random string in Python
Create a list in Python with all followers on twitter
Create a child account for connect with Stripe in Python
Spiral book in Python! Python with a spiral book! (Chapter 14 ~)
Create a Python function decorator with Class
Create a new Python numerical calculation project
Build a blockchain with Python ① Create a class
Create a simple GUI app in Python
[Python] Create a virtual environment with Anaconda
Let's create a free group with Python
Page cache in Python + Flask with Flask-Caching
Create a JSON object mapper in Python
Create a word frequency counter with Python 3.4
[GPS] Create a kml file in Python
How to create a heatmap with an arbitrary domain in Python
Create a frame with transparent background with tkinter [Python]
Create a Vim + Python test environment in 1 minute
Create a GIF file using Pillow in Python
[Cloudian # 3] Try to create a new object storage bucket with Python (boto3)
[Python] Get the files in a folder with Python
Create a Python module
Create SpatiaLite in Python
Create a standard normal distribution graph in Python
Create a PDF file with a random page size
Create a New Todoist Task from Python Script
[Note] Create a one-line timezone class with python
You can easily create a GUI with Python
Create a python3 build environment with Sublime Text3
Create a color bar with Python + Qt (PySide)
Create an image with characters in python (Japanese)
Steps to create a Twitter bot with python
What's new in Python 3.5
New in Python 3.4.0 (1)-pathlib
Work in a virtual environment with Python virtualenv.
Create a decision tree from 0 with Python (1. Overview)
Create a color-specified widget with Python + Qt (PySide)
Create a datetime object from a string in Python (Python 3.3)
Create a Photoshop format file (.psd) with python
Create a package containing global commands in Python
Create a record with attachments in KINTONE using the Python requests module
Use a custom error page in python / tornado
Create a Python environment
Until you create a new app in Django
Create a MIDI file in Python using pretty_midi
Create a loop antenna pattern in Python in KiCad
Create a Python console application easily with Click
What's new in Python 3.6
[Docker] Create a jupyterLab (python) environment in 3 minutes!
Extract data from a web page with Python
How to convert / restore a string with [] in python
Playing with a user-local artificial intelligence API in Python