Hi, I am working within Confluence Server and would like to programmatically create a wiki page based on the values of a form I created.
What would be the best way to achieve this in Confluence? I do have the HTML macro enabled.
Should I consider JavaScript with REST API?
Thanks for any direction here!
You could certainly use the HTML macro and put some script on a Confluence page that adds a form and allows you to create a page via the REST API. I've got lots of pages in our environment where I have put custom scripting on the page. You also don't have to use the HTML macro to do this. That does open up some possible security vulnerabilities that some may not be comfortable with. In that case you could put the code in a user macro and add the macro to the page. It's the same result just maybe a little more secure.
Another option would be the ConfiForms - Data Forms & Workflows add-on. FYI, I do not work for them. That said we also have this add-on in our environment and it is quite possible the most versatile and useful add-on we have for Confluence. You can use it to create Confluence pages/blogposts, create Jira issues, send emails based on form input, create "databases" within Confluence for holding pretty much any kind of data you can imagine. And you can do all that without having to program it ... however, if you are a programmer they have programming hooks to do more advanced projects. I feel it is pretty reasonably priced too for the power that it adds to Confluence.
Thanks Davin. Below is the JS I am using to create a new page, but it errors our and returns the content from the home page. Thoughts on why it may be returning the home page?
//This creates a page in a space.
var username = "user";
var password = "user";
var jsondata = {"type":"page",
"title":"My Test Page",
"space":{"key":"MRH"}, "ancestors":{"id":"1"},
"body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}};
$.ajax ({ type: "POST",
url: "http://localhost:8090/confluence/rest/api/content/",
contentType:"application/json;
charset=utf-8",
dataType: "json",
async: false,
headers: { "Authorization": "Basic " + btoa(username+ ":" + password) },
data: JSON.stringify(jsondata),
success: function (){ alert('Page saved!'); },
error : function(xhr, errorText){ alert('Error '+ xhr.responseText); } });
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Davin. After some debugging, the issue was the POST URL for my localhost. Removed "confluence" from the path and it work as expected.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My guess it will be hard to code some Javascript into a Confluence page using the HTML macro, as you can only access the HTML body & might have problems initializing the Javascript. The JS must not conflict with the heavy JS libs Confluence is using by itself. I would probably go for a separate static html page stored on the Confluence server, using Javascript & then generate the page by using the REST API.
Best
JP
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Want to make your everyday Community actions directly contribute to reforestation? The Atlassian Community can achieve this goal by liking a post, attending an ACE, sending your peers kudos, and so much more!
Help us plant more trees
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.