How do you write a power script to show metadata about all the pages in a space?

Michael Zhao October 12, 2023

Looking for help with writing a macro to audit the pages within a space in a Confluence instance, showing the following fields: 

  • Page name
  • Link to page
  • Last updated/modified date
  • Original Poster (creator) 

Previous implementation was deployed on a created page within the space being audited, and showed a table of all the pages within the space. 

3 answers

1 accepted

0 votes
Answer accepted
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.
October 14, 2023

@Michael Zhao - hi Michael!

Are you actually looking for a Power Scripts for Confluence script?*

If no, or  it's not imperative that we use PS, consider a custom user macro:

  1. See this example: https://community.atlassian.com/t5/Confluence-questions/Macro-that-lists-all-pages-for-the-specified-space-with-their/qaq-p/1452170
  2. ...and consider THIS example if you want to extend the first example: https://community.atlassian.com/t5/Confluence-articles/A-Child-Page-by-Label-User-Macro/ba-p/1502246

* today I learned that PS for Confluence is a thing! Awesome.

Michael Zhao October 14, 2023

Definitely looks like it matches what I'm looking for. Talked to a former colleague who mentioned the previous iteration was built with Power Scripts, but more looking for a starting point to build it out in a different organizational context, so not a requirement.

 

Thanks again!

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.
October 14, 2023

@Michael Zhao - FYI if you have an existing PS script, you may be able to extend it using these variables: https://appfire.atlassian.net/wiki/spaces/PSCONF/pages/15306098/Standard+Variables

0 votes
Tom_Carrott_Adaptavist
Atlassian Partner
May 1, 2024

Hey @Michael Zhao 

I'm a PM in Kolekti (Part of the Adaptavist Group) and we currently have a new discovery idea in the works, a Confluence Cloud add-on designed to streamline multi-space metadata and content management for Confluence Cloud users!

The app aims to streamline content management for Confluence Cloud by offering a centralised hub for all your pages. Imagine a "panoramic view" where you can easily:

  • Find any page: Effortlessly locate specific content across your entire Confluence instance.
  • Manage at a glance: View key information across multiple spaces like last edited, created date, page owner, labels, status etc.
  • Organise effortlessly: Move pages between spaces, copy, archive, or delete them in bulk - no technical skills needed!
  • Maintain control: Edit metadata fields like labels and permissions for multiple pages simultaneously

Your use case sounds very interesting... would you be interested in a conversation? 

0 votes
Roma Bubyakin _Wombats Corp_
Contributor
October 17, 2023

Hi @Dave Liao 

In case you are using Cloud

It might also be worth to take a look into our (Wombats Corp) app User Macro for Confluence Cloud

You can create numerous dynamic macros from the admin panel.

For your exact use case template would be the following:

## get pages in the current space
#set($sort = "-modified-date") ## order by modified date DESC
#set($status = "current") ## skip archived, deleted, and drafted
#set($limit = 250) ## increase pages limit to maximum

#set($url = "/wiki/api/v2/spaces/${space.id}/pages?sort=${sort}&status=${status}&limit=${limit}")

#set($response = $ConfluenceManager.get($url))

## Use of Atlassian UI (AUI) sortable table
<table class="aui aui-table-sortable">
<thead>
<tr>
<th>Title</th>
<th>Link to Page</th>
<th>Last updated</th>
<th>Original Poster</th>
</tr>
</thead>
<tbody>

## iterate through results of pages
#foreach($page in $response.results)
<tr>
<td>${page.title}</td>
<td><a href="${baseUrl}${page._links.webui}">${page._links.webui}</a></td>

## Convert datetime to date
## "2024-02-13T12:12:31.528Z" -> "2024-02-13"
#set($createdAt = $StringUtils.substringBefore($page.version.createdAt, "T"))
<td>${createdAt}</td>

## Retrieve additional information by accountId
#set ( $user = $ConfluenceManager.get("/wiki/rest/api/user?accountId=$page.authorId") )
<td>$user.displayName</td>
</tr>
#end
</tbody>
</table>

 

The result would be like this:
Show metadata about all the pages in a space.png

Regards, Roman

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events