JiraRestClient search returnes no results for JQL query
Asked Answered
S

2

7

I am facing issue related to Search JQL. I am using the query

(issuefunction in issuesInEpics('key = ABCD-24911') and issuetype=Feature)

In Jira it is returning some record but when I am using this query in JiraRestClient it is not working, but instead returning zero records.

It is working fine for below query :

issuefunction in issuesInEpics("resolution is not empty") and issuetype = Feature

Code Snippet:

String query="issuefunction in issuesInEpics('key = ABCD-24911') and issuetype=Feature";    
Integer resultsLength=50,startAt=0;        
JiraRestClient.getSearchClient().searchJql(query,resultsLength,startAt,null);

My Maven Dependency:

<dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-rest-java-client-api</artifactId>
        <version>4.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-rest-java-client-core</artifactId>
        <version>4.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.atlassian.fugue</groupId>
        <artifactId>fugue</artifactId>
        <version>2.2.1</version>
    </dependency>
    <dependency>
    <groupId>com.atlassian.httpclient</groupId>
    <artifactId>atlassian-httpclient-spi</artifactId>
    <version>0.17.0-m01</version>
    </dependency>

Anyone please help me to find the solution.

Samaria answered 17/9, 2019 at 12:19 Comment(17)
Removed atlassian tag - see meta.#351980Ani
Check the HTTP access logs to verify if the query received by jira matches the one you sent. Maybe there is an issue with the URL encodingGore
Are you login REST client with same user as when you are using UI?Unintelligible
@Unintelligible It is working fine for below query : issuefunction in issuesInEpics("resolution is not empty") and issuetype = FeatureSamaria
Could you please try to encode the query param ? I would do something like String query = URLEncoder.encode("issuefunction in issuesInEpics('key = ABCD-24911') and issuetype=Feature", "UTF-8");Marbles
@user2683814 thanks for answering will try thisSamaria
Url encoding is already taken care by jira rest client. I was able to pull search results just fine with <dependency> <groupId>com.atlassian.jira</groupId> <artifactId>jira-rest-java-client-core</artifactId> <version>4.0.0</version> </dependency> <dependency> <groupId>com.atlassian.fugue</groupId> <artifactId>fugue</artifactId> <version>2.6.1</version> </dependency>. Not able to reproduce the issue in my test. Are you sure you have the right search criteria ?Marbles
@user2683814 thanks for answering I have tried both String query = URLEncoder.encode("issuefunction in issuesInEpics('key = ABCD-24911') and issuetype=Feature", "UTF-8"); and also add this maven dependency both are not workingSamaria
@user2683814 For URLEncoder it is giving me RestClientException[ErrorCollection{status=400, errors={}, errorMessages=[Error in the JQL Query: The character '+' is a reserved JQL character. You must enclose it in a string or use the escape '\u002b' instead. (line 1, character 14)]}]Samaria
@user2683814 Can you share your source code how you are implementedSamaria
I used the same code. Something like try(JiraRestClient client = new AsynchronousJiraRestClientFactory().createWithBasicHttpAuthentication(uri, username, password) {String query="issuefunction in issuesInEpics('key = ABCD-24911') and issuetype=Feature"; Integer resultsLength=50,startAt=0; JiraRestClient.getSearchClient().searchJql(query,resultsLength,startAt,null).claim.getIssues().forEach(issue->System.out.println(issue.getKey()));} Could you share the exact search criteria that you use instead of one in the post ?Marbles
@user2683814 It is working fine. (issuefunction in issuesInEpics("resolution is not empty") and issuetype = Feature) but the above query is not workingSamaria
@user2683814 I am not getting which search criteria you are talking aboutSamaria
Sorry, I mean whatever goes inside parenthesis here issuesInEpics(). It looks like there is problem with search criteria since you get zero results back. Are your sure the user id have proper access to the project you are querying ? have you tried to query the any other projects ?Marbles
@user2683814 Thanks Same Jira credential use for both search but in direct jira search it is fetching record. Let me check the proper access to the project then I will update the sameSamaria
@Samaria As there is very less support i have seen for JiraRestClient, You have crossed JQL and reached up to using runner script, please consider writing how you are able run runner scripts, is it local server set up or cloud provided. Please consider writing in detail so that others also can benefitted and someone can try this for you. Simply announcing bounty will not help you, unless they had complete set up to try for you. I suggest you to update question with details and upload required code to github and share the link. ThanksDinothere
have you tried using any other clients ? like curl or postman to confirm if the issue with jira client specifically or some other user access or jira server issue.Marbles
I
0

If I understand https://community.atlassian.com/t5/Jira-questions/How-to-get-a-list-of-quot-issues-in-epic-quot-in-Jira/qaq-p/511549 correctly, a workaround would be to use

String query="issueFunction in linkedIssuesOf('key=ABCD-24911', 'is epic of') 
  AND issuetype=Feature";  

instead of

String query="issuefunction in issuesInEpics('key = ABCD-24911') 
  AND issuetype=Feature";  

Background: It looks like the functions IssuesInEpics() and epicsOf() have been only recently introduced to amend the functionality of linkedIssuesOf().

For more documentation, see https://confluence.atlassian.com/jirasoftwarecloud/advanced-searching-functions-reference-764478342.html

Interlocutory answered 23/9, 2019 at 7:51 Comment(2)
getting exception : RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={}, errorMessages=[Error in scripted function: linkedIssuesOf, see below, The value 'ABCD-24911' does not exist for the field 'filter'.]}]}Samaria
@Sitansu: Please see my corrected answer. If it still does not work, please check whether linkedIssueOf works for you at all via REST-API.Interlocutory
S
2

