It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Can I get a Page from a tiny url in a user macro? Edited

Damon Osgood Apr 10, 2018

In a Confluence user macro, I have access to the Tiny URL of a Confluence page. I'd like to get the ID of that Page, ultimately so I can iterate the descendents of that Page. So, something like:

#set($url='http://localhost/x/9_PXEg')
#set($page=$GET_PAGE($url))
#set($descendents=$pageManager.getDescendents($page))
## use $descendents...

 

I *thought* that the final six characters of the tiny url were the page id, Base64 encoded. But this does not work:

 

#set($url='http://localhost/x/9_PXEg')
#set($base64=$stringUtils.substringAfterLast($url, "/"))
#set($idString=$generalUtil.base64Decode($base64))

$idString

The Base64 decoder cannot handle the six character string, even though it was generated by the same instance of Confluence. So it seems it's not simply a Base64 number.

 

2 answers

0 votes
Stephen Deutsch Apr 11, 2018

Hi Damon,

You're on the right track... they are base64 encoded, but they are encoded as a bytestring. You may have some luck referencing this answer:

https://community.atlassian.com/t5/Confluence-questions/Is-there-a-way-to-update-tiny-links-when-migrating-a-confluence/qaq-p/713854

or maybe if I have time later today I can try to reimplement in a user macro.

0 votes
Damon Osgood Apr 11, 2018 • edited

I found a solution. It's rather ugly, but it works. Suggestions for streamlining this would be very welcome!

 

#set($url="http://localhost/x/9_PXEg")

#set($tinyUrlClass=$action.class.forName('com.atlassian.confluence.pages.TinyUrl'))

#set($stringClass=$action.class.forName('java.lang.String'))

#set($constructor=$tinyUrlClass.getConstructor($stringClass))


#set($identifier=$stringUtils.substringAfterLast($url, "/"))

#set($tinyUrl=$constructor.newInstance($identifier))

#set($pageId=$tinyUrl.getPageId())

#set($page=$pageManager.getPage($pageId))

#set($descendents=$pageManager.getDescendents($page))


 

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Confluence

6 Awesome Ways to Apply Trello, JIRA and Confluence to your Project

I attended  Atlassian Summit 2019  and learned a lot from the presenters, attendees and knowledgeable Atlassian product managers. The presentations I attended focused on applying Agile, pla...

1,037 views 7 17
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you