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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,553,211
Community Members
 
Community Events
184
Community Groups

Using CLI's renderRequest to bulk restore deleted pages on Confluence

So yesterday a user accidentally deleted a pagetree containing 160 pages. The question was, how to restore all of those pages without having to click "Restore" and "OK" 160 times.

giphy

The answer? The venerable @Bob Swift {Appfire}'s Confluence CLI!

How to restore a single page with CLI

CLI does not have a function to restore a deleted page, but if you look at a confirmation page's source (example: https://YOURATLASSIANSITE/pages/restoretrashitem.action?key=MS&contentId=139634347), you'll see it is just making a POST request. Reading HTML source and finding POST requests is an old-school web stuff, which thankfully Atlassian has chosen to not make overly complicated with Javascript and things I don't understand. I'll include some resources about this at the end.

Endpoint

https://YOURCONFLUENCESITE/pages/dorestoretrashitem.action

Parameters

  • key
  • contentID

CLI has an incredibly useful action called renderRequest which can make that POST request using the same credentials you are using with CLI. It's kind of like using curl but without having to mess with any authentication stuff.

The full command looks like this:

acli wiki --action renderRequest --request "/pages/dorestoretrashitem.action" --requestType POST --type FORM_URL_ENCODED --requestParameters="key=MS&contentId=139634347" 

That command would restore the single page in the MS space with an ID of 139634347.

Restore ALL the pages with CLI

So we've figured out how to use renderRequest to replace a single page. But as you might recall our user accidentally deleted 160 pages. We want to restore all of those.

For that, we will use CLI's runFromTrashList allows you to iterate through every single page in the Trash, and run a given action against each one. In our case, it will be the renderRequest action that does the restore.

Here is the command: 

acli wiki --action runFromTrashList --space MS --common '-a renderRequest --request "/pages/dorestoretrashitem.action" --requestType POST --type FORM_URL_ENCODED --requestParameters=key=MS&contentId=@contentId@'

So then, we are looking for all trashed pages in the MS space, and running the same renderRequest command, replacing contentId with each page in turn. 

Sharp-eyed readers will notice that the requestParameters are not double-quoted in the this command. It's... a quoting thing. I don't fully understand it, but at least on a Mac, it seems to have worked. You may need to play around with different quoting mechanisms if you run into problems, which leads us to this last bit:

You really should TEST THIS ON A DEVELOPMENT SYSTEM before trying it on Production. (Although this is a restore operation, so the worst thing that happens is you don't restore the page and have to go and figure out what went wrong.)

Sidenotes

Hierarchy

One bummer about restoring pages from the trash is that they end up at the root level of the space. As the documentation advises, you or the user will need to go to Space Tools > Reorder Pages to drag all of the restored pages back into the hierarchy, which yeah, will not be fun with 160 pages.

Waaay back in 2018, @Jonathan Smith suggested:

you could also just view the hierarchy from DEV and recreate the structure in PROD.

That's good advice, if you have a DEV instance handy.

Tested on Server and Cloud

I tested this on Confluence Server and Cloud, and was happy to see that it worked on both platforms! Yay for Atlassian not changing this mechanism when they moved it to the Cloud.

Also - I just gotta say again, thank you to @Bob Swift {Appfire} for the truly amazing tool he and his team have created.

References

3 comments

Andy Gladstone
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Mar 22, 2023

@Darryl Lee thanks for this article and for turning a user mistake into a learning experience.

Like # people like this

Hi @Darryl Lee – Amelie from Appfire's product team here. Thanks for sharing this inspiring use case!

We'd love to learn more about how you're using the CLI. Would you be open to jumping on a quick call to chat about it? 

Cheers, Amelie

Like Dave Liao likes this
Dave Liao
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 04, 2023 • edited

@Darryl Lee - CLI to the rescue! 🙌

I remember useing CLI for Jira back in the day to instantiate a bunch of accounts. Such a glorious timesaver.

I now have CLI for Jira Cloud on one of my production Cloud instances. Because it's awesome.

Like # people like this

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events