Search code examples
pluginsconfluenceatlassian-plugin-sdk

Confluence Plugin: How to create space and pages programmatically from imported CSV?


I want to add a button to the system.header/left, which I already did. And when I click that button, I want a file picker popup to choose my CSV.

From the CSV content, I want to create space and pages.

I've browsed through the documents and tutorials, but I can't find anything alike.

Could you point a direction or steps for me? At least, point me to something relevant?.


Solution

  • Here's a short overview:

    1. Your button will trigger a JavaScript.
    2. That javaScript will open a dialog window containing the form elements allowing the file upload
    3. The target of that form will be either a servlet or rest-endpoint inside your plugin. Let's assume it's a servlet.
    4. The servlet will take the submitted file, split it using the defined separator and create the page structure using the confluence API calls.
    5. And forward to the start page of your new Space.

    I'd suggest that you start with the servlet. Provide a couple of lines of test data, to check if your code creates the page structure as expected. Once this works, add the file handling part (from a dedicated html) and pass the data to your existing function. Now, you have the backend and the frontend, so rendering the dialog when your button is clicked, is pretty straight forward.

    Make sure to display the button only if the current user has the right to create a space.

    Stuff that might help you:

    Hope this helps.