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

Is there a way to get a list of matching issues from a JQL query with a REST api call?

I see the advanced search facilities, and I see that there is a REST api. I don't immediately see whether it's possible to send a JQL query through the REST api and get a list of issue/story URLs back.  Is it possible to do this?

2 answers

1 vote
DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 18, 2020

@David Karr  Jira's rest are creatively designed and they mimic behavior of Jira UI as much as possible.

Now coming to your issue, when you look closely, if your Jira search screen url is like this,

  • BASE_URL/issues/?jql=JQL_QUERY

Your REST API URL will be simply,

  • BASE_URL/rest/api/latest/search?jql=JQL_QUERY (You can try it in browser directly)

Here is a reference documentation for search API,

And sometimes when JQL become too complex or large for 'GET' method you can use 'POST' method for search API,

As @Dave Theodore [Coyote Creek Consulting]  suggested you learn basics of REST API usage from documentation he provided - https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/

I'm probably dealing with multiple issues here.

I'm currently looking at a page with a url "https://ouritrackserver/issues/?filter=-1" and with a search field of "assignee = currentUser() AND resolution = Unresolved order by updated DESC".  This obviously isn't providing a jql parameter in the url. I tried constructing something like the following url "https://ouritrackserver/rest/api/latest/search/", but I have to url encode the "jql" parameter, so I built this command line:

curl -v --user "...:..." --data-urlencode "jql='assignee = currentUser() AND resolution = Unresolved order by updated DESC'" 'https://ouritrackserver/rest/api/latest/search/

This gave me an initial 200, but then later on in the debug log, a 415 (unsupported media type).

I'm not certain whether providing authN with "--user" will satisfy the "currentUser()" predicate, but that's probably not the issue I'm hitting. I'd also like to know if it's possible to generate a "user token" to use for authN instead of my network credentials, like other common services provide (bitbucket, sonarqube, et cetera). That's still a separate issue to this 415 problem.

DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 19, 2020

@David Karr 

The page of Jira (BASE_URL/issues/?filter=-1) is a default filter page of Jira server. Here issues are fetched based filter.

Now to fetch result based on filter,

  1. First fetch filter details,
  2. Calling URL given in searchUrl field will give you results of query you are looking for.

If you didn't like the way mentioned above, you can always use JQL search, for this you need to just encode JQL query and not the whole url.

  1. So, if your JQL string is 'assignee = currentUser() AND resolution = Unresolved order by updated DESC'
  2. Your curl request will be,
    • curl --request GET \
      --url 'BASE_URL/rest/api/latest/search?jql=assignee%20%3D%20currentUser()%20AND%20resolution%20%3D%20Unresolved%20order%20by%20updated%20DESC' \
      --user 'USER_NAME:PASSWORD' \
      --header 'Accept: application/json' \
      --header 'Content-Type: application/json'
    • This will give you results you are looking for.

Now coming to your question about `currentUser()` function in search, yes this will get populated with user who is accessing API, i.e. user passed in '--user' param in your curl request.

Another important point here is passing, 'Accept: application/json' and 'Content-Type: application/json' header in API request. Otherwise you might get error like 'Media type not supported'.

Looks good.  The last question that probably got lost at the end was about generating a "user token".  If I"m going to script these retrievals, I'd rather not hardcode my network credentials.  Several services (bitbucket and sonarqube, for instance) provide the ability to generate a "user token" associated with an account that is only used with the REST api. Leaking it has less risk than network credentials.  I don't see an obvious place to do this in Jira.

DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 20, 2020

@David Karr  I'm sorry to say but there are no API tokens in Jira Server.

But you can use oAuth if you are building full fledged application. This is documented here - https://developer.atlassian.com/server/jira/platform/oauth/

LarryBrock
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 22, 2020

Hello @David Karr and @DPKJ  - I have great news!  Our friends at resolution Reichert Network Solutions GmbH have solved this issue for us by introducing API Token Authentication for Jira supporting both server and data center deployments.

TBH, I have not used this product yet but if it's anywhere near the quality of their SSO add-ons, it'll be rock solid and highly performant.

Cheers,
~~Larry Brock

DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 22, 2020

@LarryBrock  That is nice.

But token based solution like this - ( https://marketplace.atlassian.com/apps/1221182/api-tokens-for-jira?hosting=server&tab=overview ) are already available, if you want to test them.

Like Jaylynn Soto likes this
1 vote
Dave Theodore [Coyote Creek Consulting]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 17, 2020

Check out this doc. It goes over the process you need to use. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events