I am trying to configure a rest endpoint in JIRA that will make a GET call to an external rest API for a list of selectable options (retailers). I will then use a behaviour to populate a custom field with a value selected from the list. I understand the behaviour part but I am having trouble with the REST API.
Based on examples on here, this is my script currently. I am seeing the following errors...
line 31 - no such property : text for class
line 35 no such property : full name for class
line 40 ambigious prototypes for closure
I am brand new to Groovy so I am wondering where i am going wrong if anybody can shed any light? thanks in advance!
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
githubRepoQuery(httpMethod: "GET") { MultivaluedMap queryParams ->
def query = queryParams.getFirst("query") as String
def rt = [:]
if (query) {
def httpBuilder = new HTTPBuilder("http:myurl")
def repos = httpBuilder.request(Method.GET, ContentType.JSON) {
def uri = [:]
uri.path = "mypath"
def headers = [:]
headers."User-Agent" = "My JIRA"
def response = [:]
response.failure = { resp, reader ->
log.warn("Failed to get Retailer: " + reader.text)
}
}
def repoNames = repos["items"]*."full_name"
rt = [
items: repoNames.collect { String repo ->
[
value: repo,
html : repo.replaceAll(/(?i)$query/) { "<b>${it}</b>" },
label: repo,
]
},
total: repos["total_count"],
footer: "Choose repo... (${repoNames.size()} of ${repos["total_count"]} shown...)"
]
}
return Response.ok(new JsonBuilder(rt).toString()).build()
}