I think there might be a problem specific to your JIRA instance that is causing your problem. My code below is based on what Anish wrote. It compiles and runs perfectly fine, printing out the exact list of issues I expect it to display.

Maybe this helps you when you can look at two pieces of code side-by-side.

public static void main(String[] args) throws URISyntaxException {
    URI uri = new URI("https://example.com");
    JiraRestClientFactory jiraRestClientFactory = new AsynchronousJiraRestClientFactory();
    try (JiraRestClient jiraRestClient = jiraRestClientFactory.createWithBasicHttpAuthentication(uri, "email", "password")) {
        SearchRestClient searchClient = jiraRestClient.getSearchClient();
        String query = "issueFunction in issuesInEpics('key = PROJ-1234') and issuetype = Task";
        System.out.println(query);
        SearchResult result = searchClient.searchJql(query, 50, 0, null).claim();
        for (Issue issue : result.getIssues()) {
            System.out.println(issue.getKey());
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

I also tried the given JQL using a custom proxy client my company uses and the query definitely works perfectly fine. Please check your environment and JIRA logs..

Shifrah answered 25/9, 2019 at 20:56 Comment(5)
It is giving org.codehaus.jettison.json.JSONException: A JSONObject text must begin with '{' at character 0 ofSamaria
@Samaria On what line? I am not getting that at all. Can you check the Jira logs?Shifrah
In this line it is showing SearchResult result = searchClient.searchJql(query, 50, 0, null).claim();Samaria
I do not know how it is working for you but in my case it is not working. Not able to address the issue in my jira rest client implementation.As I mentioned this query is working fine with my case issuefunction in issuesInEpics("resolution is not empty") and issuetype = FeatureSamaria
@Samaria Are you sure you ran my exact code? Does the stacktrace include a call to the method AsynchronousSearchRestClient.searchJqlImplPost() or AsynchronousSearchRestClient.searchJqlImplGet()? If it's neither, does the exception originate from SearchResultJsonParser.parse() instead? If it's that last one, your problem is that your Jira instance is not returning proper values.Shifrah
I
0

If I understand https://community.atlassian.com/t5/Jira-questions/How-to-get-a-list-of-quot-issues-in-epic-quot-in-Jira/qaq-p/511549 correctly, a workaround would be to use

String query="issueFunction in linkedIssuesOf('key=ABCD-24911', 'is epic of') 
  AND issuetype=Feature";  

instead of

String query="issuefunction in issuesInEpics('key = ABCD-24911') 
  AND issuetype=Feature";  

Background: It looks like the functions IssuesInEpics() and epicsOf() have been only recently introduced to amend the functionality of linkedIssuesOf().

For more documentation, see https://confluence.atlassian.com/jirasoftwarecloud/advanced-searching-functions-reference-764478342.html

Interlocutory answered 23/9, 2019 at 7:51 Comment(2)
getting exception : RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={}, errorMessages=[Error in scripted function: linkedIssuesOf, see below, The value 'ABCD-24911' does not exist for the field 'filter'.]}]}Samaria
@Sitansu: Please see my corrected answer. If it still does not work, please check whether linkedIssueOf works for you at all via REST-API.Interlocutory

© 2022 - 2024 — McMap. All rights reserved.