Action
Post to Confluence
Posted by melandriAlessandro ,
Last update
30 days ago
UPDATES
30 days ago
Replaced template tags with Configured Values.
You’ll need at least Drafts 47 to use this action.
30 days ago
Replaced template tags with Configured Values.
You’ll need at least Drafts 47 to use this action.
4 months ago
Moved login informations (host, username and api token) to Drafts Credentials
11 months ago
Removed settings from the script code
This action allows you 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:
On first run, the action will prompt for authentication infos and save them to Draft credentials
- 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
-
configurationKey
name Atlassian SpaceId
key AtlassianSpaceId
-
configurationKey
name Atlassian ParentPage
key AtlassianParentPage
-
script
// ----- Confluence API endpoint and authentication let credential = Credential.createWithHostUsernamePassword("ConfluenceCloud", "Confluence credentials"); credential.addTextField("host", "Confluence Domain"); credential.addTextField("username", "Confluence Username"); credential.addPasswordField("password", "Confluence API Token"); credential.authorize(); // ------------------------------------------------------------------ var spaceId = context.configuredValues["AtlassianSpaceId"]; var parentPage = context.configuredValues["AtlassianParentPage"]; // ------------------------------------------------------------------ var apiUrl = "https://" + credential.getValue("host") + "/wiki/api/v2/pages"; var authorizationToken = "Basic " + Base64.encode(credential.getValue("username") + ":" + credential.getValue("password")) // 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") } 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.