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

Upload local markdown file via Confluence REST API (PowerShell)

Edited
Antti Nousiainen
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
Nov 21, 2023

I'm working on a PowerShell script that would allow me to upload a local Markdown file from a path, and create a Confluence sub-page under a parent page and display the file's contents as Markdown.

So far I'm able to create the sub-page under whatever parent or space I like, however, the Markdown isn't displaying as Markdown, just raw text.

I tried going over the REST API docs and tried using both representation types: storage (errors out) and wiki (works but doesn't shows as raw text).

Any ideas on what I'm doing wrong? Been stuck a while on this one...

Here's how the user inputs parameters for the script:

New-MarkdownSubPage -ConfluenceUrl "https://confluence.domain.corp" -SpaceKey "SPACE1" -PageTitle "Parent_Page" -FilePath "C:\Temp\markdown.md"

 

And here's the relevant bits of the script:

$parentPageUri = "$ConfluenceUrl/rest/api/content?spaceKey=$SpaceKey&title=$PageTitle"
$parentPage = Invoke-ConfluenceAPI -Uri $parentPageUri -Method "GET"
$parentPageId = $parentPage.results.id
$fileContent = Get-Content -Path $FilePath -Raw
$fileName = (Get-Item -Path $FilePath).Name

$pageData = @{
type      = "page"
title     = $fileName
space     = @{ key = $SpaceKey }
ancestors = @(@{ id = $parentPageId })
body      = @{
storage = @{
value = $fileContent
representation = "wiki"
}
}
} | ConvertTo-Json -Depth 100

$createPageUri = "$ConfluenceUrl/rest/api/content"
$createdPage = Invoke-ConfluenceAPI -Uri $createPageUri -Method "POST" -Body $pageData

 

1 answer

You need to convert the Markdown to Confluence storage Format. Maybe try an addon  https://marketplace.atlassian.com/apps/1211438/markdown-html-plantuml-latex-diagrams-open-api-mermaid 

Maybe a Library for this exists?

Regards Benno

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events