Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,560,362
Community Members
 
Community Events
185
Community Groups

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 Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events