Action
Post to Confluence
UPDATES
about 1 month ago
Removed settings from the script code
This action allows yout to publish a draft to Confluence Cloud.
Draft will be converted to HTML before publishing, so you’ll get a nicely formatted Confluence page.
Settings instructions:
- Atlassian_Domain:
https://mycompany.atlassian.net
- Atlassian_Account: Atlassian account username
- Atlassian_APIToken: You can create an API Token from your account page in the security section
- Atlassian_SpaceId: The space ID is NOT your space key. To get the space id, visit this URL while logged in:
https://MYCOMPANY.atlassian.net/wiki/rest/api/space/SPACE_KEY
- Atlassian_ParentPage: Parent page id for the new page
Steps
-
defineTemplateTag
name Atlassian_Domain
template -
defineTemplateTag
name Atlassian_Account
template -
defineTemplateTag
name Atlassian_APIToken
template -
defineTemplateTag
name Atlassian_SpaceId
template -
defineTemplateTag
name Atlassian_ParentPage
template -
script
// ----- Confluence API endpoint and authentication var domain = draft.processTemplate("[[Atlassian_Domain]]"); var apiUsr = draft.processTemplate("[[Atlassian_Account]]"); var apiToken = draft.processTemplate("[[Atlassian_APIToken]]"); // ----- Page coordinates var spaceId = draft.processTemplate("[[Atlassian_SpaceId]]"); var parentPage = draft.processTemplate("[[Atlassian_ParentPage]]"); // ------------------------------------------------------------------ var apiUrl = domain + "/wiki/api/v2/pages"; var authorizationToken = "Basic " + Base64.encode(apiUsr + ":" + apiToken) // Get the note content from the current draft var noteTitle = draft.displayTitle var noteContent = draft.processTemplate("[[trimmed_body]]") var mmd = MultiMarkdown.create(); mmd.format = "html"; mmd.criticMarkup = true; var noteContentHtml = mmd.render(noteContent); var payload = { "spaceId": spaceId, "status": "current", "title": noteTitle, "parentId": parentPage, "body": { "representation": "storage", "value": noteContentHtml } }; var http = HTTP.create(); var response = http.request({ "url": apiUrl, "method": "POST", "encoding": "json", "data": payload, "headers": { "Authorization": authorizationToken, "Content-Type": "application/json", "Accept": "application/json" } }); // Process the response if (response.success) { app.displaySuccessMessage("Note published to Confluence successfully!") } else { app.displayErrorMessage(JSON.parse(response.responseText).errors[0].title) }
Options
-
After Success Default Notification None Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.