[Python] Embed a draw.io diagram into a confluence page through an API call

Discussão em 'Python' iniciado por Stack, Abril 30, 2025.

  1. Stack

    Stack Membro Participativo

    I got this python code that creates a new page in confluence through the API. Works fine. But i would also like to embed a draw.io diagram into that same page, with this script. The diagram could for this example be a drawio file in a local folder, eg next to the below python script.


    # -*- coding: utf-8 -*-

    token = "xxxxxxxxxx"

    import requests

    pageName = input("Enter page name: ")

    headers = {
    'Content-Type': 'application/json',
    }

    json_data = {
    "ancestors":[{"id":1331789831}],
    'type': 'page',
    'title': pageName,
    'space': {
    'key': 'CPDS',
    },
    'body': {
    'storage': {
    'value': '<p>This is a new page</p>',
    'representation': 'storage',
    },
    },
    }

    response = requests.post(
    'https://org.atlassian.net/wiki/rest/api/content/',
    headers=headers,
    json=json_data,
    auth=('mr.x@org.com', token),
    )

    Continue reading...

Compartilhe esta Página