How to programmatically generate the tiny link of a Confluence page

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform Notice: Server and Data Center Only - This article only applies to Atlassian products on the server and data center platforms.

Purpose

Tiny links to Confluence pages are a good way to share content with other users. The tiny link is the one used when you share a page using the share button and can be retrieved when you view the page information.

Sometimes you may need to programmatically generate the tiny link for one or multiple pages from your Confluence instance. This document will guide you on this task.

Solution

The solution below is based on a Perl script. You may change it according to your need and also port it to your preferred coding language.

The main steps of the algorithm are:

  1. Convert the page ID to its byte array.
  2. Transform the byte array using the base64 encoding.
  3. Perform additional treatment on the resulting encoded string.


Perl script to create the tiny link of a Confluence page
use MIME::Base64 qw(encode_base64);

my $pageID=1234567; ### the page ID
my $connieBaseUrl = 'http://localhost:8090/confluence'; ### Confluence Base URL


my $tinyString = encode_base64(pack("L", $pageID)); ### the page ID must be encoded after converting it to a byte array
my $actualTinyString = '';
my $padding = 1;
foreach my $c (split //, $tinyString)
{
	if ($c eq '=')
	{ next; }
	if ($padding == 1 && $c eq 'A')
	{ next; }

	$padding = 0;
	if ($c eq '/')
	{
		$actualTinyString .= '-';
	}
	elsif ($c eq '+')
	{
		$actualTinyString .= '_';
	}
	elsif ($c eq "\n")
	{
		$actualTinyString .= '/';
	}
	else
	{
		$actualTinyString .= $c;
	}
}

my $tinyUrl = $connieBaseUrl . '/x/' . $actualTinyString;

print $tinyUrl . "\n";






Last modified on Nov 2, 2018

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.