Page tree
Skip to end of metadata
Go to start of metadata

Eventhough Confluence has a good and well documented REST API for integration with other systems it is sometimes necessary to create a custom REST endpoint.

There are two ways you can do this as I see it:

  1. Build your Confluence add-on.
  2. Create a script REST endpoint with Scriptrunner add-on from Adaptavist.

I prefer option number two as I have Scriptrunner for Confluence installed. It is a extremely useful add-on for Confluence and JIRA. Very powerful. Check the documentation for Confluence REST endpoints here.

The REST endpoint will display a simple HTTP 200 with some JSON output if all is OK. All you have to do is call the endpoint as a HTTP get request which can be done from a browser. No need for authentication in this code as we do not display sensitive information when returning the response. Nice and simple.

REST endpoint configuration

Go to "REST Endpoints" in the Confluence administration interface.

  1. Click "Add New item". 
  2. Click "Custom endpoint". 
  3. Type a note and insert the code below.
  4. Click "Add"

Check screenshot to the right

Screenshot REST endpoint

The code

 * Expose a simple healt endpoint with status, application and version info
 * Exposed at <confluencebaseurl>/rest/scriptrunner/latest/custom/health
 * */
import com.atlassian.confluence.util.GeneralUtil
import groovy.json.JsonBuilder
import groovy.transform.BaseScript

@BaseScript CustomEndpointDelegate delegate

// Allow all
def allowedGroups = []
// Create response based on GET
health(httpMethod: "GET", "groups": allowedGroups) { MultivaluedMap queryParams, String body ->
    def versionNumber = GeneralUtil.getVersionNumber()
    def result = [
            status: "OK",
            application: "Confluence",
            version: versionNumber
    // Build response
    return Response.ok(new JsonBuilder(result).toString()).build()

The endpoint can now be accessed at "<confluencebaseurl>/rest/scriptrunner/latest/custom/health"