Add Jira Link to Confluence Page Programmatically

Viewed 97

I've managed to create a confluence page with powershell programmatically. Now I want to add a link to a jira ticket inside the page.

$Headers = @{
    "Authorization" = "Basic xxxxxxxx";
    "Origin" = "https://mydomain.atlassian.net"
}

$Uri = "https://mydomain.atlassian.net/wiki/rest/api/content"

$Body = @{
    "type" = "page"
    "title" = "Test Page"
    "space" = @{
         "key" = "MYSPACE"
    }
    "ancestors" = @(
        @{
         "id" = 1234567
        }
    )
    "body" = @{
         "storage" = @{
              "value" = '<ri:shortcut ri:key="jira" ri:parameter="ISSUE-1234"/>'
              "representation" = "storage"
         }
    }
}

$Body = $Body | ConvertTo-Json 

Invoke-RestMethod -Headers $Headers -Method POST -Uri $Uri -ContentType "application/json; charset=UTF-8" -Body ([System.Text.Encoding]::UTF8.GetBytes($Body)) 

The storage format is documented here but unfortunatly the issue is not displayed on the page. It does not recognize the <ri:shortcut> element...

1 Answers

I have managed to add a link to the jira ticket via Wiki Markup

"storage" = @{
   "value" = '{jira:ISSUE-1234}'
   "representation" = "wiki"
}
Related