Anyone making JIRA rest calls using scriptrunner for jira server?

Bruce Reed February 15, 2019

I am trying to create a scriptrunner rest endpoint (server) that calls the Jira Cloud rest api to create an issue. Code that runs fine in console will not run either as a rest endpoint or as a post function. Is anyone using rest endpoints to make Jira rest calls successfully? Code snippet follows. It fails with json parse error claiming invalid characters are passed in the json input, though it is not clear on which end (the rest endpoint call or the jira api call.) Same code (minus the endpoint definition) executes flawlessly in the Console.

import ....
.
.


@BaseScript CustomEndpointDelegate delegate

doSomething(httpMethod: "GET", groups: ["jira-administrators"]) { MultivaluedMap queryParams, String body ->

def issueKey = queryParams.getFirst("issueKey").toString();

def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueObject(issueKey)

def summary = issue.getSummary()
def description = issue.getDescription()
def reporter = issue.getReporter();
def watcherManager = ComponentAccessor.getWatcherManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
def locale = ComponentAccessor.getLocaleManager().getLocaleFor(user)
def watchers = watcherManager.getWatchers(issue,locale)
def commentManager = ComponentAccessor.getCommentManager()
def comments = commentManager.getComments(issue)

final JIRA_API_URL = 'https://xxxxx.atlassian.net'

def http = new HTTPBuilder(JIRA_API_URL);
http.client.addRequestInterceptor(new HttpRequestInterceptor() {
void process(HttpRequest httpRequest, HttpContext httpContext) {
httpRequest.addHeader('Authorization', 'Basic xxxxx')
}
})

log.info("Summary: " + summary)
log.info("Description: " + description)

issueKey = null
http.request(Method.POST, ContentType.JSON) {
uri.path = '/rest/api/2/issue'
body = new JsonBuilder([
fields: [
project: [ key: "PLAC" ],
summary: summary,
description: description,
issuetype: [ name: "Bug" ]
]
])
response.success = { resp, json ->
log.warn ("Created issue: " + json.key)
issueKey = json.key
}
response.failure = { resp, json ->
log.warn("Body: " + body)
log.warn("Failed to query JIRA API: " + reader.text)
}
}

def jsonOutput = [Summary: summary , Description: description ,Reporter: reporter]
return Response.ok(new JsonBuilder(issueKey).toString()).build();
}

 

1 answer

0 votes
Bruce Reed February 19, 2019

Just an update, this seems to be a scriptrunner rest endpoint issue. The 415 response coming back appears to be caused by the POST request being made without the JSON body being passed. Confirmed this making the same call to the local jira server instead of trying Cloud. Debug logging shows that the request is seen with no body being sent.  

Bruce Reed February 19, 2019

This is not an answer. Is that only option when commenting on your own questions? Don't see a way to delete this "amswer" or add another comment. Is editing the original question the only option??

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events