How to access XML search request from script? Edited

I am trying to create a script that needs to process an xml output from a JQL search request.

I am having issues just reading the url, and is very likely due to permissions, but can't seem to find a way to make it work.

I am trying a simple script to test:


String xml_url = 'http://jira.my-company.com:8080/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?jqlQuery=project+%3D+T500+AND+issuetype+%3D+Task'

return xml_url.toURL().text

but get a 400 error:

2018-01-23 17:25:36,400 WARN [common.UserScriptEndpoint]: Script console script failed: java.io.IOException: Server returned HTTP response code: 400 for URL: http://jira.my-company.com:8080/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?jqlQuery=project+%3D+T500+AND+issuetype+%3D+Task at Script360.run(Script360.groovy:5)

 

I have trying passing the &?os_authType=basic and even &?os_username=un&?os_password=pwd (which I agree is not a good idea), and still same error.

If I use a non authenticated url, i.e. 'http://www.google.com', it works.

Does anyone know a reasonable way to access and read XML output from a JQL request using scripts in JIRA? 

Thanks!

 

1 answer

It's more a question than an Answer, 

But is there a reason you want your search to return an XML.

When I use Script to do an Issue search, I usually prefer to get a collection of IssueObjects

This way you don't have to deal with an unofficial way to get your issues.

Like something like this : 

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter

public static List JqlSearch(String jqlString) {
try {
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlString)
if (parseResult.isValid()) {
def result = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter()).getIssues()
return result
} else {
return null
}
}
catch (Exception e) {
}
}

 

Another solution would be to go through the Real REST API, and then convert the JSON result into XML

Like in this example

https://stackoverflow.com/questions/29937254/convert-json-to-xml-using-groovy

Thanks for your input. 

To answer your question, I am using XSLT processing to create output from XML, so I did not want to necessarily add another step to go from JSON to XML. 

Suggest an answer

Log in or Join to answer
Community showcase
Emilee Spencer
Published Friday in Marketplace Apps

Marketplace Spotlight: DeepAffects

Hello Atlassian Community! My name is Emilee, and I’m a Product Marketing Manager for the Marketplace team. Starting with this post, I'm kicking off a monthly series of Spotlights to highlight Ma...

50 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot