How to create simple custom macros in Confluence Cloud

Back in 2014, I made a presentation at Atlassian Summit that I hoped would challenge people's assumptions that Confluence Cloud was limited and inflexible as a solution. In it, I talk about core Confluence features (templates, macros, permissions, and space architecture) and also the possibilities of Atlassian Connect.

Some details and features have changed since then, but for the most part, the concepts in the presentation are still valid. In particular, you can still use the Atlassian Connect framework to make simple custom macros, and you don't need to be a professional programmer either.

I thought it might be worthwhile re-sharing this again.

But I'm not a developer or programmer, how could I use Atlassian Connect?

For a simple, static content macro that doesn't have any logic or configuration required (i.e. reusable blocks of content) you only need these three things:

  1. Admin access to your Confluence Cloud instance
  2. Access to web hosting that supports HTTPS - e.g. Amazon S3 hosting is good enough https://aws.amazon.com/s3/
  3. Your custom macro code, made up of three files:
    • A special configuration file ("atlassian-connect.json")
    • A file that contains your content (e.g. "macro.xml" in the example below)
    • An image or icon to represent your macro (e.g. "icon.png" in the example below)

Those 3 files are uploaded to your hosting then installed into your Confluence Cloud instance.

The file that contains your content will be a snippet of HTML / Storage Format text. An easy way to create your content snippet is to draft it on a Confluence page, then use the view storage format tool. E.g. this content 

example-storage-format.pnglooks like this in Confluence's storage format:

<p>Hello, world!</p><ac:structured-macro ac:name="info" ac:schema-version="1" ac:macro-id="b1298625-64bf-42e8-b3bc-e3489526e9bc"><ac:rich-text-body>
<p>This is an info panel</p></ac:rich-text-body></ac:structured-macro>

An atlassian-connect.json template

You don't need to really know much about the atlassian-connect.json file, although there are lots of different configuration options if you want to learn more about it.

Here is a template you can use – I have added comments where you need to make changes to this base configuration. Once you have made you changes, you can check that your atlassian-connect.json is right using this online validation tool created by Atlassian, which is hosted at https://atlassian-connect-validator.herokuapp.com/validate

If you want to make this a block rather than inline macro, change the outputType parameter to "block".

{
"key": "A unique key for your – e.g. com-yourdomain-anameforyourmacro",
"name": "A human friendly name for your of macro",
"description": "Describe your macro – e.g. Demo add-on for the Atlassian Summit 2014.",
"baseUrl": "This is the URL where you macro code is hosted - e.g. https://mymacros3domain.s3.amazonaws.com/",
"vendor": {
"name": "Your organisation’s name",
"url": "Your organisation’s URL e.g. http://yourdomain.com"
},
"authentication": {
"type": "none"
},
"modules": {
"staticContentMacros": [
{
"url": "/macro.xml",
"outputType": "inline",
"icon": {
"width": 80,
"height": 80,
"url": "/icon.png"
},
"key": "A unique key for your macro – e.g. static-macro-homepage",
"name": {
"value": "The name of your macro"
}
}
]
}
}

How do I install and test my macro?

Initially, you can install directly by using development mode in Confluence Cloud.

However, you can then deploy as a private app via the marketplace.

You can also request a free development instance of Confluence Cloud, so you can test separately before making it available to your users.

8 comments

Vincent Mann November 26, 2019

Useful, thank you

Like James Dellow likes this
James Dellow
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 2, 2021

PS since I wrote this article, Atlassian has released a new cloud development platform, called Forge:

https://developer.atlassian.com/platform/forge/

The biggest hurdle for non-developers or power users will be installing the Forge CLI (command line interface) and using it to install your add-on. But if you can master that, you'll be able to build simple macros there instead.

Like # people like this
Philip Colmer
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.
March 5, 2021

@James Dellow I love the direction that Atlassian is taking with regards to making it easier to build apps, macros, etc.

However, I thought that the following was a little bit disappointing:

"Forge apps can't be viewed by anonymous users. To use a Forge app, you must be logged in to Confluence."

(Build a Confluence hello world app (atlassian.com))

hope that that is a temporary situation while Forge is developed, otherwise I'll have to write my custom macro with Connect and then end up with multiple development platforms still.

Like James Dellow likes this
Philip Colmer
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.
March 5, 2021

It is also worth reading Forge pricing update: free through 2023 - Forge / Forge Announcements - The Atlassian Developer Community

I sincerely hope that Forge remains free. I appreciate that there is infrastructure behind the scenes that Atlassian is paying for in order for Forge to work but I would be very disappointed if Atlassian is taking a stance of encouraging developers to move over to Forge and then suddenly starts charging for it.

Like # people like this
James Dellow
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 5, 2021

@Philip Colmer I don't have any inside information, but as it is built on top of Amazon Web Service's Lambda function, any pricing would have to be relative to that cost? You would have to think it would then be hard to justify this for private apps with low (relative) usage. A more likely scenario might be they fine-tune their usage limits. But if you are a marketplace vendor with a popular and resource-intensive app, that would be something different.

BTW you can track support for anonymous users here https://ecosystem.atlassian.net/browse/FRGE-189 (although doesn't look like much is happening on that front).

3rdjkadjk June 29, 2023

@James Dellow how did you come up with the ac:macro id (on the hello world ) is it a natural template ?because i am trying to create a user macro and i dont know where to find my exact macro id please assist

James Dellow
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 25, 2023
Matt Doar _Adaptavist_
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.
March 28, 2024

There are also apps such as ScriptRunner for Confluence Cloud that let you define custom macros

https://www.scriptrunnerhq.com/inspiration/blog/the-ultimate-scriptrunner-for-confluence-macros-cheat-sheet?

Disclaimer: I work for Adaptavist who are the ScriptRunner vendor

Like # people like this

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events