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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.