Confluence Cloud macro adding attachment to the page

hi all,

My trivial macro allows users to search for images via external API, and then places it on a confluence page. I have staticContentMacros with editor and it works. StaticContentMacro renders an <ac:image><ri:url>.

Question: is it possible for a macro to inject and display a page attachment instead? Same way as default “Insert Image” action does?

I was looking around AP.confluence to call something other than saveMacro. I was also checking Confluence REST API, but getting page content to alter it and save back doesn’t sound like a safe idea. Especially that I’m not aware of location in which user triggered the macro.

Ideas? Or not possible?

Dear @szn,

of course it is possible. In case you are using a standard macro editor you could try it with an attachment macro parameter. In case you are using your own macro editor you may use the REST interface to search for attachments and then use the entry to link to your image.

Kind regards


Thank you @andreas1 for your reply. I am using a custom editor, but let’s start from a standard editor perspective to see how it works.

The example link you suggested points to a list of available parameter types. And there is a attachment type parameter. For me this seems to allow a macro to display an autocomplete field for search on attachment filenames. In other words, if a have an attachment already embedded in the page, I should be able to find it.

I did a small experiment with dynamicContentMacros[0].parameters.type == 'attachment'. I attached one image to the page, and triggered my macro. It shows an attachment dropdown list in a default editor but it is empty. But this is less important.

My goal was to achieve the opposite. I am not looking for an ability to query for existing attachments in a page from a macro editor perspective. I want to attach and display inline new image taken “from the outside”. Same way as built in Insert Image function does.

Should I expect, that filling in an ‘attachment’ parameter in a custom editor will actually insert it into a page? Any Confluence Cloud documentation about it?

Dear @szn,

I thought this sentence means that you want to query existing images:

Yes, you can attach an image from the outside to a page. In case you want to do it on the client side you will need a little JS to load the external image and then upload it. The response after the upload gives you lots of information including the download link which you can use when rendering your static macro.

Kind regards