Skip to content

Instantly share code, notes, and snippets.

@kmccarth
Last active April 12, 2023 00:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kmccarth/7c6bb4fe4b2fdf107c222d7e9cd61fab to your computer and use it in GitHub Desktop.
Save kmccarth/7c6bb4fe4b2fdf107c222d7e9cd61fab to your computer and use it in GitHub Desktop.
I needed to export our Confluence instance, here was a super easy way to get all pages, and create a file for each page (named after the article) and the page's resulting HTML.
#!/bin/bash
export CONFLUENCE_USERNAME="your_username"
export CONFLUENCE_PASSWORD="your_password"
function get_page_html()
{
mkdir ~/confluence;
result=$(curl --request GET \
--url "https://ventureapp.atlassian.net/wiki/rest/api/content/$1/?expand=body.export_view" \
--user $CONFLUENCE_USERNAME:$CONFLUENCE_PASSWORD \
--header 'Accept: application/json' \
--header 'Cache-Control: no-cache' \
--header 'Content-Type: application/json');
title=$(echo $result | jq '.title' | sed 's/\"//g' | sed 's/[][*]\|[[:space:]]//g' | sed "s/ /-/g");
file=~/confluence/$title.html
touch $file;
body=$(echo $result | jq '.body.export_view.value' | sed 's/^.\(.*\).$/\1/');
echo $body > $file;
}
function listpages()
{
limit=500;
loops=1;
for ((i=0;i<=$loops;i++)); do
start=$( expr $i '*' "$limit" )
results=$(curl --request GET \
--url "https://ventureapp.atlassian.net/wiki/rest/api/content/?limit=$limit&start=$start" \
--user $CONFLUENCE_USERNAME:$CONFLUENCE_PASSWORD \
--header 'Accept: application/json' \
--header 'Cache-Control: no-cache' \
--header 'Content-Type: application/json');
ID=$results | jq '.results[] | .id' | sed 's/\"//g' >> ~/repos/hqo/json.txt;
get_page_html $ID;
done
}
listpages();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment