This post is to document, for myself to remember, but also for others who are looking to play with the Jira API - more specifically JQL. I've wrote a list of useful queries here.
The following example assumes:
- Base URL is: (you'll need to replace 'host' with yours) https://host.atlassian.net/rest/api/2
- TestProject is a real project with a team called Avengers
Example
Get list of bugs in TestProject in current sprint for Avengers team
Authentication
Generate an API token here and copy it somewhere for safe keeping as you're going to need it in a moment.
In the "Authorization" tab, select "Basic Auth" as type with your email address as username and the token you just generated as the password.
Request URL (GET):
https://host.atlassian.net/rest/api/2/search?jql=project=TSTP AND issuetype = "Bug" AND Sprint in openSprints() AND "Engineering Team[Dropdown]" = TSTP-Avengers
Where query params are:
Key | Value |
---|---|
jql | project=TSTP AND issuetype = "Bug" AND Sprint in openSprints() AND "Engineering Team[Dropdown]" = TSTP-Avengers |
JSON Response
You'll get back a hefty JSON response which I believe you can filter (not looked into this yet). Please note I've heavily removed bits to focus on the main juicy data you get back without boring the page too much. There are loads of custom fields returned where I believe (again, not looked into this as yet) you can check on your Jira account for a list/create some more.
{
"expand": "schema,names",
"startAt": 0,
"maxResults": 50,
"total": 1,
"issues": [
{
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields,customfield_16139.properties",
"id": "44421",
"self": "https://host.atlassian.net/rest/api/2/issue/44421",
"key": "TSTP-5980",
"fields": {
"resolution": {
"self": "https://host.atlassian.net/rest/api/2/resolution/10000",
"id": "10000",
"description": "Work has been completed on this issue.",
"name": "Done"
},
"lastViewed": "2021-05-19T09:10:22.953+0100",
"labels": [
"Tech Debt"
],
"assignee": {
"displayName": "Lorna Watson"
},
"reporter": {
"displayName": "Bob Smith"
},
"customfield_15725": {
"released": true,
"releaseDate": "2017-10-25"
},
"issuetype": {
"self": "https://host.atlassian.net/rest/api/2/issuetype/1",
"id": "1",
"description": "A problem which impairs or prevents the functions of the product.",
"iconUrl": "https://host.atlassian.net/secure/viewavatar?size=medium&avatarId=1223&avatarType=issuetype",
"name": "Bug",
"subtask": false,
"avatarId": 1223
},
"project": {
"self": "https://host.atlassian.net/rest/api/2/project/1450",
"id": "1450",
"key": "TSTP",
"name": "TestProject",
"avatarUrls": {
"48x48": "https://host.atlassian.net/secure/projectavatar?pid=1450&avatarId=20535",
"24x24": "https://host.atlassian.net/secure/projectavatar?size=small&s=small&pid=1450&avatarId=20535",
"16x16": "https://host.atlassian.net/secure/projectavatar?size=xsmall&s=xsmall&pid=1450&avatarId=20535",
"32x32": "https://host.atlassian.net/secure/projectavatar?size=medium&s=medium&pid=1450&avatarId=20535"
},
"projectCategory": {
"self": "https://host.atlassian.net/rest/api/2/projectCategory/10200",
"id": "10200",
"description": "Used by ABC TestProject",
"name": "ABC TestProject"
}
},
"resolutiondate": "2021-05-19T09:10:22.982+0100",
"updated": "2021-05-19T14:40:38.903+0100",
"description": "Details of task item will be shown here",
"customfield_10007": [
{
"id": 35,
"name": "Sprint 1 (Avengers)",
"state": "active",
"boardId": 1,
"startDate": "2021-05-10T07:00:00.000Z",
"endDate": "2021-05-21T16:30:00.000Z"
}
],
"priority": {
"name": "Sev 2",
"id": "4"
},
"status": {
"self": "https://host.atlassian.net/rest/api/2/status/1086",
"description": "",
"iconUrl": "https://host.atlassian.net/images/icons/statuses/generic.png",
"name": "Complete",
"id": "1086",
"statusCategory": {
"self": "https://host.atlassian.net/rest/api/2/statuscategory/1",
"id": 1,
"key": "done",
"colorName": "green",
"name": "Done"
}
},
"creator": {
"displayName": "Bob Smith"
},
"customfield_14006": {
"self": "https://host.atlassian.net/rest/api/2/customFieldOption/11734",
"value": "Pending",
"id": "11734"
},
"customfield_13710": "Some more details",
"customfield_13702": {
"self": "https://host.atlassian.net/rest/api/2/customFieldOption/11512",
"value": "Not Reviewed",
"id": "11512"
},
"created": "2017-12-12T11:07:34.517+0000",
"customfield_12600": "{pullrequest={dataType=pullrequest, state=MERGED, stateCount=1}, json={\"cachedValue\":{\"errors\":[],\"summary\":{\"pullrequest\":{\"overall\":{\"count\":1,\"lastUpdated\":\"2021-05-18T16:48:41.146+0100\",\"stateCount\":1,\"state\":\"MERGED\",\"dataType\":\"pullrequest\",\"open\":false},\"byInstanceType\":{\"bitbucket\":{\"count\":1,\"name\":\"Bitbucket Cloud\"}}}}},\"isStale\":true}}"
}
}
]
}
All good to go.
I hope this was useful, I found it painful to get it to this stage with not being much (IMO) documentation and tutorials on using JQL for Jira API requests. Thank you!!
Top comments (0)