It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

JiraRestClient Search Not Working for JQL Query “issuefunction in issuesInEpics('key = ABCD-24911' Edited

I am facing issue related to Search JQL. I am using query (issuefunction in issuesInEpics('key = ABCD-24911') and issuetype=Feature) in Jira Portal it is returning some record but when i am using this query in JiraRestClient it is not working it is returning zero record.

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);


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.

1 answer

1 accepted

1 vote
Answer accepted
Andy Heinzer Atlassian Team Sep 18, 2019

Hi

I understand that you are able to run this specific JQL query within Jira, but that trying to run this same query in the JiraRestClient is throwing a 403 error.  It is not clear me the exact cause here yet, but from that error message it looks like a bad request.

The JQL you are using here appears to be using a Scriptrunner function for searching.  But given the way you are using it in this example, perhaps we can run a similar search without it.  I'd be interested to see if you can run the JQL search of

type=Feature AND 'Epic Link'=REGOPS-24911

I am not sure if Scriptrunner is at all a factor here yet, but I have a suspicion that it might be given the function has to use quotes and parenthesis here.   Perhaps trying this instead might give us some more information about the problem itself, and it might be an alternative query to find what I think are are the same set of issues you are looking for here.

Please let me know the results.

Andy

Hi Andy Heinzer,

After search this JQL query(

type=Feature AND 'Epic Link'=ABCD-24911

) in Jira It is working but in Jira Rest  Api It is showing Exception :

RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={}, errorMessages=[No issues have a parent epic with key or name 'ABCD-24911']}]}

For this query (issuefunction in issuesInEpics('key = ABCD-24911') and issuetype = Feature)  it is showing record for jira search but zero record fetching for JIRA Rest API .

Also query like (issuefunction in issuesInEpics("resolution is not empty") and issuetype = Feature) .It is working fine for both Jira Rest API and Jira search.

 

 

Please give me any solution for this issue . I am stuck with this issue last two week .

I have updated my question please look into this issue.

It is working fine for below query :

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

Andy Heinzer Atlassian Team Sep 20, 2019

Hi,

Thanks for posting back with more information here.  I did some more research on this issue and I think you might find this other post interesting, https://community.developer.atlassian.com/t/rest-api-search-giving-400-bad-request/12889

It seems that when you are searching via the REST API, in some cases you have to use the HTTP verb POST instead of GET.  This is noted in the JIRA Server platform REST API reference

GET vs POST: If the JQL query is too large to be encoded as a query param you should instead POST to this resource.

What I am not clear on is exactly how to do that with the specific REST package you appear to be using here.  It looks like it is only using a GET for this endpoint.

Alternatively, I noticed in the last comment there that another users recommends to encode the '=' sign as it could be causing an error in the search.  I believe this encodes to a %3D

Since your other working query doesn't have this equals sign, it does seem to lend credence to this idea.  See if you can adjust your string from

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

to be more like

String query="issuefunction in issuesInEpics('key%3DABCD-24911') and issuetype%3DFeature";

I replaced the = with %3D.  Please try this and let me know the results.

Andy

My URL Already Encoded internally  by

searchJql function , After encoded URL :

https://xxxxxx.com/login/rest/api/latest/search?jql=issuefunction+in+issuesInEpics('key+%3D+ABCD-24911')+and+issuetype+%3D+Feature&expand=schema,names

 

 

Also I have tried this it is also not fetching records : 

issuefunction in issuesInEpics('key%3DABCD-24911') and issuetype%3DFeature
Andy Heinzer Atlassian Team Sep 24, 2019

Well, what about trying another way to run that same query without the equals sign?  Perhaps you can try the syntax of

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

It should return the same results as the equals sign would generate in a JQL query.

Try this and let me know.

Andy

Hi Andy,

 

It is also not working . It is fetching zero results.

Andy Heinzer Atlassian Team Sep 27, 2019

The fact that we don't get results is not necessarily meaning our JQL query is bad.  It could be that this is an authentication or authorization limitation.  Search is open within Jira to even unauthenticated users.  But those users won't be able to return any issues that they don't have permissions to see.

Perhaps calling the getMyPermissionsRestClient() method could tell us more about the account permissions making this request.

 

 

MyPermissionsInput myPer=new MyPermissionsInput("ABCD", null, null, null);
Promise<Permissions> permission=theClient.getMyPermissionsRestClient().getMyPermissions(myPer);

After debug I got the permission for LINK_ISSUE,  what does it means  can you please tell me.

Permission{id=21, key=LINK_ISSUE, name=Link Issues, description=Ability to link issues together and create linked issues. Only useful if issue linking is turned on., havePermission=false}

Andy Heinzer Atlassian Team Oct 02, 2019

That permission is a project level permission.  More details in Managing project permissions.   That specific permission alone is not sufficient to be able to see issues in Jira.   In your case, I would want to make sure that this account has the ability to 'Browse projects' permission in all the projects that you want to get search results back from.   Without this permission, the search results for that user account will never return any issues those projects.

Which might make sense here that your query is correct, but the permissions of the account making the request are limiting the search results to zero.

Thanks a lot I fixed that issue. It was a permission issue for specific user.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

The add-in you’ve been waiting for: Jira Cloud for Excel 🙌

Introducing Jira Cloud for Excel Here at the product integrations team at Atlassian, we are thrilled to announce the new Jira Cloud for Excel add-in! This add-in lets you export Jira data directly ...

872 views 6 24
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you