Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to import ready draw.io diagram to Confluence page using API only?

Daria Antsupova November 16, 2020

I have some process when I programmatically generate draw.io diagrams and then I need to paste these diagrams to the Confluence page. I suppose to use API only.

I realized how I can insert a diagram on page, but before I need to have it in draw.io plugin search.

So, my question about importing - how I can execute using API of Confluence  the same action as import diagrams from diagram editor:

 - add draw.io macro to the page, then click 'Edit' to launch the diagram editor.

- From there you go File -> Import.

- The XML you are importing needs to be a draw.io diagram.

1 answer

1 accepted

1 vote
Answer accepted
Boris
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 18, 2020

Hi Daria,

If you already have the diagram file, you just need to upload it to a page or blog post. You can use the rest endpoint for that. Attachment's content type needs to be "application/vnd.jgraph.mxfile" so search can pick it up.

 

Boris.

Daria Antsupova November 19, 2020

It works, thank you.

My example of code on Python:

url = CONFLUENCE_BASE_URL+'/rest/api/content/'+CONTENT_ID
headers = {"X-Atlassian-Token": "nocheck"}
files = {'file': ('diagram.drawio', open('tmp/diagram.drawio', 'rb'), 'application/vnd.jgraph.mxfile')}
requests.post(url+'/child/attachment', data=data, auth=('user', 'password'), files=files, headers=headers)
mawi May 30, 2022

Hi  @Boris Jockov _draw_io_ ( & @Daria Antsupova )!

If I update the drawio diagram via the API, will the preview (rendered image on the confluence page) that the drawio macro results in also be updated (or be updated when the page is rendered, either way so that the new diagram is used and shown) ?

BR! /marcus

David Benson _draw_io_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 31, 2022

@mawiThe PNG preview is generated on diagram save, it's a client-side operation. The diagram shown on the page view is the diagram itself, the viewer is JavaScript that loads and displays the diagram.

Like mawi likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events