How to call a Confluence Custom REST Endpoint from JIRA Custom REST Endpoint

Hi

I'd like to call a Confluence Custom REST endpoint (built using Scriptrunner for Confluence) from within a JIRA Custom REST Endpoint?

(How) can this be done?

Kind regards

Koen Gillard

 

1 answer

In the body of your Confluence REST endpoint method, you can use any valid Java/Groovy methods to call any external REST API, including those in JIRA.

The Groovy HttpBuilder library is particularly handy for making web requests, and has a RESTClient class that makes rest operations pretty simple.

Note that in most of the examples in the HttpBuilder documentation use  @Grab to pull in HttpBuilder as a dependency, but you won't need to. ScriptRunner already pulls it in, so you can just import it.

Example code:

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript

import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
 
import groovyx.net.http.RESTClient

@BaseScript CustomEndpointDelegate delegate 

doSomething( 
    httpMethod: "GET", groups: ["jira-users"] 
) { MultivaluedMap queryParams, String body -> 
    def confluence = new RESTClient( 'https://my.confluence.suf/rest/api/myCustomEndPoint')
    def response = confluence.get([:]) //simple empty get call, could replace with post, etc.
    //You'll probably need to process the data you get back from the endpoint for your return code. Here, I'll just return it "as-is"
    return Response.ok(response.data).build() 
}

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,254 views 14 20
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot