Unable to get response from Confluence server with REST API

I have the below groovy code as a post function in jira

import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpRequest;
import org.apache.http.protocol.HttpContext;  
import groovyx.net.http.RESTClient
def http = new RESTClient('https://my-dev.server.net')

http.client.addRequestInterceptor(new HttpRequestInterceptor() {
    void process(HttpRequest httpRequest, HttpContext httpContext) {
        httpRequest.addHeader('Authorization', 'Basic ' + 'admin:admin'.bytes.encodeBase64().toString())

def response = http.get(path: "/rest/api/content?expand=version&title=testpage1&spaceKey=testDocs")

println response.data.text

The error is

groovyx.net.http.HttpResponseException: Not Found

The same url when queried using the browser/POSTMAN returns a proper response


Where am I going wrong ?

Thanks in advance.

Is this scriptrunner? https://scriptrunner.adaptavist.com/latest/jira/interacting-with-confluence-from-jira.html

1 Like

Using jiras built in custom script functionality to execute a groovy script , I am using jira 6.3.9.

Might want to look into that. Don’t think that’s a thing. Does your jira server have a route to the confluence server?

Are you referring to an App Link configuration between jira and confluence ?

Just tested the code with a public rest api and it works

def wikiURL = "https://en.wikipedia.org/api/rest_v1/page/title/Google"
def http = new RESTClient(wikiURL);
http.client.addRequestInterceptor(new HttpRequestInterceptor() {
    void process(HttpRequest httpRequest, HttpContext httpContext) {
def response = http.get(path: wikiURL)
println response.data.items

@justin_shapiro: The app link between jira and confluence is configured

The issue was solved with the help of
It has 3 main steps

  • retrieve Confluence application link

  • set up parameters to pass to the REST API call which will create the Confluence page, eg page title and content

  • use the REST API to create the page

I was missing out on getting the proper confluence application link. I followed the code on https://gist.github.com/jechlin/cf9ccb524918993872d5 for my use case and it worked !

Thanks @sfbehnke for the link and @justin_shapiro for the guidance !

Oh yeah I had a post-function that would create “Quotes” in confluence based on the quote issuetype in JIRA and it pulled all the data off the ticket. Very cool. :slight_smile: