Komail
June 21, 2017, 1:49pm
1
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
https://my-dev.server.net/rest/api/content?expand=version&title=test1&spaceKey=testDocs
Where am I going wrong ?
Thanks in advance.
Komail
June 21, 2017, 4:56pm
3
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?
Komail
June 21, 2017, 11:53pm
5
Are you referring to an App Link configuration between jira and confluence ?
Komail
June 22, 2017, 8:01am
6
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
Komail
June 22, 2017, 10:07am
7
The issue was solved with the help of
https://scriptrunner.adaptavist.com/latest/jira/interacting-with-confluence-from-jira.html
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 CreateConfluencePageWikiMarkup.groovy · GitHub 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.