Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Custom picker using REST API - 404 after selecting value

Miroslav Kralik
Contributor
October 29, 2024

I am trying to create a custom picker using Jira Cloud REST API to fetch and return specific issues based on JQL filter. 

What works: 

  • authentication
  • fetching issues
  • searching and displaying results in the picker

What does not work

  • "click" event: after I click on the picker option, I get an error that the selected issue does not exist (404). I tested the endpoint via postman and it should work just fine.

 

Questions

  • Is there a way to troubleshoot what endpoint and what payload does the Scriptrunner execute?
  • Any idea, what's wrong with the getItemFromId method?

 

Screenshot 2024-10-29 at 15.49.21.pngScreenshot 2024-10-29 at 16.20.00.png

 

Screenshot 2024-10-29 at 16.24.13.png


 

import com.onresolve.scriptrunner.canned.jira.fields.model.PickerOption

import groovyx.net.http.ContentType

import groovyx.net.http.HTTPBuilder

import groovyx.net.http.Method


HTTPBuilder getHttpBuilder() {

new HTTPBuilder("https://mycompany.atlassian.net/rest/api/3/")

}


def fields = "summary"


search = { String inputValue ->

def jql= "project=DEVEX"

if(!inputValue.blank) jql += " AND summary ~ $inputValue"


def username = "my_email"

def password = "my_password"


def response = httpBuilder.request(Method.GET, ContentType.JSON) {

headers."Authorization" = "Basic ${"${username}:${password}".bytes.encodeBase64()}"

headers."User-Agent" = "Jira Data Center"

headers."Acceot" = "application/json"

uri.path = 'search'

uri.query = [jql: jql, fields: fields]

response.failure = { null }

} as Map


// issues[0].key => KEY-1

// issues[0].fields.summary => My issue

// issues[0].fields.customfield_10150.displayName => Last Name, First Name


response.issues


}



toOption = { Map<String, String> issue, Closure highlight ->

new PickerOption(

value: issue.key,

label: "${issue.key}: ${issue['fields']['summary']}",

html: "${highlight("${issue.key}: ${issue['fields']['summary']}", false)}",

)

}



getItemFromId = { String key ->

httpBuilder.request(Method.GET, ContentType.JSON) {

uri.path = "issue/$key"

uri.query = [fields: fields]

response.failure = { null }

}

}



renderItemViewHtml = { Map issue ->

"${issue.key}: ${issue['fields']['summary']}"

}



renderItemTextOnlyValue = renderItemViewHtml

 

0 comments

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events