Hello,
I was looking for a solution but couldn’t find it anywhere, so I’m posting my question here. If there’s an existing answer, please feel free to share the link!
I need to programmatically create draw.io diagrams. I’m retrieving data from PlantUML and converting it to Draw.io XML format. I can open the converted files in Draw.io in the browser, and everything works well.
Now, I need to edit existing pages and insert the Draw.io macro in specific locations.
From my understanding, I likely need to upload the Draw.io file first and then create a macro that references it ?
I can't seem to find a well-documented workflow for automating this process.
I’m using Python. Any help would be greatly appreciated!
nwm, i found the solution. For those that were in search.
first upload the file as atachement. i have base_url in my config dict.
def upload_file(page_id, file_path):
"""Uploads a file to Confluence as an attachment to the specified page."""
base_url = cfg["site_url"] + "/wiki"
# Define the endpoint for uploading an attachment to the page
url = f"{base_url}/rest/api/content/{page_id}/child/attachment"
# Set the file data for upload
with open(file_path, 'rb') as file_data:
files = {'file': (os.path.basename(file_path), file_data, 'application/xml')}
response = requests.post(url, headers={"X-Atlassian-Token": "no-check"}, auth=get_auth(), files=files)
then create an html snippet for draw.io and use the file name in it. (file name, not the atachement id, without path, only filename)
def generate_drawio_html(file_name):
"""Generates HTML to embed a Draw.io diagram from an attached file."""
drawio_html = f"""
<ac:structured-macro ac:name="drawio">
<ac:parameter ac:name="diagramName">{file_name}</ac:parameter>
<ac:parameter ac:name="pageSize">false</ac:parameter>
<ac:parameter ac:name="attachment">{file_name}</ac:parameter>
</ac:structured-macro>
"""
return drawio_html
then insert the snipet in your html and update the confluence page with something like
response = requests.put(url, headers=get_headers(use_admin_cookie), auth=get_auth(), json=body)
solved, archive it for future searches :)
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.