4 answers

1 accepted

0 vote
Steven Behnke Community Champion Jun 09, 2016

There is no built-in way to accomplish this. Since Atlassian publishes their own REST API as public, we could take advantage of that API to do this job for us. It would require scripting in whatever language someone at your company is familiar with. I can talk in pseudo code.

Our script could run a search to return some results – 

https://confluence.domain.com/rest/api/search?cql=label=badlabel

This would return a list of results. I searched for badlabel and I was returned two results, both are attachments. This list is paginated so we only could receive twenty-five pages at a time, at which point we'd have to pass the &start=25 parameter to indicate where to start the results. We might also want to limit results to &type=attachment. I included an example of my results below.

Results are returned in an array, so we'd like to obtain each content's ID.

{  
  results:[  
    {  
      content:{  
        id:"att37029975",
        type:"attachment",
        title:"image2015-10-15 9:55:5.png",
        _links:{  
          webui:"/display/~steve/Using+Transitions+to+set+Resolution?preview=%2F37029969%2F37029975%2Fimage2015-10-15+9%3A55%3A5.png",
          self:"https://confluence.domain.com/rest/api/content/att37029975"
        },
        _expandable:{  
          container:"",
          metadata:"",
          extensions:"",
          operations:"",
          children:"",
          history:"/rest/api/content/att37029975/history",
          ancestors:"",
          body:"",
          version:"",
          descendants:"",
          space:"/rest/api/space/~steve"
        }
      },
      title:"image2015-10-15 9:55:5.png",
      excerpt:"badlabel",
      url:"/display/~steve/Using+Transitions+to+set+Resolution?preview=%2F37029969%2F37029975%2Fimage2015-10-15+9%3A55%3A5.png",
      resultParentContainer:{  
        title:"Using Transitions to set Resolution",
        displayUrl:"/display/~steve/Using+Transitions+to+set+Resolution"
      },
      resultGlobalContainer:{  
        title:"Steve Behnke",
        displayUrl:"/display/~steve"
      },
      entityType:"content",
      iconCssClass:"icon-file-image",
      lastModified:"2015-10-15T09:55:05.000-07:00",
      friendlyLastModified:"Oct 15, 2015"
    },
    {  
      content:{  
        id:"att37029973",
        type:"attachment",
        title:"image2015-10-15 9:54:19.png",
        _links:{  
          webui:"/display/~steve/Using+Transitions+to+set+Resolution?preview=%2F37029969%2F37029973%2Fimage2015-10-15+9%3A54%3A19.png",
          self:"https://confluence.domain.com/rest/api/content/att37029973"
        },
        _expandable:{  
          container:"",
          metadata:"",
          extensions:"",
          operations:"",
          children:"",
          history:"/rest/api/content/att37029973/history",
          ancestors:"",
          body:"",
          version:"",
          descendants:"",
          space:"/rest/api/space/~steve"
        }
      },
      title:"image2015-10-15 9:54:19.png",
      excerpt:"badlabel",
      url:"/display/~steve/Using+Transitions+to+set+Resolution?preview=%2F37029969%2F37029973%2Fimage2015-10-15+9%3A54%3A19.png",
      resultParentContainer:{  
        title:"Using Transitions to set Resolution",
        displayUrl:"/display/~steve/Using+Transitions+to+set+Resolution"
      },
      resultGlobalContainer:{  
        title:"Steve Behnke",
        displayUrl:"/display/~steve"
      },
      entityType:"content",
      iconCssClass:"icon-file-image",
      lastModified:"2015-10-15T09:54:20.000-07:00",
      friendlyLastModified:"Oct 15, 2015"
    }
  ],
  start:0,
  limit:25,
  size:2,
  totalSize:2,
  cqlQuery:"label=badlabel",
  searchDuration:58,
  _links:{  
    base:"https://confluence.domain.com",
    context:""
  }
}

We will then loop through all attachment ID's we received. First we should add the new label. If we use a program like CURL we can indicate POST and pass the label – 

curl -H "Content-Type: application/json" -X POST -d '{"prefix":"global","name":"goodLabel"}' https://confluence.domain.com/rest/api/content/att37029975/label

Then we should loop through all attachment ID's again and remove the old label – 

https://confluence.domain.com/rest/api/content/att37029975l/label?badLabel

 

Jana, Are you trying edit a label?

Apologies for my cryptic entry!  I didn't realize I was interacting with the system in this way. 

 

Yes, we've got Confluence 5.8, and I'm not a Sys Admin, just a user trying to help an internal customer who accidentally fat-fingered the wrong year for a label. It's on ~ 200 attachments, so I was hoping to find an end-user way to edit/replace her erroneous entry.  After much digging, it seems there are several add-on possibilities, but I doubt my Sys Admins will install it just for this one client.

Any insights on how I can accomplish this for a single Space w/o involving the tech team?

Thanks mucho Steven!  The client has decided to take 30 lashes and tackle the issue manually.  I sincerely appreciate your thorough and useful reply!  I'll forward the info to our Sys Admins, should this happen to another client in the future smile

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jul 10, 2018 in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

634 views 21 11
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you