Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automatically add labels to page attachments

Karrie Donbergs
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 22, 2023

Is there a way to automatically add labels to new page attachments?

I know that labels can be included with a page template, so when a new page is created in a space the page labels will carry over. Is there anything similar for page attachments?

Thank you

2 answers

0 votes
Helmy Ibrahim _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.
August 23, 2023

Hi @Karrie Donbergs

Adding on to @Aron Gombas _Midori_ 's comment - your requirement is definitely possible with ScriptRunner for Confluence Cloud.

Please follow the following steps to set it up:

  1. Create a Script Listener
  2. Listen to the 'Attachment Created' event
  3. Use the following sample script:
    attachments.each { attachment ->
    def attachmentId = attachment.idAsString

    post("/wiki/rest/api/content/${attachmentId}/label")
    .header('Content-Type', 'application/json')
    .header('Accept', 'application/json')
    .body([
    prefix: 'global',
    name: 'label-name'
    ])
    }

Currently, the script will add a label to all attachments created. Of course, you could tune the script by specifying various conditions so that it only runs when you want it to.

Please let me know if you have any further questions on this.

I hope this helps!

Kind regards,
Helmy

0 votes
Aron Gombas _Midori_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 23, 2023

This use case sounds something typically solved with Confluence Automation.

But:

  1. There is an action to add labels, but it works only for pages and blog posts.
  2. And, there is no trigger "attachment created"...

So, it won't work.

If you don't mind writing Groovy code to implement this automation, then ScriptRunner could solve this for you. It isn't a very hard problem. If you are lucky, Adaptavist (the vendor of SR) will be able to give you a ready-made script for this.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events